Skip to content

Commit

Permalink
Setting Prometheus Remote_write Period default value to 1m (#38553)
Browse files Browse the repository at this point in the history
* Correcting period for Prometheus remote_write

* Update CHANGELOG.next.asciidoc
  • Loading branch information
gizas authored Apr 10, 2024
1 parent b2edf8a commit e798bb1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
*Heartbeat*

*Metricbeat*

- Setting period for counter cache for Prometheus remote_write at least to 60sec {pull}38553[38553]

*Osquerybeat*

Expand Down
7 changes: 7 additions & 0 deletions metricbeat/module/prometheus/remote_write/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ metricbeat.modules:
metricsets: ["remote_write"]
host: "localhost"
port: "9201"
use_types: true
rate_counters: true
period: 60s
-------------------------------------------------------------------------------------

`use_types` parameter (default: false) enables a different layout for metrics storage, leveraging Elasticsearch
Expand All @@ -95,6 +98,10 @@ types, including https://www.elastic.co/guide/en/elasticsearch/reference/current
the counter increment since the last collection. This metric should make some aggregations easier and with better
performance. This parameter can only be enabled in combination with `use_types`.

`period` parameter (default: 60s) configures the timeout of internal cache, which stores counter values in order to calculate rates between consecutive fetches. The parameter will be validated and all values lower than 60sec will be reset to the default value.

Note that by default prometheus pushes data with the interval of 60s (in remote write). In case that prometheus push rate is changed, the `period` parameter needs to be configured accordingly.

When `use_types` and `rate_counters` are enabled, metrics are stored like this:

[source,json]
Expand Down
17 changes: 15 additions & 2 deletions x-pack/metricbeat/module/prometheus/remote_write/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

package remote_write

import "errors"
import (
"errors"
"time"
)

type config struct {
UseTypes bool `config:"use_types"`
RateCounters bool `config:"rate_counters"`
TypesPatterns TypesPatterns `config:"types_patterns" yaml:"types_patterns,omitempty"`
Period time.Duration `config:"period" validate:"positive"`
}

type TypesPatterns struct {
Expand All @@ -21,12 +25,21 @@ var defaultConfig = config{
TypesPatterns: TypesPatterns{
CounterPatterns: nil,
HistogramPatterns: nil},
Period: time.Second * 60,
}

func (c *config) Validate() error {
if c.RateCounters && !c.UseTypes {
return errors.New("'rate_counters' can only be enabled when `use_types` is also enabled")
}

duration, err := time.ParseDuration(c.Period.String())
{
if err != nil {
return err
} else if duration < 60*time.Second {
// by default prometheus push data with the interval 60s, in order to calculate counter rate we are setting Period to 60secs accordingly
c.Period = time.Second * 60
}
}
return nil
}
3 changes: 2 additions & 1 deletion x-pack/metricbeat/module/prometheus/remote_write/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func remoteWriteEventsGeneratorFactory(base mb.BaseMetricSet) (remote_write.Remo
}

if config.UseTypes {
logp.Debug("prometheus.remote_write.cache", "Period for counter cache for remote_write: %v", config.Period.String())
// use a counter cache with a timeout of 5x the period, as a safe value
// to make sure that all counters are available between fetches
counters := collector.NewCounterCache(base.Module().Config().Period * 5)
counters := collector.NewCounterCache(config.Period * 5)

g := remoteWriteTypedGenerator{
counterCache: counters,
Expand Down

0 comments on commit e798bb1

Please sign in to comment.