diff --git a/go.mod b/go.mod index 9649afe24c..f0fac9e7af 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ replace github.com/influxdata/telegraf => github.com/aws/telegraf v0.10.2-0.2024 // Replace with https://github.com/amazon-contributing/opentelemetry-collector-contrib, there are no requirements for all receivers/processors/exporters // to be all replaced since there are some changes that will always be from upstream - replace ( github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter => github.com/amazon-contributing/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter v0.0.0-20240903195955-5944792b593a github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter => github.com/amazon-contributing/opentelemetry-collector-contrib/exporter/awsemfexporter v0.0.0-20240903195955-5944792b593a diff --git a/plugins/inputs/prometheus/metrics_receiver_test.go b/plugins/inputs/prometheus/metrics_receiver_test.go index 6496bbc5df..ff87b9b00f 100644 --- a/plugins/inputs/prometheus/metrics_receiver_test.go +++ b/plugins/inputs/prometheus/metrics_receiver_test.go @@ -4,14 +4,15 @@ package prometheus import ( + "os" + "path/filepath" + "testing" + kitlog "github.com/go-kit/log" "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/storage" "github.com/stretchr/testify/assert" - "os" - "path/filepath" - "testing" ) func Test_metricAppender_Add_BadMetricName(t *testing.T) { @@ -122,44 +123,11 @@ func Test_loadConfigFromFile(t *testing.T) { logger.Log("reloaded") return nil } - err := reloadConfig(configFile, logger, true, reloader) + taManager := createTargetAllocatorManager(configFile, logger, nil, nil) + err := reloadConfig(configFile, logger, taManager, reloader) assert.NoError(t, err) -} - -func Test_TA_Labels(t *testing.T) { - mbCh := make(chan PrometheusMetricBatch, 3) - mr := metricsReceiver{pmbCh: mbCh} - ma := mr.Appender(nil) - var ts int64 = 10 - var v = 10.0 - ls := []labels.Label{ - {Name: "__address__", Value: "192.168.20.37:8080"}, - {Name: "__meta_kubernetes_namespace", Value: "default"}, - {Name: "__meta_kubernetes_pod_container_id", Value: "containerd://b3a3dd8e4630a0c99fd65f4cffb8f2524394ec3e86dce2e94dced7dce082ea94"}, - {Name: "__meta_kubernetes_pod_container_image", Value: "registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.12.0"}, - {Name: "__meta_kubernetes_pod_container_init", Value: "false"}, - {Name: "__meta_kubernetes_pod_container_name", Value: "kube-state-metrics"}, - {Name: "__meta_kubernetes_pod_container_port_name", Value: "http"}, - {Name: "__meta_kubernetes_pod_container_port_number", Value: "8080"}, - {Name: "__meta_kubernetes_pod_container_port_protocol", Value: "TCP"}, - {Name: "__meta_kubernetes_pod_controller_kind", Value: "ReplicaSet"}, - {Name: "__meta_kubernetes_pod_controller_name", Value: "example-kube-state-metrics-7446cc6b96"}, - {Name: "__meta_kubernetes_pod_host_ip", Value: "192.168.0.41"}, - {Name: "__meta_kubernetes_pod_ip", Value: "192.168.20.37"}, - } - - ref, err := ma.Append(0, ls, ts, v) - assert.Equal(t, ref, storage.SeriesRef(0)) - assert.Nil(t, err) - mac, _ := ma.(*metricAppender) - assert.Equal(t, 1, len(mac.batch)) + assert.True(t, taManager.enabled) + assert.Equal(t, taManager.config.TargetAllocator.CollectorID, "collector-1") + assert.Equal(t, taManager.config.TargetAllocator.TLSSetting.CAFile, DEFAULT_TLS_CA_FILE_PATH) - expected := PrometheusMetric{ - metricName: "metric_name", - metricValue: v, - metricType: "", - timeInMS: ts, - tags: map[string]string{"tag_a": "a"}, - } - assert.Equal(t, expected, *mac.batch[0]) } diff --git a/plugins/inputs/prometheus/start.go b/plugins/inputs/prometheus/start.go index 2eb219d577..912d9e124c 100644 --- a/plugins/inputs/prometheus/start.go +++ b/plugins/inputs/prometheus/start.go @@ -23,7 +23,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/prometheus/prometheus/discovery/targetgroup" "os" "os/signal" "runtime" @@ -31,6 +30,8 @@ import ( "syscall" "time" + "github.com/prometheus/prometheus/discovery/targetgroup" + "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/oklog/run" diff --git a/plugins/inputs/prometheus/target_allocator.go b/plugins/inputs/prometheus/target_allocator.go index e0706ec4e4..b2263091b0 100644 --- a/plugins/inputs/prometheus/target_allocator.go +++ b/plugins/inputs/prometheus/target_allocator.go @@ -1,8 +1,13 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: MIT + package prometheus import ( "context" "fmt" + "strings" + "github.com/go-kit/log" "github.com/go-kit/log/level" otelpromreceiver "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver" @@ -17,11 +22,12 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" "gopkg.in/yaml.v3" - "strings" "os" ) +const DEFAULT_TLS_CA_FILE_PATH = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt" + type TargetAllocatorManager struct { enabled bool manager *tamanager.Manager @@ -129,7 +135,7 @@ func (tam *TargetAllocatorManager) loadConfig(filename string) error { return nil // no target allocator return } //has target allocator - tam.config.TargetAllocator.TLSSetting.CAFile = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt" + tam.config.TargetAllocator.TLSSetting.CAFile = DEFAULT_TLS_CA_FILE_PATH return nil } func (tam *TargetAllocatorManager) Start() error {