-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
054a91b
commit a0c895e
Showing
6 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Prometheus.Contrib.EventListeners.Counters; | ||
using Xunit; | ||
|
||
namespace prometheus_net.Contrib.Tests | ||
{ | ||
public class CountersTests | ||
{ | ||
[Fact] | ||
public void MeanCounter_WhenMeanIsGreaterThanZero_ThenUseMeanForValue() | ||
{ | ||
var meanCounter = new MeanCounter("test1", "test2", "test3"); | ||
|
||
var eventData = new Dictionary<string, object> | ||
{ | ||
["Name"] = "cpu-usage", | ||
["DisplayName"] = "CPU Usage", | ||
["Mean"] = 15d, | ||
["StandardDeviation"] = 0, | ||
["Count"] = 1, | ||
["Min"] = 0, | ||
["Max"] = 0, | ||
["InvervalSec"] = 9.9996233, | ||
["Series"] = "Interval=10000", | ||
["CounterType"] = "Mean", | ||
["Metadata"] = "", | ||
["DisplayUnits"] = "%", | ||
}; | ||
|
||
meanCounter.TryReadEventCounterData(eventData); | ||
|
||
Assert.Equal(15, meanCounter.Metric.Value); | ||
} | ||
|
||
[Fact] | ||
public void MeanCounter_WhenMeanIsZero_ThenUseCountForValue() | ||
{ | ||
var meanCounter = new MeanCounter("test1", "test2", "test3"); | ||
|
||
var eventData = new Dictionary<string, object> | ||
{ | ||
["Name"] = "active-db-contexts", | ||
["DisplayName"] = "Active DbContexts", | ||
["Mean"] = 0d, | ||
["StandardDeviation"] = 0, | ||
["Count"] = 5, | ||
["Min"] = 0, | ||
["Max"] = 0, | ||
["InvervalSec"] = 9.9996233, | ||
["Series"] = "Interval=10000", | ||
["CounterType"] = "Mean", | ||
["Metadata"] = "", | ||
["DisplayUnits"] = "", | ||
}; | ||
|
||
meanCounter.TryReadEventCounterData(eventData); | ||
|
||
Assert.Equal(5, meanCounter.Metric.Value); | ||
} | ||
|
||
[Fact] | ||
public void MeanCounter_WhenMeanIsNaN_ThenUseZeroForValue() | ||
{ | ||
var meanCounter = new MeanCounter("test1", "test2", "test3"); | ||
|
||
var eventData = new Dictionary<string, object> | ||
{ | ||
["Name"] = "compiled-query-cache-hit-rate", | ||
["DisplayName"] = "Query Cache Hit Rate", | ||
["Mean"] = double.NaN, | ||
["StandardDeviation"] = 0, | ||
["Count"] = 1, | ||
["Min"] = double.NaN, | ||
["Max"] = double.NaN, | ||
["InvervalSec"] = 9.9996233, | ||
["Series"] = "Interval=10000", | ||
["CounterType"] = "Mean", | ||
["Metadata"] = "", | ||
["DisplayUnits"] = "%" | ||
}; | ||
|
||
meanCounter.TryReadEventCounterData(eventData); | ||
|
||
Assert.Equal(0, meanCounter.Metric.Value); | ||
} | ||
|
||
[Fact] | ||
public void IncrementCounter_WhenIncrement_ThenUseIncrementForValue() | ||
{ | ||
var incrementCounter = new IncrementCounter("test1", "test2", "test3"); | ||
|
||
var eventData = new Dictionary<string, object> | ||
{ | ||
["Name"] = "optimistic-concurrency-failures-per-second", | ||
["DisplayName"] = "Optimistic Concurrency Failures", | ||
["DisplayRateTimeScale"] = "00:00:01", | ||
["Increment"] = 1d, | ||
["IntervalSec"] = 675.144775, | ||
["Metadata"] = "", | ||
["Series"] = "Interval=10000", | ||
["CounterType"] = "Sum", | ||
["DisplayUnits"] = "" | ||
}; | ||
|
||
incrementCounter.TryReadEventCounterData(eventData); | ||
|
||
Assert.Equal(1, incrementCounter.Metric.Value); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
prometheus-net.Contrib.Tests/prometheus-net.Contrib.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<RootNamespace>prometheus_net.Contrib.Tests</RootNamespace> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\prometheus-net.Contrib\prometheus-net.Contrib.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("prometheus-net.Contrib.Tests")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters