Skip to content

Commit

Permalink
WIP defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed Mar 27, 2024
1 parent 2f5e452 commit 4b2f888
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 97 deletions.
39 changes: 21 additions & 18 deletions internal/component/prometheus/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ type Arguments struct {
Clustering cluster.ComponentBlock `river:"clustering,block,optional"`
}

var (
PrometheusProto string = "PrometheusProto"
PrometheusText0_0_4 string = "PrometheusText0.0.4"
OpenMetricsText0_0_1 string = "OpenMetricsText0.0.1"
OpenMetricsText1_0_0 string = "OpenMetricsText1.0.0"
)
var defaultScrapeProtocols = convertDefaultScrapeProtocols()

func convertDefaultScrapeProtocols() []string {
// We use `DefaultProtoFirstScrapeProtocols` to keep the native histograms disabled by default.
// See https://github.com/prometheus/prometheus/pull/12738/files#diff-17f1012e0c2fbd9bcd8dff3c23b18ff4b6676eef3beca6f8a3e72e6a36633334R64-R68
protocols := make([]string, 0, len(config.DefaultScrapeProtocols))
for _, p := range config.DefaultScrapeProtocols {
protocols = append(protocols, string(p))
}
return protocols
}

// SetToDefault implements river.Defaulter.
func (arg *Arguments) SetToDefault() {
Expand All @@ -119,14 +124,7 @@ func (arg *Arguments) SetToDefault() {
HTTPClientConfig: component_config.DefaultHTTPClientConfig,
ScrapeInterval: 1 * time.Minute, // From config.DefaultGlobalConfig
ScrapeTimeout: 10 * time.Second, // From config.DefaultGlobalConfig
//TODO: I'm not sure if this is accurate. See:
// https://github.com/prometheus/prometheus/pull/12738/files#diff-17f1012e0c2fbd9bcd8dff3c23b18ff4b6676eef3beca6f8a3e72e6a36633334R64-R68
ScrapeProtocols: []string{
PrometheusProto,
OpenMetricsText1_0_0,
OpenMetricsText0_0_1,
PrometheusText0_0_4,
},
ScrapeProtocols: defaultScrapeProtocols,
}
}

Expand All @@ -136,12 +134,17 @@ func (arg *Arguments) Validate() error {
return fmt.Errorf("scrape_timeout (%s) greater than scrape_interval (%s) for scrape config with job name %q", arg.ScrapeTimeout, arg.ScrapeInterval, arg.JobName)
}

// Validate scrape protocols
existing := make(map[string]struct{})
for _, p := range arg.ScrapeProtocols {
switch p {
case PrometheusProto, OpenMetricsText0_0_1, OpenMetricsText1_0_0, PrometheusText0_0_4:
default:
return fmt.Errorf("unsupported scrape protocol %q", p)
if _, ok := existing[p]; ok {
return fmt.Errorf("duplicate scrape protocol %q: make sure the scrape protocols provided are unique", p)
}
promSP := config.ScrapeProtocol(p)
if err := promSP.Validate(); err != nil {
return fmt.Errorf("invalid scrape protocol %q: %w", p, err)
}
existing[p] = struct{}{}
}

// We must explicitly Validate because HTTPClientConfig is squashed and it won't run otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func (b *ConfigBuilder) appendExporter(commonConfig *int_config.Common, name str
scrapeConfig.ScrapeTimeout = b.cfg.Integrations.ConfigV1.PrometheusGlobalConfig.ScrapeTimeout
}

// TODO: Consider making this configurable if we add static mode support for native histograms.
scrapeConfig.ScrapeProtocols = prom_config.DefaultScrapeProtocols

scrapeConfigs := []*prom_config.ScrapeConfig{&scrapeConfig}

promConfig := &prom_config.Config{
Expand Down
Loading

0 comments on commit 4b2f888

Please sign in to comment.