Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: linter error fixes #579

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/operator/endpoint_status_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ type scrapeEndpointBuilder struct {
}

func (b *scrapeEndpointBuilder) add(target *prometheusv1.TargetsResult) error {
b.total += 1
b.total++
if target != nil {
for _, activeTarget := range target.Active {
if err := b.addActiveTarget(activeTarget, b.time); err != nil {
return err
}
}
} else {
b.failed += 1
b.failed++
}
return nil
}
Expand Down Expand Up @@ -135,15 +135,15 @@ func newScrapeEndpointStatusBuilder(target *prometheusv1.ActiveTarget, time meta

// Adds a sample target, potentially merging with a pre-existing one.
func (b *scrapeEndpointStatusBuilder) addSampleTarget(target *prometheusv1.ActiveTarget) {
b.status.ActiveTargets += 1
b.status.ActiveTargets++
errorType := target.LastError
lastError := &errorType
if target.Health == "up" {
if len(target.LastError) == 0 {
lastError = nil
}
} else {
b.status.UnhealthyTargets += 1
b.status.UnhealthyTargets++
}

sampleGroup, ok := b.groupByError[errorType]
Expand All @@ -160,7 +160,7 @@ func (b *scrapeEndpointStatusBuilder) addSampleTarget(target *prometheusv1.Activ
}
b.groupByError[errorType] = sampleGroup
}
*sampleGroup.Count += 1
*sampleGroup.Count++
sampleGroup.SampleTargets = append(sampleGroup.SampleTargets, sampleTarget)
}

Expand Down
22 changes: 12 additions & 10 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Copyright 2022 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the tool mean to remove the copyright?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was probably just me fat fingering the deletion of the line. Good catch. I'll add that back.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -12,6 +10,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package operator contains the Prometheus operator.
package operator

