From 2a22f19ab849db5dbb2d1b2383588c44bdaa0fef Mon Sep 17 00:00:00 2001 From: Kyle Eckhart Date: Fri, 17 Nov 2023 11:44:39 -0500 Subject: [PATCH] Cleanup merge + missing review comments + fix deprecations from go.mod update --- component/otelcol/config_filter_test.go | 6 +++-- .../integrations/azure-exporter-config.md | 4 ++-- go.mod | 2 +- pkg/operator/config/config_test.go | 11 +++++---- pkg/operator/config/metrics_templates_test.go | 15 ++++++------ pkg/operator/reconciler_metrics.go | 11 +++++---- pkg/operator/resources_metrics.go | 13 +++++----- pkg/operator/resources_pod_template.go | 13 +++++----- .../internal/dtobuilder/dtobuilder.go | 24 +++++++++---------- tools/smoke/internal/tasks.go | 6 ++--- 10 files changed, 56 insertions(+), 49 deletions(-) diff --git a/component/otelcol/config_filter_test.go b/component/otelcol/config_filter_test.go index 9e4eab1ec293..39a1fae4c90a 100644 --- a/component/otelcol/config_filter_test.go +++ b/component/otelcol/config_filter_test.go @@ -3,11 +3,13 @@ package otelcol_test import ( "testing" + "k8s.io/utils/ptr" + "github.com/grafana/agent/component/otelcol" + "github.com/grafana/river" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/pdata/plog" - "k8s.io/utils/pointer" ) func TestConvertMatchProperties(t *testing.T) { @@ -49,7 +51,7 @@ func TestConvertMatchProperties(t *testing.T) { Libraries: []otelcol.InstrumentationLibrary{ { Name: "mongo-java-driver", - Version: pointer.String("3.8.0"), + Version: ptr.To("3.8.0"), }, }, SpanKinds: []string{"span1"}, diff --git a/docs/sources/static/configuration/integrations/azure-exporter-config.md b/docs/sources/static/configuration/integrations/azure-exporter-config.md index fe8a08f86457..d2aa146dfc55 100644 --- a/docs/sources/static/configuration/integrations/azure-exporter-config.md +++ b/docs/sources/static/configuration/integrations/azure-exporter-config.md @@ -107,7 +107,7 @@ The account used by Grafana Agent needs: # Can't be used if `regions` is set. [resource_graph_query_filter: ] - # Optional: The list of regions for gathering metrics. Enables gather metrics for all resources in the subscription. + # Optional: The list of regions for gathering metrics. Enables gathering metrics for all resources in the subscription. # The list of available `regions` to your subscription can be found by running the Azure CLI command `az account list-locations --query '[].name'`. # Can't be used if `resource_graph_query_filter` is set. regions: @@ -156,7 +156,7 @@ The account used by Grafana Agent needs: # Optional: Which azure cloud environment to connect to, azurecloud, azurechinacloud, azuregovernmentcloud, or azurepprivatecloud [azure_cloud_environment: | default = "azurecloud"] - # Optional: validation is disabled by default to reduce the number of azure exporter instances required when a `resource_type` has metrics with varying dimensions. + # Optional: Validation is disabled by default to reduce the number of Azure exporter instances required when a `resource_type` has metrics with varying dimensions. # Choosing to enable `validate_dimensions` will require one exporter instance per metric + dimension combination which can be very tedious to maintain. [validate_dimensions: | default = false] ``` diff --git a/go.mod b/go.mod index fa07ad483da1..4614e9124d44 100644 --- a/go.mod +++ b/go.mod @@ -227,7 +227,6 @@ require ( gotest.tools v2.2.0+incompatible k8s.io/api v0.28.3 k8s.io/apiextensions-apiserver v0.28.0 - k8s.io/apimachinery v0.28.3 k8s.io/client-go v0.28.3 k8s.io/component-base v0.28.1 k8s.io/klog/v2 v2.100.1 @@ -616,6 +615,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/receiver/vcenterreceiver v0.87.0 github.com/prometheus/tsdb v0.10.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.42.0 + k8s.io/apimachinery v0.28.3 ) require ( diff --git a/pkg/operator/config/config_test.go b/pkg/operator/config/config_test.go index 532a8d546aaa..d9ad7b16a02e 100644 --- a/pkg/operator/config/config_test.go +++ b/pkg/operator/config/config_test.go @@ -4,16 +4,17 @@ import ( "fmt" "testing" - "github.com/grafana/agent/pkg/operator/assets" - "github.com/grafana/agent/pkg/util" - "github.com/grafana/agent/pkg/util/subset" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" k8s_yaml "sigs.k8s.io/yaml" + "github.com/grafana/agent/pkg/operator/assets" + "github.com/grafana/agent/pkg/util" + "github.com/grafana/agent/pkg/util/subset" + gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" ) @@ -231,7 +232,7 @@ func TestAdditionalScrapeConfigsMetrics(t *testing.T) { Name: "agent", }, Spec: gragent.GrafanaAgentSpec{ - Image: pointer.String("grafana/agent:latest"), + Image: ptr.To("grafana/agent:latest"), ServiceAccountName: "agent", Metrics: gragent.MetricsSubsystemSpec{ InstanceSelector: &meta_v1.LabelSelector{ diff --git a/pkg/operator/config/metrics_templates_test.go b/pkg/operator/config/metrics_templates_test.go index e0182ea6249c..1b7cb619bc9d 100644 --- a/pkg/operator/config/metrics_templates_test.go +++ b/pkg/operator/config/metrics_templates_test.go @@ -6,16 +6,17 @@ import ( "strings" "testing" - jsonnet "github.com/google/go-jsonnet" - gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" - "github.com/grafana/agent/pkg/operator/assets" - "github.com/grafana/agent/pkg/util" + "github.com/google/go-jsonnet" prom_v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" + + gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" + "github.com/grafana/agent/pkg/operator/assets" + "github.com/grafana/agent/pkg/util" ) func TestExternalLabels(t *testing.T) { @@ -89,8 +90,8 @@ func TestExternalLabels(t *testing.T) { }, Spec: gragent.GrafanaAgentSpec{ Metrics: gragent.MetricsSubsystemSpec{ - MetricsExternalLabelName: pointer.String("deployment"), - ReplicaExternalLabelName: pointer.String("replica"), + MetricsExternalLabelName: ptr.To("deployment"), + ReplicaExternalLabelName: ptr.To("replica"), ExternalLabels: map[string]string{"foo": "bar"}, }, }, diff --git a/pkg/operator/reconciler_metrics.go b/pkg/operator/reconciler_metrics.go index 9873708479bb..eec1ffa072fb 100644 --- a/pkg/operator/reconciler_metrics.go +++ b/pkg/operator/reconciler_metrics.go @@ -11,16 +11,17 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/google/go-jsonnet" - gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" - "github.com/grafana/agent/pkg/operator/clientutil" - "github.com/grafana/agent/pkg/operator/config" apps_v1 "k8s.io/api/apps/v1" core_v1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" + + gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" + "github.com/grafana/agent/pkg/operator/clientutil" + "github.com/grafana/agent/pkg/operator/config" ) // createMetricsConfigurationSecret creates the Grafana Agent metrics configuration and stores @@ -99,7 +100,7 @@ func (r *reconciler) createTelemetryConfigurationSecret( Labels: r.config.Labels.Merge(managedByOperatorLabels), OwnerReferences: []v1.OwnerReference{{ APIVersion: d.Agent.APIVersion, - BlockOwnerDeletion: pointer.Bool(true), + BlockOwnerDeletion: ptr.To(true), Kind: d.Agent.Kind, Name: d.Agent.Name, UID: d.Agent.UID, diff --git a/pkg/operator/resources_metrics.go b/pkg/operator/resources_metrics.go index 0081f4490af0..ee6e0cdbbbd2 100644 --- a/pkg/operator/resources_metrics.go +++ b/pkg/operator/resources_metrics.go @@ -5,15 +5,16 @@ import ( "fmt" "strings" - gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" prom_operator "github.com/prometheus-operator/prometheus-operator/pkg/operator" apps_v1 "k8s.io/api/apps/v1" core_v1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" + + gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" ) const ( @@ -77,8 +78,8 @@ func generateMetricsStatefulSetService(cfg *Config, d gragent.Deployment) *core_ APIVersion: d.Agent.APIVersion, Kind: d.Agent.Kind, Name: d.Agent.Name, - BlockOwnerDeletion: pointer.Bool(true), - Controller: pointer.Bool(true), + BlockOwnerDeletion: ptr.To(true), + Controller: ptr.To(true), UID: d.Agent.UID, }}, Labels: cfg.Labels.Merge(map[string]string{ @@ -230,8 +231,8 @@ func metadataFromPodTemplate(name string, d gragent.Deployment, tmpl core_v1.Pod OwnerReferences: []meta_v1.OwnerReference{{ APIVersion: d.Agent.APIVersion, Kind: d.Agent.Kind, - BlockOwnerDeletion: pointer.Bool(true), - Controller: pointer.Bool(true), + BlockOwnerDeletion: ptr.To(true), + Controller: ptr.To(true), Name: d.Agent.Name, UID: d.Agent.UID, }}, diff --git a/pkg/operator/resources_pod_template.go b/pkg/operator/resources_pod_template.go index 5e97851cd8ce..c4b82cc0f279 100644 --- a/pkg/operator/resources_pod_template.go +++ b/pkg/operator/resources_pod_template.go @@ -4,13 +4,14 @@ import ( "fmt" "path" - "github.com/grafana/agent/pkg/build" - gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" - "github.com/grafana/agent/pkg/operator/clientutil" core_v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" + + "github.com/grafana/agent/pkg/build" + gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1" + "github.com/grafana/agent/pkg/operator/clientutil" ) type podTemplateOptions struct { @@ -258,7 +259,7 @@ func generatePodTemplate( }, Resources: d.Agent.Spec.Resources, SecurityContext: &core_v1.SecurityContext{ - Privileged: pointer.Bool(opts.Privileged), + Privileged: ptr.To(opts.Privileged), }, TerminationMessagePolicy: core_v1.TerminationMessageFallbackToLogsOnError, }, @@ -288,7 +289,7 @@ func generatePodTemplate( NodeSelector: d.Agent.Spec.NodeSelector, PriorityClassName: d.Agent.Spec.PriorityClassName, RuntimeClassName: d.Agent.Spec.RuntimeClassName, - TerminationGracePeriodSeconds: pointer.Int64(4800), + TerminationGracePeriodSeconds: ptr.To(int64(4800)), Volumes: volumes, Tolerations: d.Agent.Spec.Tolerations, Affinity: d.Agent.Spec.Affinity, diff --git a/pkg/util/testappender/internal/dtobuilder/dtobuilder.go b/pkg/util/testappender/internal/dtobuilder/dtobuilder.go index 3aa15bb9e5a7..7af96e485d85 100644 --- a/pkg/util/testappender/internal/dtobuilder/dtobuilder.go +++ b/pkg/util/testappender/internal/dtobuilder/dtobuilder.go @@ -15,7 +15,7 @@ import ( "github.com/prometheus/prometheus/model/metadata" "github.com/prometheus/prometheus/model/textparse" "google.golang.org/protobuf/types/known/timestamppb" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // Sample represents an individually written sample to a storage.Appender. @@ -118,11 +118,11 @@ func (b *builder) buildFamiliesFromMetadata() { for familyName, m := range b.Metadata { mt := textParseToMetricType(m.Type) mf := &dto.MetricFamily{ - Name: pointer.String(familyName), + Name: ptr.To(familyName), Type: &mt, } if m.Help != "" { - mf.Help = pointer.String(m.Help) + mf.Help = ptr.To(m.Help) } b.families = append(b.families, mf) @@ -225,18 +225,18 @@ func (b *builder) buildMetricsFromSamples() { // Retrieve the *dto.Metric based on labels. m := getOrCreateMetric(mf, sample.Labels) if sample.PrintTimestamp { - m.TimestampMs = pointer.Int64(sample.Timestamp) + m.TimestampMs = ptr.To(sample.Timestamp) } switch familyType(mf) { case dto.MetricType_COUNTER: m.Counter = &dto.Counter{ - Value: pointer.Float64(sample.Value), + Value: ptr.To(sample.Value), } case dto.MetricType_GAUGE: m.Gauge = &dto.Gauge{ - Value: pointer.Float64(sample.Value), + Value: ptr.To(sample.Value), } case dto.MetricType_SUMMARY: @@ -249,7 +249,7 @@ func (b *builder) buildMetricsFromSamples() { val := uint64(sample.Value) m.Summary.SampleCount = &val case metricName == mf.GetName()+"_sum": - m.Summary.SampleSum = pointer.Float64(sample.Value) + m.Summary.SampleSum = ptr.To(sample.Value) case metricName == mf.GetName(): quantile, err := strconv.ParseFloat(sample.Labels.Get(model.QuantileLabel), 64) if err != nil { @@ -258,13 +258,13 @@ func (b *builder) buildMetricsFromSamples() { m.Summary.Quantile = append(m.Summary.Quantile, &dto.Quantile{ Quantile: &quantile, - Value: pointer.Float64(sample.Value), + Value: ptr.To(sample.Value), }) } case dto.MetricType_UNTYPED: m.Untyped = &dto.Untyped{ - Value: pointer.Float64(sample.Value), + Value: ptr.To(sample.Value), } case dto.MetricType_HISTOGRAM: @@ -277,7 +277,7 @@ func (b *builder) buildMetricsFromSamples() { val := uint64(sample.Value) m.Histogram.SampleCount = &val case metricName == mf.GetName()+"_sum": - m.Histogram.SampleSum = pointer.Float64(sample.Value) + m.Histogram.SampleSum = ptr.To(sample.Value) case metricName == mf.GetName()+"_bucket": boundary, err := strconv.ParseFloat(sample.Labels.Get(model.BucketLabel), 64) if err != nil { @@ -345,8 +345,8 @@ func toLabelPairs(mt dto.MetricType, ls labels.Labels) []*dto.LabelPair { } res = append(res, &dto.LabelPair{ - Name: pointer.String(l.Name), - Value: pointer.String(l.Value), + Name: ptr.To(l.Name), + Value: ptr.To(l.Value), }) } diff --git a/tools/smoke/internal/tasks.go b/tools/smoke/internal/tasks.go index 3b887d577f77..a2243f512a4a 100644 --- a/tools/smoke/internal/tasks.go +++ b/tools/smoke/internal/tasks.go @@ -9,7 +9,7 @@ import ( "github.com/go-kit/log/level" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // The Task interface represents some unit of work performed concurrently. @@ -32,7 +32,7 @@ type deletePodTask struct { func (t *deletePodTask) Run(ctx context.Context) error { level.Debug(t.logger).Log("msg", "deleting pod") if err := t.clientset.CoreV1().Pods(t.namespace).Delete(ctx, t.pod, metav1.DeleteOptions{ - GracePeriodSeconds: pointer.Int64(0), + GracePeriodSeconds: ptr.To(int64(0)), }); err != nil { level.Error(t.logger).Log("msg", "failed to delete pod", "err", err) } @@ -91,7 +91,7 @@ func (t *deletePodBySelectorTask) Run(ctx context.Context) error { pod := list.Items[i].Name level.Debug(t.logger).Log("msg", "deleting pod", "pod", pod) if err := t.clientset.CoreV1().Pods(t.namespace).Delete(ctx, pod, metav1.DeleteOptions{ - GracePeriodSeconds: pointer.Int64(0), + GracePeriodSeconds: ptr.To(int64(0)), }); err != nil { level.Error(t.logger).Log("msg", "failed to delete pod", "pod", pod, "err", err) }