Merge pull request #13278 from Automaat/feat/extend-kuma-sd-api

kuma_sd: Extend Kuma SD configuration to allow users to specify ClientId
This commit is contained in:
Julien Pivotto 2023-12-18 12:12:07 +01:00 committed by GitHub
commit 10557ed8e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 5 deletions

View file

@ -568,6 +568,7 @@ var expectedConf = &Config{
ServiceDiscoveryConfigs: discovery.Configs{ ServiceDiscoveryConfigs: discovery.Configs{
&xds.KumaSDConfig{ &xds.KumaSDConfig{
Server: "http://kuma-control-plane.kuma-system.svc:5676", Server: "http://kuma-control-plane.kuma-system.svc:5676",
ClientID: "main-prometheus",
HTTPClientConfig: config.DefaultHTTPClientConfig, HTTPClientConfig: config.DefaultHTTPClientConfig,
RefreshInterval: model.Duration(15 * time.Second), RefreshInterval: model.Duration(15 * time.Second),
FetchTimeout: model.Duration(2 * time.Minute), FetchTimeout: model.Duration(2 * time.Minute),

View file

@ -221,6 +221,7 @@ scrape_configs:
kuma_sd_configs: kuma_sd_configs:
- server: http://kuma-control-plane.kuma-system.svc:5676 - server: http://kuma-control-plane.kuma-system.svc:5676
client_id: main-prometheus
- job_name: service-marathon - job_name: service-marathon
marathon_sd_configs: marathon_sd_configs:

View file

@ -108,6 +108,7 @@ scrape_configs:
kuma_sd_configs: kuma_sd_configs:
- server: http://kuma-control-plane.kuma-system.svc:5676 - server: http://kuma-control-plane.kuma-system.svc:5676
client_id: main-prometheus
marathon_sd_configs: marathon_sd_configs:
- servers: - servers:

View file

@ -155,10 +155,14 @@ func kumaMadsV1ResourceParser(resources []*anypb.Any, typeURL string) ([]model.L
func NewKumaHTTPDiscovery(conf *KumaSDConfig, logger log.Logger, reg prometheus.Registerer) (discovery.Discoverer, error) { func NewKumaHTTPDiscovery(conf *KumaSDConfig, logger log.Logger, reg prometheus.Registerer) (discovery.Discoverer, error) {
// Default to "prometheus" if hostname is unavailable. // Default to "prometheus" if hostname is unavailable.
clientID, err := osutil.GetFQDN() clientID := conf.ClientID
if err != nil { if clientID == "" {
level.Debug(logger).Log("msg", "error getting FQDN", "err", err) var err error
clientID = "prometheus" clientID, err = osutil.GetFQDN()
if err != nil {
level.Debug(logger).Log("msg", "error getting FQDN", "err", err)
clientID = "prometheus"
}
} }
clientConfig := &HTTPResourceClientConfig{ clientConfig := &HTTPResourceClientConfig{

View file

@ -205,7 +205,7 @@ func TestNewKumaHTTPDiscovery(t *testing.T) {
require.True(t, ok) require.True(t, ok)
require.Equal(t, kumaConf.Server, resClient.Server()) require.Equal(t, kumaConf.Server, resClient.Server())
require.Equal(t, KumaMadsV1ResourceTypeURL, resClient.ResourceTypeURL()) require.Equal(t, KumaMadsV1ResourceTypeURL, resClient.ResourceTypeURL())
require.NotEmpty(t, resClient.ID()) require.Equal(t, kumaConf.ClientID, resClient.ID())
require.Equal(t, KumaMadsV1ResourceType, resClient.config.ResourceType) require.Equal(t, KumaMadsV1ResourceType, resClient.config.ResourceType)
} }

View file

@ -55,6 +55,7 @@ type SDConfig struct {
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"` RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
FetchTimeout model.Duration `yaml:"fetch_timeout,omitempty"` FetchTimeout model.Duration `yaml:"fetch_timeout,omitempty"`
Server string `yaml:"server,omitempty"` Server string `yaml:"server,omitempty"`
ClientID string `yaml:"client_id,omitempty"`
} }
// mustRegisterMessage registers the provided message type in the typeRegistry, and panics // mustRegisterMessage registers the provided message type in the typeRegistry, and panics

View file

@ -36,6 +36,7 @@ var (
sdConf = SDConfig{ sdConf = SDConfig{
Server: "http://127.0.0.1", Server: "http://127.0.0.1",
RefreshInterval: model.Duration(10 * time.Second), RefreshInterval: model.Duration(10 * time.Second),
ClientID: "test-id",
} }
testFetchFailuresCount = prometheus.NewCounter( testFetchFailuresCount = prometheus.NewCounter(

View file

@ -2230,6 +2230,11 @@ See below for the configuration options for Kuma MonitoringAssignment discovery:
# Address of the Kuma Control Plane's MADS xDS server. # Address of the Kuma Control Plane's MADS xDS server.
server: <string> server: <string>
# Client id is used by Kuma Control Plane to compute Monitoring Assignment for specific Prometheus backend.
# This is useful when migrating between multiple Prometheus backends, or having separate backend for each Mesh.
# When not specified, system hostname/fqdn will be used if available, if not `prometheus` will be used.
[ client_id: <string> ]
# The time to wait between polling update requests. # The time to wait between polling update requests.
[ refresh_interval: <duration> | default = 30s ] [ refresh_interval: <duration> | default = 30s ]