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

Generate runtime metrics #213

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Generate runtime metrics #213

merged 2 commits into from
Jul 6, 2023

Conversation

pablochacin
Copy link
Collaborator

@pablochacin pablochacin commented Jun 16, 2023

Description

Add options to the agent for generating go runtime metrics.

Fixes: #199

Checklist:

  • My code follows the coding style of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works.
  • Any dependent changes have been merged and published in downstream modules

@pablochacin pablochacin force-pushed the report-runtime-metrics branch 2 times, most recently from 78a7eea to a078a01 Compare June 19, 2023 18:59
@pablochacin pablochacin force-pushed the report-runtime-metrics branch 2 times, most recently from 8a6b7ec to ec76899 Compare July 5, 2023 10:03
@pablochacin pablochacin changed the title WIP:Generate runtime metrics Generate runtime metrics Jul 5, 2023
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin marked this pull request as ready for review July 5, 2023 10:22
@pablochacin pablochacin requested a review from roobre July 5, 2023 13:09
Copy link
Collaborator

@roobre roobre left a comment

Choose a reason for hiding this comment

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

Left some comments. I wonder thought how this will evolve when we transition to daemon mode, as I think Prometheus might make more sense in that case. IIRC the prometheus go library can collect this metrics for us.


type metricsProbe struct {
config MetricsConfig
collector context.CancelFunc
Copy link
Collaborator

Choose a reason for hiding this comment

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

collector seems a bit strange as a name for a cancel function, what about cancelCollector?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense

Comment on lines 113 to 124
go func() {
ticks := time.NewTicker(m.rate)
for {
select {
case <-ticks.C:
m.sample()
case <-ctx.Done():
ticks.Stop()
m.generate()
}
}
}()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not seeing how this goroutine exits when the context is cancelled. Wouldn't the goroutine be looping forever when ctx.Done() returns a closed channel?

A maybe simpler approach could be to:

Suggested change
go func() {
ticks := time.NewTicker(m.rate)
for {
select {
case <-ticks.C:
m.sample()
case <-ctx.Done():
ticks.Stop()
m.generate()
}
}
}()
go func() {
ticks := time.NewTicker(m.rate)
defer ticks.Stop()
for {
select {
case <-ticks.C:
m.sample()
case <-ctx.Done():
m.generate()
return
}
}
}()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Thanks

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin requested a review from roobre July 6, 2023 13:03
Copy link
Collaborator

@roobre roobre left a comment

Choose a reason for hiding this comment

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

Looking good!

@pablochacin pablochacin merged commit 49d65e8 into main Jul 6, 2023
7 checks passed
@pablochacin pablochacin deleted the report-runtime-metrics branch July 6, 2023 16:27
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.

Collect agent metrics for debugging
2 participants