From f0db7d474f562cbf4a8ef5779e171f5641aeaa29 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 18 Feb 2024 19:19:36 +0200 Subject: [PATCH] lib/promscrape/discovery/kuma: add support for `client_id` option See https://github.com/prometheus/prometheus/pull/13278 --- docs/CHANGELOG.md | 1 + docs/sd_configs.md | 6 ++++++ lib/promscrape/discovery/kuma/api.go | 21 ++++++++++++++++----- lib/promscrape/discovery/kuma/kuma.go | 3 ++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2a6a58bc3..a7287ab9c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -32,6 +32,7 @@ See also [LTS releases](https://docs.victoriametrics.com/LTS-releases.html). * FEATURE: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): propagate [label filters](https://docs.victoriametrics.com/keyconcepts/#filtering) via all the [label manipulation functions](https://docs.victoriametrics.com/metricsql/#label-manipulation-functions). For example, `label_del(some_metric{job="foo"}, "instance") + other_metric{pod="bar"}` is now transformed to `label_del(some_metric{job="foo",pod="bar"}, "instance") + other_metric{job="foo",pod="bar"}`. This should reduce the amounts of time series processed during query execution. * FEATURE: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): expose `vm_last_partition_parts` [metrics](https://docs.victoriametrics.com/#monitoring), which show the number of [parts in the latest partition](https://docs.victoriametrics.com/#storage). These metrics may help debugging query performance slowdown related to the increased number of parts in the last partition, since usually all the ingested data is written to the last partition and all the queries are performed over the recently ingested data, e.g. the last partition. +* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add support for `client_id` option into [kuma_sd_configs](https://docs.victoriametrics.com/sd_configs/#kuma_sd_configs) in the same way as Prometheus does. See [this pull request](https://github.com/prometheus/prometheus/pull/13278). * FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl.html): support client-side TLS configuration for [InfluxDB](https://docs.victoriametrics.com/vmctl/#migrating-data-from-influxdb-1x). See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5748). Thanks to @khushijain21 for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5783). * FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl.html): support client-side TLS configuration for [Remote Read protocol](https://docs.victoriametrics.com/vmctl/#migrating-data-by-remote-read-protocol). See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5748). Thanks to @khushijain21 for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5798). * FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): preserve [`WITH` templates](https://play.victoriametrics.com/select/accounting/1/6a716b0f-38bc-4856-90ce-448fd713e3fe/expand-with-exprs) when clicking the `prettify query` button at the right side of query input field. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5383). diff --git a/docs/sd_configs.md b/docs/sd_configs.md index 9ed10bd76..389fb7dfd 100644 --- a/docs/sd_configs.md +++ b/docs/sd_configs.md @@ -1243,6 +1243,12 @@ scrape_configs: # - server: "http://localhost:5676" + # client_id is an optional client ID to send to Kuma Control Plane. + # The hostname of the server where vmagent runs is used if it isn't set. + # If the hostname is empty, then "vmagent" string is used as client_id. + # + # client_id: "..." + # Additional HTTP API client options can be specified here. # See https://docs.victoriametrics.com/sd_configs.html#http-api-client-options ``` diff --git a/lib/promscrape/discovery/kuma/api.go b/lib/promscrape/discovery/kuma/api.go index 26b62f081..fa27ad6d1 100644 --- a/lib/promscrape/discovery/kuma/api.go +++ b/lib/promscrape/discovery/kuma/api.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/url" + "os" "strings" "sync" "sync/atomic" @@ -23,8 +24,9 @@ import ( var configMap = discoveryutils.NewConfigMap() type apiConfig struct { - client *discoveryutils.Client - apiPath string + client *discoveryutils.Client + clientID string + apiPath string // labels contains the latest discovered labels. labels atomic.Pointer[[]*promutils.Labels] @@ -65,9 +67,18 @@ func newAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) { return nil, fmt.Errorf("cannot create HTTP client for %q: %w", apiServer, err) } + clientID := sdc.ClientID + if clientID == "" { + clientID, _ = os.Hostname() + if clientID == "" { + clientID = "vmagent" + } + } + cfg := &apiConfig{ - client: client, - apiPath: apiPath, + client: client, + clientID: clientID, + apiPath: apiPath, fetchErrors: metrics.GetOrCreateCounter(fmt.Sprintf(`promscrape_discovery_kuma_errors_total{type="fetch",url=%q}`, sdc.Server)), parseErrors: metrics.GetOrCreateCounter(fmt.Sprintf(`promscrape_discovery_kuma_errors_total{type="parse",url=%q}`, sdc.Server)), @@ -142,7 +153,7 @@ func (cfg *apiConfig) updateTargetsLabels(ctx context.Context) error { dReq := &discoveryRequest{ VersionInfo: cfg.latestVersion, Node: discoveryRequestNode{ - ID: "vmagent", + ID: cfg.clientID, }, TypeURL: "type.googleapis.com/kuma.observability.v1.MonitoringAssignment", ResponseNonce: cfg.latestNonce, diff --git a/lib/promscrape/discovery/kuma/kuma.go b/lib/promscrape/discovery/kuma/kuma.go index c5bd82490..11ba4fc75 100644 --- a/lib/promscrape/discovery/kuma/kuma.go +++ b/lib/promscrape/discovery/kuma/kuma.go @@ -19,7 +19,8 @@ var SDCheckInterval = flag.Duration("promscrape.kumaSDCheckInterval", 30*time.Se // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kuma_sd_config type SDConfig struct { - Server string `yaml:"server"` + Server string `yaml:"server"` + ClientID string `yaml:"client_id,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`