Skip to content

Commit

Permalink
Cleanup merge + missing review comments + fix deprecations from go.mo…
Browse files Browse the repository at this point in the history
…d update
  • Loading branch information
kgeckhart committed Nov 17, 2023
1 parent c5c802a commit 33f19e1
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 54 deletions.
5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ v0.38.0-rc.0 (2023-11-16)
- renamed 3 metrics starting with `mysql_perf_schema_transaction_` to start with `mysql_perf_schema_transactions_` to be consistent with column names.
- exposing only server's own stats by matching `MEMBER_ID` with `@@server_uuid` resulting "member_id" label to be dropped.

### Other changes

- Bump `mysqld_exporter` version to v0.15.0. (@marctc)
- Bump `github-exporter` version to 1.0.6. (@marctc)

### Features

- Added a new `stage.decolorize` stage to `loki.process` component which
Expand Down
6 changes: 4 additions & 2 deletions component/otelcol/config_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The account used by Grafana Agent needs:
# Can't be used if `regions` is set.
[resource_graph_query_filter: <string>]

# 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:
Expand Down Expand Up @@ -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: <string> | 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: <bool> | default = false]
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,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
Expand Down Expand Up @@ -618,6 +617,7 @@ require (
github.com/prometheus/tsdb v0.10.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.42.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
k8s.io/apimachinery v0.28.3
)

require (
Expand Down
11 changes: 6 additions & 5 deletions pkg/operator/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down
15 changes: 8 additions & 7 deletions pkg/operator/config/metrics_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"},
},
},
Expand Down
11 changes: 6 additions & 5 deletions pkg/operator/reconciler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions pkg/operator/resources_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}},
Expand Down
13 changes: 7 additions & 6 deletions pkg/operator/resources_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions pkg/util/testappender/internal/dtobuilder/dtobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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.
Expand Down Expand Up @@ -106,11 +106,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)
Expand Down Expand Up @@ -164,18 +164,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:
Expand All @@ -188,7 +188,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 {
Expand All @@ -197,13 +197,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:
Expand All @@ -216,7 +216,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 {
Expand Down Expand Up @@ -284,8 +284,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),
})
}

Expand Down
6 changes: 3 additions & 3 deletions tools/smoke/internal/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 33f19e1

Please sign in to comment.