mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 08:26:19 +01:00
b9bb64ce55
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
40 lines
824 B
Go
40 lines
824 B
Go
package consul
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Agent is Consul agent.
|
|
//
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
type Agent struct {
|
|
Config AgentConfig
|
|
Member AgentMember
|
|
Meta map[string]string
|
|
}
|
|
|
|
// AgentConfig is Consul agent config.
|
|
//
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
type AgentConfig struct {
|
|
Datacenter string
|
|
NodeName string
|
|
}
|
|
|
|
// AgentMember is Consul agent member info.
|
|
//
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
type AgentMember struct {
|
|
Addr string
|
|
}
|
|
|
|
// ParseAgent parses Consul agent information from data.
|
|
func ParseAgent(data []byte) (*Agent, error) {
|
|
var a Agent
|
|
if err := json.Unmarshal(data, &a); err != nil {
|
|
return nil, fmt.Errorf("cannot unmarshal agent info from %q: %w", data, err)
|
|
}
|
|
return &a, nil
|
|
}
|