2023-02-22 12:59:56 +00:00
|
|
|
package kuma
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SDCheckInterval defines interval for targets refresh.
|
2023-02-23 01:05:49 +00:00
|
|
|
var SDCheckInterval = flag.Duration("promscrape.kumaSDCheckInterval", 30*time.Second, "Interval for checking for changes in kuma service discovery. "+
|
2023-02-22 12:59:56 +00:00
|
|
|
"This works only if kuma_sd_configs is configured in '-promscrape.config' file. "+
|
|
|
|
"See https://docs.victoriametrics.com/sd_configs.html#kuma_sd_configs for details")
|
|
|
|
|
|
|
|
// SDConfig represents service discovery config for Kuma Service Mesh.
|
|
|
|
//
|
|
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kuma_sd_config
|
|
|
|
type SDConfig struct {
|
2023-02-23 01:05:49 +00:00
|
|
|
Server string `yaml:"server"`
|
|
|
|
|
2023-02-22 12:59:56 +00:00
|
|
|
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
|
|
|
ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
|
|
|
|
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
|
|
|
|
|
2023-02-23 01:05:49 +00:00
|
|
|
// fetch_timeout isn't used, so it isn't defined.
|
|
|
|
// FetchTimeout time.Duration `yaml:"fetch_timeout,omitempty"`
|
|
|
|
|
|
|
|
// refresh_interval is obtained from `-promscrape.kumaSDCheckInterval` command-line option.
|
|
|
|
// RefreshInterval time.Duration `yaml:"refresh_interval,omitempty"`
|
2023-02-22 12:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabels returns kuma service discovery labels according to sdc.
|
|
|
|
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
|
|
|
|
cfg, err := getAPIConfig(sdc, baseDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get API config for kuma_sd: %w", err)
|
|
|
|
}
|
2023-07-20 00:37:49 +00:00
|
|
|
pLabels := cfg.labels.Load()
|
2023-02-23 01:05:49 +00:00
|
|
|
return *pLabels, nil
|
2023-02-22 12:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MustStop stops further usage for sdc.
|
|
|
|
func (sdc *SDConfig) MustStop() {
|
|
|
|
v := configMap.Delete(sdc)
|
|
|
|
if v != nil {
|
|
|
|
// v can be nil if GetLabels wasn't called yet.
|
|
|
|
cfg := v.(*apiConfig)
|
|
|
|
cfg.mustStop()
|
|
|
|
}
|
|
|
|
}
|