forked from open-telemetry/opentelemetry-dotnet-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from twenzel/EventSourceConfiguration
Test configuration via IConfiguration
- Loading branch information
Showing
5 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
.github/workflows/package-Instrumentation.EventCounters.yml
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,49 @@ | ||
name: Pack OpenTelemetry.Contrib.Instrumentation.EventCounters | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
logLevel: | ||
description: 'Log level' | ||
required: true | ||
default: 'warning' | ||
push: | ||
tags: | ||
- 'Instrumentation.EventCounters-*' # trigger when we create a tag with prefix "Instrumentation.AWS-" | ||
|
||
jobs: | ||
build-test-pack: | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
PROJECT: OpenTelemetry.Contrib.Instrumentation.EventCounters | ||
|
||
strategy: | ||
matrix: | ||
os: [windows-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # fetching all | ||
|
||
- name: Install dependencies | ||
run: dotnet restore | ||
|
||
- name: dotnet build ${{env.PROJECT}} | ||
run: dotnet build src/${{env.PROJECT}} --configuration Release --no-restore -p:Deterministic=true | ||
|
||
- name: dotnet test ${{env.PROJECT}} | ||
run: dotnet test test/${{env.PROJECT}}.Tests | ||
|
||
- name: dotnet pack ${{env.PROJECT}} | ||
run: dotnet pack src/${{env.PROJECT}} --configuration Release --no-build | ||
|
||
- name: Publish Artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{env.PROJECT}}-packages | ||
path: '**/${{env.PROJECT}}/bin/**/*.*nupkg' | ||
|
||
- name: Publish Nuget | ||
run: | | ||
nuget push **/${{env.PROJECT}}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }} |
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
82 changes: 82 additions & 0 deletions
82
test/OpenTelemetry.Contrib.Instrumentation.EventCounters.Tests/EventCountersOptionsTests.cs
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,82 @@ | ||
// <copyright file="EventCountersOptionsTests.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System.IO; | ||
using System.Text; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
|
||
namespace OpenTelemetry.Contrib.Instrumentation.EventCounters.Tests | ||
{ | ||
public class EventCountersOptionsTests | ||
{ | ||
[Fact] | ||
public void Can_Be_Read_From_Configuration() | ||
{ | ||
var json = @"{ | ||
""Telemetry"": { | ||
""RefreshIntervalSecs"": 55, | ||
""Sources"": [ | ||
{ | ||
""EventSourceName"": ""System.Runtime"", | ||
""EventCounters"" : [ | ||
{ | ||
""Name"": ""cpu-usage"", | ||
""Description"": ""Current CPU usage"", | ||
""Type"": ""DoubleGauge"" | ||
}, | ||
{ | ||
""Name"": ""working-set"", | ||
""Description"": ""Process working set"", | ||
""Type"": ""LongSum"", | ||
""MetricName"": ""process_working_set"" | ||
} | ||
] | ||
}, | ||
{ | ||
""EventSourceName"": ""MyCustomSource"", | ||
""EventCounters"" : [ | ||
{ | ||
""Name"": ""orders_submitted"", | ||
""Description"": ""Number of submitted orders"", | ||
""Type"": ""LongSum"" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}"; | ||
|
||
var configuration = new ConfigurationBuilder().AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json))).Build(); | ||
|
||
var options = configuration.GetSection("Telemetry").Get<EventCountersOptions>(); | ||
Assert.Equal(55, options.RefreshIntervalSecs); | ||
Assert.Equal(2, options.Sources.Count); | ||
|
||
Assert.Equal(2, options.Sources[0].EventCounters.Count); | ||
Assert.Equal("System.Runtime", options.Sources[0].EventSourceName); | ||
|
||
Assert.Equal("cpu-usage", options.Sources[0].EventCounters[0].Name); | ||
Assert.Equal("Current CPU usage", options.Sources[0].EventCounters[0].Description); | ||
Assert.Equal(OpenTelemetry.Metrics.MetricType.DoubleGauge, options.Sources[0].EventCounters[0].Type); | ||
|
||
Assert.Equal("working-set", options.Sources[0].EventCounters[1].Name); | ||
Assert.Equal("Process working set", options.Sources[0].EventCounters[1].Description); | ||
Assert.Equal(OpenTelemetry.Metrics.MetricType.LongSum, options.Sources[1].EventCounters[0].Type); | ||
Assert.Equal("process_working_set", options.Sources[0].EventCounters[1].MetricName); | ||
} | ||
} | ||
} |
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