diff --git a/.github/workflows/lint-go.yml b/.github/workflows/lint-go.yml index 4392454..b99c87f 100644 --- a/.github/workflows/lint-go.yml +++ b/.github/workflows/lint-go.yml @@ -16,4 +16,4 @@ jobs: uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main with: go-version: '1.21' - lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/cf7f3aebaad2d323730a9ab2a76f6cb78f459ee4/config/lint/.golangci.yaml + lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/a9cc2c5524838736f3f8fd084021a0116675476d/config/lint/.golangci.yaml diff --git a/pkg/commander/eventmesh/eventmesh.go b/pkg/commander/eventmesh/eventmesh.go index ae4ec95..8e5e754 100644 --- a/pkg/commander/eventmesh/eventmesh.go +++ b/pkg/commander/eventmesh/eventmesh.go @@ -27,7 +27,7 @@ import ( "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" "github.com/kyma-project/eventing-manager/pkg/logger" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // TODO: remove as this is only used in a development setup + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // IMORTANT: remove as this is only used in a development setup ) const ( diff --git a/pkg/commander/nats/nats.go b/pkg/commander/nats/nats.go index 733b345..2e7ed5e 100644 --- a/pkg/commander/nats/nats.go +++ b/pkg/commander/nats/nats.go @@ -26,7 +26,7 @@ import ( "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" "github.com/kyma-project/eventing-manager/pkg/logger" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // TODO: remove as this is only required in a dev setup + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // IMPORTANT: remove as this is only required in a dev setup ) const ( diff --git a/pkg/handler/handler_v1alpha1_test.go b/pkg/handler/handler_v1alpha1_test.go index a6a356e..ec6e11b 100644 --- a/pkg/handler/handler_v1alpha1_test.go +++ b/pkg/handler/handler_v1alpha1_test.go @@ -588,6 +588,7 @@ func TestHandler_sendEventAndRecordMetrics_TracingAndDefaults(t *testing.T) { } func CreateCloudEvent(t *testing.T) *ceevent.Event { + t.Helper() builder := epptestingutils.NewCloudEventBuilder( epptestingutils.WithCloudEventType(epptestingutils.CloudEventTypeWithPrefix), ) diff --git a/pkg/handler/health/health_test.go b/pkg/handler/health/health_test.go index 54b0916..4254674 100644 --- a/pkg/handler/health/health_test.go +++ b/pkg/handler/health/health_test.go @@ -98,6 +98,7 @@ func TestChecker(t *testing.T) { } func assertResponseLivenessStatusCode(t *testing.T, endpoint string, checker *ConfigurableChecker, statusCode int) { + t.Helper() writer := httptest.NewRecorder() request := httptest.NewRequest(http.MethodGet, endpoint, nil) @@ -107,6 +108,7 @@ func assertResponseLivenessStatusCode(t *testing.T, endpoint string, checker *Co } func assertResponseReadinessStatusCode(t *testing.T, endpoint string, checker *ConfigurableChecker, statusCode int) { + t.Helper() writer := httptest.NewRecorder() request := httptest.NewRequest(http.MethodGet, endpoint, nil) diff --git a/pkg/legacy/legacytest/test.go b/pkg/legacy/legacytest/test.go index d5f0deb..2aa0df4 100644 --- a/pkg/legacy/legacytest/test.go +++ b/pkg/legacy/legacytest/test.go @@ -42,6 +42,7 @@ func ValidLegacyRequest(version, appname, eventType string) (*http.Request, erro } func InvalidLegacyRequestOrDie(t *testing.T, version, appname, eventType string) *http.Request { + t.Helper() r, err := InvalidLegacyRequest(version, appname, eventType) assert.NoError(t, err) return r diff --git a/pkg/metrics/collector.go b/pkg/metrics/collector.go index e4685c8..e115ee2 100644 --- a/pkg/metrics/collector.go +++ b/pkg/metrics/collector.go @@ -1,8 +1,8 @@ package metrics import ( - "fmt" "net/http" + "strconv" "time" "github.com/gorilla/mux" @@ -143,7 +143,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { // RecordLatency records a backendLatencyHelp metric. func (c *Collector) RecordBackendLatency(duration time.Duration, statusCode int, destSvc string) { - c.backendLatency.WithLabelValues(fmt.Sprint(statusCode), destSvc).Observe(float64(duration.Milliseconds())) + c.backendLatency.WithLabelValues(strconv.Itoa(statusCode), destSvc).Observe(float64(duration.Milliseconds())) } // SetHealthStatus updates the health metric. @@ -157,7 +157,7 @@ func (c *Collector) SetHealthStatus(healthy bool) { // RecordEventType records an eventType metric. func (c *Collector) RecordEventType(eventType, eventSource string, statusCode int) { - c.eventType.WithLabelValues(eventType, eventSource, fmt.Sprint(statusCode)).Inc() + c.eventType.WithLabelValues(eventType, eventSource, strconv.Itoa(statusCode)).Inc() } // MetricsMiddleware returns a http.Handler that can be used as middleware in gorilla.mux to track diff --git a/pkg/metrics/metricstest/metricstest.go b/pkg/metrics/metricstest/metricstest.go index f17504e..df3acdb 100644 --- a/pkg/metrics/metricstest/metricstest.go +++ b/pkg/metrics/metricstest/metricstest.go @@ -14,15 +14,18 @@ import ( // EnsureMetricLatency ensures metric eventing_epp_backend_duration_seconds exists. func EnsureMetricLatency(t *testing.T, collector metrics.PublishingMetricsCollector, count int) { + t.Helper() ensureMetricCount(t, collector, metrics.BackendLatencyKey, count) } // EnsureMetricEventTypePublished ensures metric eventing_epp_event_type_published_total exists. func EnsureMetricEventTypePublished(t *testing.T, collector metrics.PublishingMetricsCollector, count int) { + t.Helper() ensureMetricCount(t, collector, metrics.EventTypePublishedMetricKey, count) } func ensureMetricCount(t *testing.T, collector metrics.PublishingMetricsCollector, metric string, expectedCount int) { + t.Helper() if count := testutil.CollectAndCount(collector, metric); count != expectedCount { t.Fatalf("invalid count for metric:%s, want:%d, got:%d", metric, expectedCount, count) } @@ -34,6 +37,7 @@ func ensureMetricCount(t *testing.T, collector metrics.PublishingMetricsCollecto func EnsureMetricMatchesTextExpositionFormat(t *testing.T, collector metrics.PublishingMetricsCollector, tef string, metricNames ...string, ) { + t.Helper() if err := testutil.CollectAndCompare(collector, strings.NewReader(tef), metricNames...); err != nil { t.Fatalf("%v", err) } diff --git a/pkg/receiver/receiver_test.go b/pkg/receiver/receiver_test.go index 3ee1246..ac81e82 100644 --- a/pkg/receiver/receiver_test.go +++ b/pkg/receiver/receiver_test.go @@ -43,6 +43,7 @@ func TestStartListener(t *testing.T) { defer close(start) wg.Add(1) go func(t *testing.T) { + t.Helper() defer wg.Done() start <- true t.Log("starting receiver in goroutine") diff --git a/pkg/sender/jetstream/jetstream_test.go b/pkg/sender/jetstream/jetstream_test.go index 4787404..49b0c16 100644 --- a/pkg/sender/jetstream/jetstream_test.go +++ b/pkg/sender/jetstream/jetstream_test.go @@ -108,6 +108,7 @@ type TestEnvironment struct { // setupTestEnvironment sets up the resources and mocks required for testing. func setupTestEnvironment(t *testing.T) *TestEnvironment { + t.Helper() natsServer := epptestingutils.StartNATSServer() require.NotNil(t, natsServer) @@ -141,6 +142,7 @@ func setupTestEnvironment(t *testing.T) *TestEnvironment { // createCloudEvent build a cloud event. func createCloudEvent(t *testing.T) *event.Event { + t.Helper() jsType := fmt.Sprintf("%s.%s", epptestingutils.StreamName, epptestingutils.CloudEventTypeWithPrefix) builder := epptestingutils.NewCloudEventBuilder( epptestingutils.WithCloudEventType(jsType), @@ -177,6 +179,7 @@ func getConsumerConfig() *natsgo.ConsumerConfig { // addStream creates a stream for the test events. func addStream(t *testing.T, connection *natsgo.Conn, config *natsgo.StreamConfig) { + t.Helper() js, err := connection.JetStream() assert.NoError(t, err) info, err := js.AddStream(config) @@ -185,6 +188,7 @@ func addStream(t *testing.T, connection *natsgo.Conn, config *natsgo.StreamConfi } func addConsumer(t *testing.T, connection *natsgo.Conn, sc *natsgo.StreamConfig, config *natsgo.ConsumerConfig) { + t.Helper() js, err := connection.JetStream() assert.NoError(t, err) info, err := js.AddConsumer(sc.Name, config) diff --git a/pkg/subscribed/helpers.go b/pkg/subscribed/helpers.go index 76140c4..ba0ff0b 100644 --- a/pkg/subscribed/helpers.go +++ b/pkg/subscribed/helpers.go @@ -152,7 +152,7 @@ func FilterEventTypeVersionsV1alpha1(eventTypePrefix, bebNs, appName string, continue } - // TODO revisit the filtration logic as part of https://github.com/kyma-project/kyma/issues/10761 + // IMPORTANT revisit the filtration logic as part of https://github.com/kyma-project/kyma/issues/10761 // filter by event-source if exists if len(strings.TrimSpace(filter.EventSource.Value)) > 0 && !strings.EqualFold(filter.EventSource.Value, bebNs) { diff --git a/pkg/subscribed/helpers_test.go b/pkg/subscribed/helpers_test.go index c9ea97e..e0323b4 100644 --- a/pkg/subscribed/helpers_test.go +++ b/pkg/subscribed/helpers_test.go @@ -352,16 +352,16 @@ func NewEventMeshFilters(opts ...EventMeshFilterOption) *emeventingv1alpha1.BEBF } func WithOneEventMeshFilter(filters *emeventingv1alpha1.BEBFilters) { - evSource := "/default/foo.kyma/kt1" - evType := "foo.prefix.custom.foovarkes.order.created.v1" + const evSource = "/default/foo.kyma/kt1" + const evType = "foo.prefix.custom.foovarkes.order.created.v1" filters.Filters = []*emeventingv1alpha1.EventMeshFilter{ NewEventMeshFilter(evSource, evType), } } func WithMultipleEventMeshFiltersFromSameSource(filters *emeventingv1alpha1.BEBFilters) { - evSource := "/default/foo.kyma/kt1" - evType := "foo.prefix.custom.foovarkes.order.created.v1" + const evSource = "/default/foo.kyma/kt1" + const evType = "foo.prefix.custom.foovarkes.order.created.v1" filters.Filters = []*emeventingv1alpha1.EventMeshFilter{ NewEventMeshFilter(evSource, evType), NewEventMeshFilter(evSource, evType), @@ -374,7 +374,7 @@ func WithMultipleEventMeshFiltersFromDiffSource(filters *emeventingv1alpha1.BEBF evSource2 := "/default/foo.different/kt1" evSource3 := "/default/foo.different2/kt1" evSource4 := "" - evType := "foo.prefix.custom.foovarkes.order.created.v1" + const evType = "foo.prefix.custom.foovarkes.order.created.v1" filters.Filters = []*emeventingv1alpha1.EventMeshFilter{ NewEventMeshFilter(evSource1, evType), NewEventMeshFilter(evSource2, evType), diff --git a/pkg/tracing/helpers.go b/pkg/tracing/helpers.go index 7391cd6..a438ebb 100644 --- a/pkg/tracing/helpers.go +++ b/pkg/tracing/helpers.go @@ -1,7 +1,6 @@ package tracing import ( - "fmt" "net/http" ceevent "github.com/cloudevents/sdk-go/v2/event" @@ -27,7 +26,7 @@ func AddTracingContextToCEExtensions(reqHeaders http.Header, event *ceevent.Even traceParent := reqHeaders.Get(traceParentKey) if len(traceParent) > 0 { st := extensions.DistributedTracingExtension{ - TraceParent: fmt.Sprintf("%v", traceParent), + TraceParent: traceParent, } st.AddTracingAttributes(event) } diff --git a/testing/fixtures.go b/testing/fixtures.go index 1dc9b7d..0a21394 100644 --- a/testing/fixtures.go +++ b/testing/fixtures.go @@ -129,6 +129,7 @@ func (b *CloudEventBuilder) BuildStructured() (string, http.Header) { } func (b *CloudEventBuilder) Build(t *testing.T) *ceevent.Event { + t.Helper() e := ceevent.New(b.specVersion) assert.NoError(t, e.Context.SetID(b.id)) assert.NoError(t, e.Context.SetType(b.eventType)) diff --git a/testing/mock_server.go b/testing/mock_server.go index f52f33c..2764919 100644 --- a/testing/mock_server.go +++ b/testing/mock_server.go @@ -48,6 +48,7 @@ func WithValidator(validator Validator) MockServerOption { } func (m *MockServer) Start(t *testing.T, tokenEndpoint, eventsEndpoint, eventsWithHTTP400 string) { + t.Helper() m.server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { time.Sleep(m.responseTime)