lib/promscrape/discovery/kuma: add support for client_id option

See https://github.com/prometheus/prometheus/pull/13278
This commit is contained in:
Aliaksandr Valialkin 2024-02-18 19:19:36 +02:00
parent 690f6c833c
commit f0db7d474f
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 25 additions and 6 deletions

View file

@ -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).

View file

@ -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
```

View file

@ -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,

View file

@ -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"`