import (
Expand Down Expand Up @@ -57,26 +56,29 @@ const (
// configuration data.
DefaultPublicNamespace = "gmp-public"

// Fixed names used in various resources managed by the operator.
NameOperator = "gmp-operator"
// NameOperator is a fixed name used in various resources managed by the operator.
NameOperator = "gmp-operator"
// componentName is a fixed name used in various resources managed by the operator.
componentName = "managed_prometheus"

// Filename for configuration files.
configFilename = "config.yaml"

// The well-known app name label.
// LabelAppName is the well-known app name label.
LabelAppName = "app.kubernetes.io/name"
// The component name, will be exposed as metric name.
// AnnotationMetricName is the component name, will be exposed as metric name.
AnnotationMetricName = "components.gke.io/component-name"
// ClusterAutoscalerSafeEvictionLabel is the annotation label that determines
// whether the cluster autoscaler can safely evict a Pod when the Pod doesn't
// satisfy certain eviction criteria.
ClusterAutoscalerSafeEvictionLabel = "cluster-autoscaler.kubernetes.io/safe-to-evict"

// The k8s Application, will be exposed as component name.
KubernetesAppName = "app"
// KubernetesAppName is the k8s Application, will be exposed as component name.
KubernetesAppName = "app"
// RuleEvaluatorAppName is the name of the rule-evaluator application.
RuleEvaluatorAppName = "managed-prometheus-rule-evaluator"
AlertmanagerAppName = "managed-prometheus-alertmanager"
// AlertmanagerAppName is the name of the alert manager application.
AlertmanagerAppName = "managed-prometheus-alertmanager"

// The level of concurrency to use to fetch all targets.
defaultTargetPollConcurrency = 4
Expand Down Expand Up @@ -479,7 +481,7 @@ func (o *Operator) ensureCerts(ctx context.Context, dir string) ([]byte, error)
// Use crt as the ca in the the self-sign case.
caData = crt
} else {
return nil, errors.New("Flags key-base64 and cert-base64 must both be set.")
return nil, errors.New("flags key-base64 and cert-base64 must both be set")
}
// Create cert/key files.
if err := ioutil.WriteFile(filepath.Join(dir, "tls.crt"), crt, 0666); err != nil {
Expand Down
15 changes: 8 additions & 7 deletions pkg/operator/operator_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
NameAlertmanager = "alertmanager"
)

// Secret paths
const (
RulesSecretName = "rules"
CollectionSecretName = "collection"
Expand Down Expand Up @@ -615,18 +616,18 @@ func (r *operatorConfigReconciler) makeAlertmanagerConfigs(ctx context.Context,

// getSecretOrConfigMapBytes is a helper function to conditionally fetch
// the secret or configmap selector payloads.
func getSecretOrConfigMapBytes(ctx context.Context, kClient client.Reader, namespace string, scm *monitoringv1.SecretOrConfigMap) ([]byte, error) {
func getSecretOrConfigMapBytes(ctx context.Context, c client.Reader, namespace string, scm *monitoringv1.SecretOrConfigMap) ([]byte, error) {
var (
b []byte
err error
)
if secret := scm.Secret; secret != nil {
b, err = getSecretKeyBytes(ctx, kClient, namespace, secret)
b, err = getSecretKeyBytes(ctx, c, namespace, secret)
if err != nil {
return b, err
}
} else if cm := scm.ConfigMap; cm != nil {
b, err = getConfigMapKeyBytes(ctx, kClient, namespace, cm)
b, err = getConfigMapKeyBytes(ctx, c, namespace, cm)
if err != nil {
return b, err
}
Expand All @@ -635,7 +636,7 @@ func getSecretOrConfigMapBytes(ctx context.Context, kClient client.Reader, names
}

// getSecretKeyBytes processes the given NamespacedSecretKeySelector and returns the referenced data.
func getSecretKeyBytes(ctx context.Context, kClient client.Reader, namespace string, sel *corev1.SecretKeySelector) ([]byte, error) {
func getSecretKeyBytes(ctx context.Context, c client.Reader, namespace string, sel *corev1.SecretKeySelector) ([]byte, error) {
var (
secret = &corev1.Secret{}
nn = types.NamespacedName{
Expand All @@ -644,7 +645,7 @@ func getSecretKeyBytes(ctx context.Context, kClient client.Reader, namespace str
}
bytes []byte
)
err := kClient.Get(ctx, nn, secret)
err := c.Get(ctx, nn, secret)
if err != nil {
return bytes, fmt.Errorf("unable to get secret %q: %w", sel.Name, err)
}
Expand All @@ -657,7 +658,7 @@ func getSecretKeyBytes(ctx context.Context, kClient client.Reader, namespace str
}

// getConfigMapKeyBytes processes the given NamespacedConfigMapKeySelector and returns the referenced data.
func getConfigMapKeyBytes(ctx context.Context, kClient client.Reader, namespace string, sel *corev1.ConfigMapKeySelector) ([]byte, error) {
func getConfigMapKeyBytes(ctx context.Context, c client.Reader, namespace string, sel *corev1.ConfigMapKeySelector) ([]byte, error) {
var (
cm = &corev1.ConfigMap{}
nn = types.NamespacedName{
Expand All @@ -666,7 +667,7 @@ func getConfigMapKeyBytes(ctx context.Context, kClient client.Reader, namespace
}
b []byte
)
err := kClient.Get(ctx, nn, cm)
err := c.Get(ctx, nn, cm)
if err != nil {
return b, fmt.Errorf("unable to get secret %q: %w", sel.Name, err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/target_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
}, []string{})

// Minimum duration between polls.
pollDurationMin = 10 * time.Second
minPollDuration = 10 * time.Second
)

// Responsible for fetching the targets given a pod.
Expand Down Expand Up @@ -154,7 +154,7 @@ func shouldPoll(ctx context.Context, cfgNamespacedName types.NamespacedName, kub
// Reconcile polls the collector pods, fetches and aggregates target status and
// upserts into each PodMonitoring's Status field.
func (r *targetStatusReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
timer := r.clock.NewTimer(pollDurationMin)
timer := r.clock.NewTimer(minPollDuration)

now := time.Now()

Expand Down Expand Up @@ -403,9 +403,9 @@ func getTarget(ctx context.Context, logger logr.Logger, port int32, pod *corev1.
if pod.Status.PodIP == "" {
return nil, errors.New("pod does not have IP allocated")
}
podUrl := fmt.Sprintf("http://%s:%d", pod.Status.PodIP, port)
podURL := fmt.Sprintf("http://%s:%d", pod.Status.PodIP, port)
client, err := api.NewClient(api.Config{
Address: podUrl,
Address: podURL,
})
if err != nil {
return nil, fmt.Errorf("unable to create Prometheus client: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/target_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ func TestPolling(t *testing.T) {
}()

// First tick.
fakeClock.Step(pollDurationMin)
fakeClock.Step(minPollDuration)
statusTick1 := []v1.ScrapeEndpointStatus{
{
Name: "PodMonitoring/gmp-test/prom-example-1/metrics",
Expand Down Expand Up @@ -1340,7 +1340,7 @@ func TestPolling(t *testing.T) {
expectStatus(t, "first wait", statusTick1)

// Second tick.
fakeClock.Step(pollDurationMin)
fakeClock.Step(minPollDuration)
statusTick2 := []v1.ScrapeEndpointStatus{
{
Name: "PodMonitoring/gmp-test/prom-example-1/metrics",
Expand Down Expand Up @@ -1373,7 +1373,7 @@ func TestPolling(t *testing.T) {
// We didn't tick yet so we don't expect a change yet.
expectStatus(t, "second wait", statusTick2)

fakeClock.Step(pollDurationMin)
fakeClock.Step(minPollDuration)
statusTick3 := []v1.ScrapeEndpointStatus{
{
Name: "PodMonitoring/gmp-test/prom-example-1/metrics",
Expand Down