Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event counter listener #177

Closed
wants to merge 46 commits into from

Conversation

hananiel
Copy link

@hananiel hananiel commented Jan 20, 2022

Resolves #215

This PR provides the option to use any EventCounter as metric instrumentation, using an EventListener to "subscribe" to all Event sources the developer has specified.

The listener reads the event counter payload and passes it to the MeterTelemetryPublisher.

The publisher creates the instrumentation based on user provided definition or if none is provided, by using the information given by the event counter (see Inferring the Instrument Type).

The configuration is very easy. You can add all event counters of an event source just by

 options.AddEventSource("Microsoft-AspNetCore-Server-Kestrel")

or define each event counter fine grained by

options.AddEventSource("Microsoft-AspNetCore-Server-Kestrel")
 .With("connections-per-second", "The number of connections per update interval", InstrumentationType.Gauge)
 .With("total-connections", "The number of total connections", InstrumentationType.Gauge)

@@ -0,0 +1,58 @@
# MySqlData Instrumentation for OpenTelemetry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

{
if (eventData == null)
{
throw new ArgumentNullException(nameof(eventData));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does anyone catch this?

}
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the usage is not clear... could you describe with an example?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are looking for how configuration is done, I havent coded that up yet, just making sure what I have so far is in the ballpark. Using the extension method provided (AddEventCounterListener) adds the EventListener that then republishes counters via metricsAPI. For example running the program listing in the Readme.md above produces the following output:

  • I assumed all counters will be instrumented as guages
  • Since this requires aggregation in the collect interval, the appropriate one is last value

Export cpu-usage, Unit: CPU Usage, Meter: OpenTelemetry.Contrib.EventCounterListener/0.0.0.0 (2022-01-20T03:48:23.3248145Z, 2022-01-20T03:48:37.2994387Z] DoubleGauge Value: 0 Export working-set, Unit: Working Set, Meter: OpenTelemetry.Contrib.EventCounterListener/0.0.0.0 (2022-01-20T03:48:23.3275819Z, 2022-01-20T03:48:37.2994398Z] DoubleGauge Value: 31 Export gc-heap-size, Unit: GC Heap Size, Meter: OpenTelemetry.Contrib.EventCounterListener/0.0.0.0 (2022-01-20T03:48:23.3276834Z, 2022-01-20T03:48:37.2994400Z] DoubleGauge Value: 5 Export gen-0-gc-count, Unit: Gen 0 GC Count, Meter: OpenTelemetry.Contrib.EventCounterListener/0.0.0.0 (2022-01-20T03:48:23.3280650Z, 2022-01-20T03:48:37.2994402Z] DoubleGauge Value: 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without seeing how a user would configure, its hard to comment on it.
Some qns:
What are the inputs provided by the user? Do they pick each and every eventcounter?
Given there are different types of EventCounters, do we let user let us know if they want it treated as counter/gauge/histogram?

(Ofcourse we don't want to solve it in 1st iteration, but want to get a feel of how would the final version look like )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the inputs provided by the user? Do they pick each and every eventcounter?

I was thinking they can filter by EventSource, and then get more granular at the particular counter.

Given there are different types of EventCounters, do we let user let us know if they want it treated as counter/gauge/histogram?

I have made a list of well known eventcounters and ran Reiley's "algorithm" for picking an instrument. In each case they made no sense to add them, since the eventCounters themselves are preaggregated, it makes no sense to further aggregate them - let me know if I am wrong about this or a different guide to pick instruments. Dependending on the answer to this, we could also make this the default option while giving users customizability to change this.

If you need to get on a zoom call for 15 mins, I am available today or next week is fine as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did realize something I had misunderstood about different eventcounter types. I'll rework this.

NuGet.config Outdated
@@ -4,6 +4,8 @@
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="MyGet" value="https://www.myget.org/F/opentelemetry/api/v3/index.json" />
<add key="Dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this, as we won't need any packages from non nuget.org/myget.org

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed ..

@twenzel
Copy link
Contributor

twenzel commented Jan 21, 2022

@hananiel Can we rename the projects OpenTelemetry.Contrib.EventCounterListener (+.Tests) to OpenTelemetry.Contrib.Instrumentation.EventCounterListener to be the same as the used namespace and as the other projects?

@linux-foundation-easycla
Copy link

CLA Not Signed

  • ❌ The commit (7381f48 ,79ce3c2c0b8804ec4c170101b835800f66134b73 ,769ff52fb03642ab88e621f93313535a7e9bb273 ,a92627b80af448febea13793bd9f8dfecdd9d5af ,3fb77d37110055af340f1391a2291311badf8c1d ,86367ca9143723170c0c4ff3bb3524ccc4032ab9 ,18c35078e8fddf3dab31890614e490208f193f88 ,bffd20016fd4e9458798a0419a84e0c59946798a ,69bd1025c990f3bdbaff9c3e87f25af4f00aadfa ,4f7ff3e3a2bd3787bc416cd5d5d9eed3e9111735 ,a56237593322511ca48cf198f721c65f65f57925) is missing the User's ID, preventing the EasyCLA check. Consult GitHub Help to resolve.For further assistance with EasyCLA, please submit a support request ticket.

1 similar comment
@linux-foundation-easycla
Copy link

CLA Not Signed

  • ❌ The commit (7381f48 ,79ce3c2c0b8804ec4c170101b835800f66134b73 ,769ff52fb03642ab88e621f93313535a7e9bb273 ,a92627b80af448febea13793bd9f8dfecdd9d5af ,3fb77d37110055af340f1391a2291311badf8c1d ,86367ca9143723170c0c4ff3bb3524ccc4032ab9 ,18c35078e8fddf3dab31890614e490208f193f88 ,bffd20016fd4e9458798a0419a84e0c59946798a ,69bd1025c990f3bdbaff9c3e87f25af4f00aadfa ,4f7ff3e3a2bd3787bc416cd5d5d9eed3e9111735 ,a56237593322511ca48cf198f721c65f65f57925) is missing the User's ID, preventing the EasyCLA check. Consult GitHub Help to resolve.For further assistance with EasyCLA, please submit a support request ticket.

@twenzel
Copy link
Contributor

twenzel commented Jan 24, 2022

Hi @cijothomas 🙋🏼‍♂️,
we think the code is now fine for a review.
Please have look and tell us what you think.

@hananiel hananiel force-pushed the EventCounterListener branch from 837be0b to cfb4d0f Compare January 26, 2022 21:27
}
```

Configuration can be done completely using the IConfiguration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont think we need to document the usage of IConfiguration or anything else here. Its not related to this package.

{
public static void Main(string[] args)
{
using var meterprovider = Sdk.CreateMeterProviderBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you describe the overall approach/design used in the PR description? Its a bit hard to figure out the design in a big PR without some writeup.

Copy link

@Im5tu Im5tu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me a few days to see the message @cijothomas - looks good, just a minor comment. Think we need to be aware that some EventSource's are available on startup as they are typically created on first use. So this could be before the EventListener has been created depending on the configuration of the app. Code as is will miss this if it's not fully initialized from what I can see. May be worth calling EventSource.GetSources() just after initialization (in our version we actually call this every 5-10 seconds to see if there's any new event sources that the user has request us track)

/// Creates a counter instrumentation of long values which is an instrument that reports monotonically
/// increasing values.
/// </summary>
Counter = 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counter is an sync instrument, so we should not use it from EventCounter.
Only supported instruments should be the ObservableCounter, ObservableGauge, and ObservableUpDownCounter (when that instrument is added)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only named "Counter". The publisher creates an ObservableCounter.
Should we rename the Counter enum value to ObservableCounter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. it's not clear which instrument from Metrics API should be used, so a matching name would help here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names were renamed.

Hananiel Sarella and others added 3 commits February 8, 2022 15:51
Rename instrumentation types to reflect the created instrumentation
@twenzel
Copy link
Contributor

twenzel commented Feb 13, 2022

@cijothomas Anything else missing?

@hananiel hananiel mentioned this pull request Feb 18, 2022
@ZEXSM
Copy link

ZEXSM commented Feb 27, 2022

@hananiel have you considered receiving diagnostic data via EventPipeSession, as is done by e.g. dotnet counters, instead of subscribing to an EventListener?

https://docs.microsoft.com/en-us/dotnet/core/diagnostics/eventpipe
https://docs.microsoft.com/en-us/dotnet/core/diagnostics/diagnostics-client-library

@twenzel
Copy link
Contributor

twenzel commented Feb 28, 2022

@ZEXSM EventPipes should be used to retrieve the data for out-proc scenarios. EventListeners can be used for in-proc. Since we're running in-proc the EventListeners are the prefered way.

See https://docs.microsoft.com/en-us/dotnet/core/diagnostics/event-counters

@cijothomas
Copy link
Member

@hananiel @twenzel To unblock and make progress, I'd suggest to break this down into smaller PRs, similar to suggestion for runtime metrics PR (#207 (comment)).

For this one, consider following

  1. Add project/workflow
  2. Extension method to enable, with just a basic support of specifying list of EventSource/EventCounter name. Default to ObservableGauge for all.
  3. Add usage and example
  4. Add capability to add allow user to specify which Instrument to use for each eventcounter.
  5. Release 1st alpha and iterate based on initial feedback.

(its generally very hard to get people to review big PRs, so I'd strongly suggest small PRs, each addressing a specific concern, to constantly make progress, and hopefully attract more reviewers.)

@hananiel
Copy link
Author

Closing in lieu of #365

@hananiel hananiel closed this May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EventCounter -> Metric API instrumentation
5 participants