mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 07:19:17 +01:00
lib/promscrape/discovery/consulagent: substitute metaPrefix with the __meta_consulagent_
plaintext string
This simplifies future code navigation and search for the specific meta-label starting from __meta_consulagent_* prefix. For example, `grep __meta_consulagent_namespace` finds the exact place where this label is defined. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3953 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4217
This commit is contained in:
parent
7db647e924
commit
b9bb64ce55
@ -204,23 +204,23 @@ The following meta labels are available on discovered targets during [relabeling
|
||||
|
||||
The list of discovered Consul targets is refreshed at the interval, which can be configured via `-promscrape.consulSDCheckInterval` command-line flag.
|
||||
|
||||
If you have performance issues with consul_sd_configs on a large cluster, then consider using [consulagent_sd_configs](#consulagent_sd_configs) instead.
|
||||
If you have performance issues with `consul_sd_configs` on a large cluster, then consider using [consulagent_sd_configs](#consulagent_sd_configs) instead.
|
||||
|
||||
## consulagent_sd_configs
|
||||
|
||||
Consul Agent SD configuration allows retrieving scrape targets from [Consul's Agent API](https://developer.hashicorp.com/consul/api-docs/agent/service).
|
||||
When using the Agent API, each running vmagent will only get services registered in the local Consul Agent running on the same node when discovering new targets.
|
||||
It's suitable for huge clusters for which using the [Catalog API](https://developer.hashicorp.com/consul/api-docs/catalog#list-services) would be too slow or resource intensive,
|
||||
in other cases we recommend to use [consul_sd_configs](#consul_sd_configs).
|
||||
Consul Agent SD configuration allows retrieving scrape targets from [Consul Agent API](https://developer.hashicorp.com/consul/api-docs/agent/service).
|
||||
When using the Agent API, only services registered in the locally running Consul Agent are discovered.
|
||||
It is suitable for huge clusters for which using the [Catalog API](https://developer.hashicorp.com/consul/api-docs/catalog#list-services) would be too slow or resource intensive,
|
||||
in other cases it is recommended to use [consul_sd_configs](#consul_sd_configs).
|
||||
|
||||
Configuration example:
|
||||
|
||||
```yaml
|
||||
scrape_configs:
|
||||
- job_name: consul
|
||||
- job_name: consulagent
|
||||
consulagent_sd_configs:
|
||||
|
||||
# server is an optional Consul agent to connect to. By default localhost:8500 is used
|
||||
# server is an optional Consul Agent to connect to. By default localhost:8500 is used
|
||||
- server: "localhost:8500"
|
||||
|
||||
# token is an optional Consul API token.
|
||||
@ -252,12 +252,12 @@ scrape_configs:
|
||||
# Individual tags are also available via __meta_consul_tag_<tagname> labels - see below.
|
||||
# tag_separator: "..."
|
||||
|
||||
# filter is optional filter for service nodes discovery request.
|
||||
# filter is optional filter for service nodes discovery request.
|
||||
# Replaces tags and node_metadata options.
|
||||
# consul supports it since 1.14 version
|
||||
# list of supported filters https://developer.hashicorp.com/consul/api-docs/catalog#filtering-1
|
||||
# syntax examples https://developer.hashicorp.com/consul/api-docs/features/filtering
|
||||
# filter: "..."
|
||||
# filter: "..."
|
||||
|
||||
# Additional HTTP API client options can be specified here.
|
||||
# See https://docs.victoriametrics.com/sd_configs.html#http-api-client-options
|
||||
|
@ -29,7 +29,7 @@ type AgentMember struct {
|
||||
Addr string
|
||||
}
|
||||
|
||||
// ParseAgent parses Consul agent information from bytes.
|
||||
// ParseAgent parses Consul agent information from data.
|
||||
func ParseAgent(data []byte) (*Agent, error) {
|
||||
var a Agent
|
||||
if err := json.Unmarshal(data, &a); err != nil {
|
||||
|
@ -144,7 +144,7 @@ func getDatacenter(client *discoveryutils.Client, dc string) (string, error) {
|
||||
}
|
||||
agent, err := GetAgentInfo(client)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot query consul agent info: %w", err)
|
||||
return "", err
|
||||
}
|
||||
return agent.Config.Datacenter, nil
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ func getServiceNodesLabels(cfg *apiConfig) []*promutils.Labels {
|
||||
}
|
||||
|
||||
func appendTargetLabels(sn consul.ServiceNode, ms []*promutils.Labels, serviceName, tagSeparator string, agent *consul.Agent) []*promutils.Labels {
|
||||
const metaPrefix = "__meta_consulagent_"
|
||||
var addr string
|
||||
|
||||
// If the service address is not empty it should be used instead of the node address
|
||||
@ -35,30 +34,30 @@ func appendTargetLabels(sn consul.ServiceNode, ms []*promutils.Labels, serviceNa
|
||||
|
||||
m := promutils.NewLabels(16)
|
||||
m.Add("__address__", addr)
|
||||
m.Add(metaPrefix+"address", agent.Member.Addr)
|
||||
m.Add(metaPrefix+"dc", agent.Config.Datacenter)
|
||||
m.Add(metaPrefix+"health", consul.AggregatedStatus(sn.Checks))
|
||||
m.Add(metaPrefix+"namespace", sn.Service.Namespace)
|
||||
m.Add(metaPrefix+"node", agent.Config.NodeName)
|
||||
m.Add(metaPrefix+"service", serviceName)
|
||||
m.Add(metaPrefix+"service_address", sn.Service.Address)
|
||||
m.Add(metaPrefix+"service_id", sn.Service.ID)
|
||||
m.Add(metaPrefix+"service_port", strconv.Itoa(sn.Service.Port))
|
||||
m.Add("__meta_consulagent_address", agent.Member.Addr)
|
||||
m.Add("__meta_consulagent_dc", agent.Config.Datacenter)
|
||||
m.Add("__meta_consulagent_health", consul.AggregatedStatus(sn.Checks))
|
||||
m.Add("__meta_consulagent_namespace", sn.Service.Namespace)
|
||||
m.Add("__meta_consulagent_node", agent.Config.NodeName)
|
||||
m.Add("__meta_consulagent_service", serviceName)
|
||||
m.Add("__meta_consulagent_service_address", sn.Service.Address)
|
||||
m.Add("__meta_consulagent_service_id", sn.Service.ID)
|
||||
m.Add("__meta_consulagent_service_port", strconv.Itoa(sn.Service.Port))
|
||||
|
||||
discoveryutils.AddTagsToLabels(m, sn.Service.Tags, metaPrefix, tagSeparator)
|
||||
discoveryutils.AddTagsToLabels(m, sn.Service.Tags, "__meta_consulagent_", tagSeparator)
|
||||
|
||||
for k, v := range agent.Meta {
|
||||
m.Add(discoveryutils.SanitizeLabelName(metaPrefix+"metadata_"+k), v)
|
||||
m.Add(discoveryutils.SanitizeLabelName("__meta_consulagent_metadata_"+k), v)
|
||||
}
|
||||
for k, v := range sn.Service.Meta {
|
||||
m.Add(discoveryutils.SanitizeLabelName(metaPrefix+"service_metadata_"+k), v)
|
||||
m.Add(discoveryutils.SanitizeLabelName("__meta_consulagent_service_metadata_"+k), v)
|
||||
}
|
||||
for k, v := range sn.Node.TaggedAddresses {
|
||||
m.Add(discoveryutils.SanitizeLabelName(metaPrefix+"tagged_address_"+k), v)
|
||||
m.Add(discoveryutils.SanitizeLabelName("__meta_consulagent_tagged_address_"+k), v)
|
||||
}
|
||||
for k, v := range sn.Service.TaggedAddresses {
|
||||
address := fmt.Sprintf("%s:%d", v.Address, v.Port)
|
||||
m.Add(discoveryutils.SanitizeLabelName(metaPrefix+"tagged_address_"+k), address)
|
||||
m.Add(discoveryutils.SanitizeLabelName("__meta_consulagent_tagged_address_"+k), address)
|
||||
}
|
||||
ms = append(ms, m)
|
||||
return ms
|
||||
|
Loading…
Reference in New Issue
Block a user