/
prometheus_common.go
37 lines (31 loc) · 1.38 KB
/
prometheus_common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package providers
import (
"github.com/DataDog/datadog-agent/comp/core/autodiscovery/common/types"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
// getPrometheusConfigs reads and initializes the openmetrics checks from the configuration
// It defines a default openmetrics instances with default AD if the checks configuration is empty
func getPrometheusConfigs() ([]*types.PrometheusCheck, error) {
checks, err := types.PrometheusScrapeChecksTransformer(config.Datadog.GetString("prometheus_scrape.checks"))
if err != nil {
return []*types.PrometheusCheck{}, err
}
if len(checks) == 0 {
log.Info("The 'prometheus_scrape.checks' configuration is empty, a default openmetrics check configuration will be used")
return []*types.PrometheusCheck{types.DefaultPrometheusCheck}, nil
}
validChecks := []*types.PrometheusCheck{}
for i, check := range checks {
if err := check.Init(config.Datadog.GetInt("prometheus_scrape.version")); err != nil {
log.Errorf("Ignoring check configuration (# %d): %v", i+1, err)
continue
}
validChecks = append(validChecks, check)
}
return validChecks, nil
}