-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Cache and expire metrics for prometheus output #2016
Conversation
type PrometheusClient struct { | ||
Listen string | ||
Listen string | ||
ExpirationInterval int64 `toml:"expiration_interval"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this type to internal.Duration
, that way it can reprepsented like expiration_interval = "10s"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to import github.com/influxdata/telegraf/internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -171,7 +174,12 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error { | |||
"key: %s, labels: %v,\nerr: %s\n", | |||
mname, l, err.Error()) | |||
} | |||
p.metrics[desc.String()] = metric | |||
|
|||
metricWithTime := &MetricWithExpiration{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't declare a tmp var for metricWithTime, just do p.metrics[desc.String()] = &MetricWithExpiration{ ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
sync.Mutex | ||
} | ||
|
||
var sampleConfig = ` | ||
## Address to listen on | ||
# listen = ":9126" | ||
|
||
## Interval to expire metrics and not deliver to prometheus, 0 == no expiration | ||
# expiration_interval = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say this should default to "60s"
, since the current behavior of the plugin is to expire metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll also need to set the value in the struct that gets returned in the init()
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is what you're looking for here, let me know if I did it wrong
@sparrc I updated the changelog on this; is there anything else you'd like me to do? |
looks good but the changelog update is in the wrong section, you should rebase and put it into release 1.2 |
Running 1.2.1 and still seeing same behavior (as detailed in #1775). |
Required for all PRs:
This implements the solution we discussed in #1775