diff --git a/cmd/event-publisher-proxy/main.go b/cmd/event-publisher-proxy/main.go index d4174ac..f5c3983 100644 --- a/cmd/event-publisher-proxy/main.go +++ b/cmd/event-publisher-proxy/main.go @@ -1,4 +1,4 @@ -package main +package main //nolint:cyclop // it is only starting required instances. import ( golog "log" @@ -7,12 +7,12 @@ import ( kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/prometheus/client_golang/prometheus" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander/eventmesh" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander/nats" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/latency" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/commander" + "github.com/kyma-project/eventing-publisher-proxy/pkg/commander/eventmesh" + "github.com/kyma-project/eventing-publisher-proxy/pkg/commander/nats" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/latency" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" ) const ( diff --git a/go.mod b/go.mod index d9b1e14..4b270d0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/kyma-project/kyma/components/event-publisher-proxy +module github.com/kyma-project/eventing-publisher-proxy go 1.21 diff --git a/pkg/application/clean_test.go b/pkg/application/clean_test.go index 16cb9aa..58c87dd 100644 --- a/pkg/application/clean_test.go +++ b/pkg/application/clean_test.go @@ -7,7 +7,7 @@ import ( applicationv1alpha1 "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" ) func TestCleanName(t *testing.T) { @@ -69,12 +69,15 @@ func TestCleanName(t *testing.T) { for _, tc := range testCases { if gotName := GetCleanTypeOrName(tc.givenApplication); tc.wantName != gotName { - t.Errorf("Clean application name:[%s] failed, want:[%v] but got:[%v]", tc.givenApplication.Name, tc.wantName, gotName) + t.Errorf("Clean application name:[%s] failed, want:[%v] but got:[%v]", + tc.givenApplication.Name, tc.wantName, gotName) } } } func Test_GetTypeOrName(t *testing.T) { + t.Parallel() + testCases := []struct { name string givenApplication *applicationv1alpha1.Application @@ -87,9 +90,10 @@ func Test_GetTypeOrName(t *testing.T) { wantName: "alphanumeric0123", }, { - name: "Should return application name if label with right key does not exists", - givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{"ignore-me": "value"}), - wantName: "alphanumeric0123", + name: "Should return application name if label with right key does not exists", + givenApplication: applicationtest.NewApplication("alphanumeric0123", + map[string]string{"ignore-me": "value"}), + wantName: "alphanumeric0123", }, { name: "Should return application name as unclean", @@ -98,14 +102,16 @@ func Test_GetTypeOrName(t *testing.T) { }, // application type label is available, then use it instead of the application name { - name: "Should return application label instead of name", - givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{TypeLabel: "apptype"}), - wantName: "apptype", + name: "Should return application label instead of name", + givenApplication: applicationtest.NewApplication("alphanumeric0123", + map[string]string{TypeLabel: "apptype"}), + wantName: "apptype", }, { - name: "Should return application label as unclean", - givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{TypeLabel: "apptype=with.!@#none-$%^alphanumeric_&*-characters"}), - wantName: "apptype=with.!@#none-$%^alphanumeric_&*-characters", + name: "Should return application label as unclean", + givenApplication: applicationtest.NewApplication("alphanumeric0123", + map[string]string{TypeLabel: "apptype=with.!@#none-$%^alphanumeric_&*-characters"}), + wantName: "apptype=with.!@#none-$%^alphanumeric_&*-characters", }, } diff --git a/pkg/application/fake/lister.go b/pkg/application/fake/lister.go index ed1de51..3451f98 100644 --- a/pkg/application/fake/lister.go +++ b/pkg/application/fake/lister.go @@ -10,7 +10,7 @@ import ( applicationv1alpha1 "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" ) func NewApplicationListerOrDie(ctx context.Context, app *applicationv1alpha1.Application) *application.Lister { diff --git a/pkg/application/lister.go b/pkg/application/lister.go index 93ec16a..73001b9 100644 --- a/pkg/application/lister.go +++ b/pkg/application/lister.go @@ -15,7 +15,7 @@ import ( "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/tools/cache" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers" + "github.com/kyma-project/eventing-publisher-proxy/pkg/informers" ) type Lister struct { diff --git a/pkg/cloudevents/builder/eventmesh.go b/pkg/cloudevents/builder/eventmesh.go index 80553f8..fb8b553 100644 --- a/pkg/cloudevents/builder/eventmesh.go +++ b/pkg/cloudevents/builder/eventmesh.go @@ -6,7 +6,7 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" ) // Perform a compile-time check. diff --git a/pkg/cloudevents/builder/eventmesh_test.go b/pkg/cloudevents/builder/eventmesh_test.go index c115d72..b6dde2d 100644 --- a/pkg/cloudevents/builder/eventmesh_test.go +++ b/pkg/cloudevents/builder/eventmesh_test.go @@ -9,10 +9,10 @@ import ( cloudevents "github.com/cloudevents/sdk-go/v2" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" "github.com/stretchr/testify/require" diff --git a/pkg/cloudevents/builder/generic.go b/pkg/cloudevents/builder/generic.go index ae09129..2a41663 100644 --- a/pkg/cloudevents/builder/generic.go +++ b/pkg/cloudevents/builder/generic.go @@ -10,18 +10,19 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" "go.uber.org/zap" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" ) // Perform a compile-time check. var _ CloudEventBuilder = &GenericBuilder{} -var ( +const ( // jsBuilderName used as the logger name. genericBuilderName = "generic-type-builder" ) -func NewGenericBuilder(typePrefix string, cleaner cleaner.Cleaner, applicationLister *application.Lister, logger *logger.Logger) CloudEventBuilder { +func NewGenericBuilder(typePrefix string, cleaner cleaner.Cleaner, applicationLister *application.Lister, + logger *logger.Logger) CloudEventBuilder { return &GenericBuilder{ typePrefix: typePrefix, applicationLister: applicationLister, @@ -84,7 +85,8 @@ func (gb *GenericBuilder) GetAppNameOrSource(source string, namedLogger *zap.Sug if gb.isApplicationListerEnabled() { if appObj, err := gb.applicationLister.Get(source); err == nil && appObj != nil { appName = application.GetTypeOrName(appObj) - namedLogger.With("application", source).Debug("Using application name: %s as source.", appName) + namedLogger.With("application", source).Debug("Using application name: %s as source.", + appName) } else { namedLogger.With("application", source).Debug("Cannot find application.") } diff --git a/pkg/cloudevents/builder/generic_test.go b/pkg/cloudevents/builder/generic_test.go index 31d63f7..32e1ea2 100644 --- a/pkg/cloudevents/builder/generic_test.go +++ b/pkg/cloudevents/builder/generic_test.go @@ -7,11 +7,11 @@ import ( "testing" cloudevents "github.com/cloudevents/sdk-go/v2" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" "github.com/stretchr/testify/require" diff --git a/pkg/cloudevents/builder/types.go b/pkg/cloudevents/builder/types.go index f2764df..4b91756 100644 --- a/pkg/cloudevents/builder/types.go +++ b/pkg/cloudevents/builder/types.go @@ -2,7 +2,7 @@ package builder import ( cev2event "github.com/cloudevents/sdk-go/v2/event" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" ) diff --git a/pkg/cloudevents/eventtype/clean.go b/pkg/cloudevents/eventtype/clean.go index 43c4959..df8f3b4 100644 --- a/pkg/cloudevents/eventtype/clean.go +++ b/pkg/cloudevents/eventtype/clean.go @@ -8,7 +8,7 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/logger" "go.uber.org/zap" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" ) var ( diff --git a/pkg/cloudevents/eventtype/clean_test.go b/pkg/cloudevents/eventtype/clean_test.go index 90b6edb..2c642fb 100644 --- a/pkg/cloudevents/eventtype/clean_test.go +++ b/pkg/cloudevents/eventtype/clean_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" ) //nolint:lll // we need long lines here as the event types can get very long diff --git a/pkg/cloudevents/eventtype/eventtypetest/eventtypetest.go b/pkg/cloudevents/eventtype/eventtypetest/eventtypetest.go index 4c2a624..f41e9fb 100644 --- a/pkg/cloudevents/eventtype/eventtypetest/eventtypetest.go +++ b/pkg/cloudevents/eventtype/eventtypetest/eventtypetest.go @@ -15,7 +15,3 @@ func (c CleanerStub) Clean(_ string) (string, error) { func (cf CleanerFunc) Clean(eventType string) (string, error) { return cf(eventType) } - -var DefaultCleaner = func(eventType string) (string, error) { - return eventType, nil -} diff --git a/pkg/cloudevents/eventtype/parse.go b/pkg/cloudevents/eventtype/parse.go index 1dbf210..f157efd 100644 --- a/pkg/cloudevents/eventtype/parse.go +++ b/pkg/cloudevents/eventtype/parse.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" ) // parse splits the event-type using the given prefix and returns the application name, event and version diff --git a/pkg/cloudevents/utils_test.go b/pkg/cloudevents/utils_test.go index e49a354..a7e8464 100644 --- a/pkg/cloudevents/utils_test.go +++ b/pkg/cloudevents/utils_test.go @@ -10,8 +10,8 @@ import ( cehttp "github.com/cloudevents/sdk-go/v2/protocol/http" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/eventmesh" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/eventmesh" ) func TestWriteRequestWithHeaders(t *testing.T) { diff --git a/pkg/commander/eventmesh/eventmesh.go b/pkg/commander/eventmesh/eventmesh.go index 7664b13..eddce57 100644 --- a/pkg/commander/eventmesh/eventmesh.go +++ b/pkg/commander/eventmesh/eventmesh.go @@ -4,21 +4,21 @@ import ( "context" "github.com/kelseyhightower/envconfig" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/oauth" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/eventmesh" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/signals" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" + "github.com/kyma-project/eventing-publisher-proxy/pkg/informers" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/oauth" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/receiver" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/eventmesh" + "github.com/kyma-project/eventing-publisher-proxy/pkg/signals" + "github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed" "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" @@ -101,7 +101,7 @@ func (c *Commander) Start() error { // Configure Subscription Lister subDynamicSharedInfFactory := subscribed.GenerateSubscriptionInfFactory(k8sConfig) - subLister := subDynamicSharedInfFactory.ForResource(subscribed.GVR).Lister() + subLister := subDynamicSharedInfFactory.ForResource(subscribed.SubscriptionGVR()).Lister() subscribedProcessor := &subscribed.Processor{ SubscriptionLister: &subLister, Prefix: c.envCfg.EventTypePrefix, diff --git a/pkg/commander/nats/nats.go b/pkg/commander/nats/nats.go index 4343e49..ba39129 100644 --- a/pkg/commander/nats/nats.go +++ b/pkg/commander/nats/nats.go @@ -4,20 +4,20 @@ import ( "context" "github.com/kelseyhightower/envconfig" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" - pkgnats "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/nats" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/jetstream" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/signals" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler" + "github.com/kyma-project/eventing-publisher-proxy/pkg/informers" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" + pkgnats "github.com/kyma-project/eventing-publisher-proxy/pkg/nats" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/receiver" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/jetstream" + "github.com/kyma-project/eventing-publisher-proxy/pkg/signals" + "github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed" "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" @@ -108,7 +108,7 @@ func (c *Commander) Start() error { // configure Subscription Lister subDynamicSharedInfFactory := subscribed.GenerateSubscriptionInfFactory(k8sConfig) - subLister := subDynamicSharedInfFactory.ForResource(subscribed.GVR).Lister() + subLister := subDynamicSharedInfFactory.ForResource(subscribed.SubscriptionGVR()).Lister() subscribedProcessor := &subscribed.Processor{ SubscriptionLister: &subLister, Prefix: c.envCfg.ToConfig().EventTypePrefix, diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 673c94c..8f98c60 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -7,10 +7,10 @@ import ( "strings" "time" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" "github.com/gorilla/mux" "github.com/kyma-project/kyma/components/eventing-controller/logger" @@ -21,15 +21,15 @@ import ( cev2event "github.com/cloudevents/sdk-go/v2/event" cev2http "github.com/cloudevents/sdk-go/v2/protocol/http" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/tracing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/receiver" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + "github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed" + "github.com/kyma-project/eventing-publisher-proxy/pkg/tracing" ) // EventingHandler is responsible for receiving HTTP requests and dispatching them to the Backend. @@ -149,6 +149,7 @@ func (h *Handler) handlePublishLegacyEvent(w http.ResponseWriter, r *http.Reques ceEvent, err := h.LegacyTransformer.TransformPublishRequestToCloudEvent(data) if err != nil { legacy.WriteJSONResponse(w, legacy.ErrorResponse(http.StatusInternalServerError, err)) + //nolint:nilnil // this will be removed once subscription v1alpha1 is removed. return nil, nil } @@ -175,6 +176,7 @@ func (h *Handler) handlePublishLegacyEventV1alpha1(w http.ResponseWriter, r *htt event, _ := h.LegacyTransformer.WriteLegacyRequestsToCE(w, data) if event == nil { h.namedLogger().Error("Failed to transform legacy event to CloudEvent, event is nil") + //nolint:nilnil // this will be removed once subscription v1alpha1 is removed. return nil, nil } diff --git a/pkg/handler/handler_test.go b/pkg/handler/handler_test.go index cf96c93..46a605c 100644 --- a/pkg/handler/handler_test.go +++ b/pkg/handler/handler_test.go @@ -1,4 +1,3 @@ -//nolint:lll // output directly from prometheus package handler import ( @@ -12,28 +11,28 @@ import ( "github.com/stretchr/testify/require" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/legacytest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/common" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/jetstream" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/legacytest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/common" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/jetstream" eclogger "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner" "github.com/stretchr/testify/assert" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype/eventtypetest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/histogram/mocks" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/metricstest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype/eventtypetest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/histogram/mocks" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/metricstest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) func TestHandler_publishCloudEvents(t *testing.T) { diff --git a/pkg/handler/handler_v1alpha1_test.go b/pkg/handler/handler_v1alpha1_test.go index ea640e0..61f41d3 100644 --- a/pkg/handler/handler_v1alpha1_test.go +++ b/pkg/handler/handler_v1alpha1_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/common" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/common" cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/cloudevents/sdk-go/v2/client" @@ -22,17 +22,17 @@ import ( eclogger "github.com/kyma-project/kyma/components/eventing-controller/logger" "github.com/stretchr/testify/assert" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype/eventtypetest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/histogram/mocks" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/metricstest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype/eventtypetest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/histogram/mocks" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/metricstest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) func Test_extractCloudEventFromRequest(t *testing.T) { diff --git a/pkg/informers/sync.go b/pkg/informers/sync.go index e9648e9..1853ba9 100644 --- a/pkg/informers/sync.go +++ b/pkg/informers/sync.go @@ -17,7 +17,8 @@ const ( type waitForCacheSyncFunc func(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool // WaitForCacheSyncOrDie waits for the cache to sync. If sync fails everything stops. -func WaitForCacheSyncOrDie(ctx context.Context, dc dynamicinformer.DynamicSharedInformerFactory, logger *logger.Logger) { +func WaitForCacheSyncOrDie(ctx context.Context, dc dynamicinformer.DynamicSharedInformerFactory, + logger *logger.Logger) { dc.Start(ctx.Done()) ctx, cancel := context.WithTimeout(context.Background(), DefaultResyncPeriod) diff --git a/pkg/legacy/error_responses.go b/pkg/legacy/error_responses.go index ce5e9b4..4e474e3 100644 --- a/pkg/legacy/error_responses.go +++ b/pkg/legacy/error_responses.go @@ -3,7 +3,7 @@ package legacy import ( "net/http" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" ) // An HTTPErrorResponse represents an error with a status code and an error message. diff --git a/pkg/legacy/helpers.go b/pkg/legacy/helpers.go index 2e66e8e..1f0d815 100644 --- a/pkg/legacy/helpers.go +++ b/pkg/legacy/helpers.go @@ -8,8 +8,8 @@ import ( kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" ) const ( diff --git a/pkg/legacy/legacy.go b/pkg/legacy/legacy.go index 793e6cf..fd73186 100644 --- a/pkg/legacy/legacy.go +++ b/pkg/legacy/legacy.go @@ -12,9 +12,9 @@ import ( "github.com/google/uuid" "github.com/pkg/errors" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - apiv1 "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + apiv1 "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" ) var ( @@ -53,7 +53,7 @@ func (t *Transformer) isApplicationListerEnabled() bool { } // CheckParameters validates the parameters in the request and sends error responses if found invalid. -func (t *Transformer) checkParameters(parameters *apiv1.PublishEventParametersV1) (response *apiv1.PublishEventResponses) { +func (t *Transformer) checkParameters(parameters *apiv1.PublishEventParametersV1) *apiv1.PublishEventResponses { if parameters == nil { return ErrorResponseBadRequest(ErrorMessageBadPayload) } @@ -86,7 +86,8 @@ func (t *Transformer) checkParameters(parameters *apiv1.PublishEventParametersV1 } // ExtractPublishRequestData extracts the data for publishing event from the given legacy event request. -func (t *Transformer) ExtractPublishRequestData(request *http.Request) (*apiv1.PublishRequestData, *apiv1.PublishEventResponses, error) { +func (t *Transformer) ExtractPublishRequestData(request *http.Request) (*apiv1.PublishRequestData, + *apiv1.PublishEventResponses, error) { // parse request body to PublishRequestV1 if request.Body == nil || request.ContentLength == 0 { resp := ErrorResponseBadRequest(ErrorMessageBadPayload) @@ -124,7 +125,8 @@ func (t *Transformer) ExtractPublishRequestData(request *http.Request) (*apiv1.P // WriteLegacyRequestsToCE transforms the legacy event to cloudevent from the given request. // It also returns the original event-type without cleanup as the second return type. -func (t *Transformer) WriteLegacyRequestsToCE(writer http.ResponseWriter, publishData *apiv1.PublishRequestData) (*cev2.Event, string) { +func (t *Transformer) WriteLegacyRequestsToCE(writer http.ResponseWriter, + publishData *apiv1.PublishRequestData) (*cev2.Event, string) { uncleanedAppName := publishData.ApplicationName // clean the application name form non-alphanumeric characters @@ -153,7 +155,8 @@ func (t *Transformer) WriteLegacyRequestsToCE(writer http.ResponseWriter, publis return event, eventType } -func (t *Transformer) WriteCEResponseAsLegacyResponse(writer http.ResponseWriter, statusCode int, event *cev2.Event, msg string) { +func (t *Transformer) WriteCEResponseAsLegacyResponse(writer http.ResponseWriter, statusCode int, + event *cev2.Event, msg string) { response := &apiv1.PublishEventResponses{} // Fail if !is2XXStatusCode(statusCode) { @@ -171,7 +174,8 @@ func (t *Transformer) WriteCEResponseAsLegacyResponse(writer http.ResponseWriter } // TransformPublishRequestToCloudEvent converts the given publish request to a CloudEvent with raw values. -func (t *Transformer) TransformPublishRequestToCloudEvent(publishRequestData *apiv1.PublishRequestData) (*cev2.Event, error) { +func (t *Transformer) TransformPublishRequestToCloudEvent(publishRequestData *apiv1.PublishRequestData) (*cev2.Event, + error) { source := publishRequestData.ApplicationName publishRequest := publishRequestData.PublishEventParameters @@ -210,7 +214,8 @@ func (t *Transformer) TransformPublishRequestToCloudEvent(publishRequestData *ap } // convertPublishRequestToCloudEvent converts the given publish request to a CloudEvent. -func (t *Transformer) convertPublishRequestToCloudEvent(appName string, publishRequest *apiv1.PublishEventParametersV1) (*cev2.Event, error) { +func (t *Transformer) convertPublishRequestToCloudEvent(appName string, + publishRequest *apiv1.PublishEventParametersV1) (*cev2.Event, error) { if !application.IsCleanName(appName) { return nil, errors.New("application name should be cleaned from none-alphanumeric characters") } diff --git a/pkg/legacy/legacy_test.go b/pkg/legacy/legacy_test.go index d428edd..dd1c887 100644 --- a/pkg/legacy/legacy_test.go +++ b/pkg/legacy/legacy_test.go @@ -13,13 +13,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake" - legacyapi "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/legacytest" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest" + "github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake" + legacyapi "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/legacytest" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) const ( @@ -173,7 +173,8 @@ func TestConvertPublishRequestToCloudEvent(t *testing.T) { wantEventMeshNamespace := testingutils.MessagingNamespace wantEventID := givenEventID - wantEventType := formatEventType(givenEventTypePrefix, givenApplicationName, eventTypeMultiSegmentCombined, givenLegacyEventVersion) + wantEventType := formatEventType(givenEventTypePrefix, givenApplicationName, eventTypeMultiSegmentCombined, + givenLegacyEventVersion) wantTimeNowFormatted, _ := time.Parse(time.RFC3339, givenTimeNow) wantDataContentType := internal.ContentTypeApplicationJSON diff --git a/pkg/metrics/collector.go b/pkg/metrics/collector.go index 29f42fd..b4f331e 100644 --- a/pkg/metrics/collector.go +++ b/pkg/metrics/collector.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/histogram" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/histogram" ) const ( diff --git a/pkg/metrics/collector_test.go b/pkg/metrics/collector_test.go index ab90fb2..0051581 100644 --- a/pkg/metrics/collector_test.go +++ b/pkg/metrics/collector_test.go @@ -11,8 +11,8 @@ import ( "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/histogram/mocks" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/latency" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/histogram/mocks" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/latency" ) func TestNewCollector(t *testing.T) { diff --git a/pkg/metrics/histogram/mocks/BucketsProvider.go b/pkg/metrics/histogram/mocks/BucketsProvider.go index 7efa77e..39382bd 100644 --- a/pkg/metrics/histogram/mocks/BucketsProvider.go +++ b/pkg/metrics/histogram/mocks/BucketsProvider.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -24,3 +24,17 @@ func (_m *BucketsProvider) Buckets() []float64 { return r0 } + +// NewBucketsProvider creates a new instance of BucketsProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBucketsProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *BucketsProvider { + mock := &BucketsProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/metrics/metricstest/metricstest.go b/pkg/metrics/metricstest/metricstest.go index 8d29fe9..3abf504 100644 --- a/pkg/metrics/metricstest/metricstest.go +++ b/pkg/metrics/metricstest/metricstest.go @@ -10,7 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics" + "github.com/kyma-project/eventing-publisher-proxy/pkg/metrics" ) // EnsureMetricLatency ensures metric eventing_epp_backend_duration_seconds exists. @@ -32,7 +32,8 @@ func ensureMetricCount(t *testing.T, collector metrics.PublishingMetricsCollecto // EnsureMetricMatchesTextExpositionFormat ensures that metrics collected by the given collector // match the given metric output in TextExpositionFormat. // This is useful to compare metrics with their given labels. -func EnsureMetricMatchesTextExpositionFormat(t *testing.T, collector metrics.PublishingMetricsCollector, tef string, metricNames ...string) { +func EnsureMetricMatchesTextExpositionFormat(t *testing.T, collector metrics.PublishingMetricsCollector, + tef string, metricNames ...string) { if err := testutil.CollectAndCompare(collector, strings.NewReader(tef), metricNames...); err != nil { t.Fatalf("%v", err) } diff --git a/pkg/nats/connect.go b/pkg/nats/connect.go index a2dc3fe..ba17023 100644 --- a/pkg/nats/connect.go +++ b/pkg/nats/connect.go @@ -8,6 +8,7 @@ import ( type Opt = nats.Option +//nolint:gochecknoglobals // cloning functions as variables. var ( WithRetryOnFailedConnect = nats.RetryOnFailedConnect WithMaxReconnects = nats.MaxReconnects diff --git a/pkg/nats/connect_test.go b/pkg/nats/connect_test.go index 95069e0..8e4617c 100644 --- a/pkg/nats/connect_test.go +++ b/pkg/nats/connect_test.go @@ -4,11 +4,12 @@ import ( "testing" "time" - "github.com/nats-io/nats.go" + natsgo "github.com/nats-io/nats.go" + "github.com/stretchr/testify/assert" - pkgnats "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/nats" - publishertesting "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + pkgnats "github.com/kyma-project/eventing-publisher-proxy/pkg/nats" + publishertesting "github.com/kyma-project/eventing-publisher-proxy/testing" ) func TestConnect(t *testing.T) { @@ -54,7 +55,7 @@ func TestConnect(t *testing.T) { defer func() { connection.Close() }() // then - assert.Equal(t, connection.Status(), nats.CONNECTED) + assert.Equal(t, connection.Status(), natsgo.CONNECTED) assert.Equal(t, clientURL, connection.Opts.Servers[0]) assert.Equal(t, tc.givenRetryOnFailedConnect, connection.Opts.RetryOnFailedConnect) assert.Equal(t, tc.givenMaxReconnect, connection.Opts.MaxReconnect) diff --git a/pkg/oauth/client.go b/pkg/oauth/client.go index f2653ab..ae04cb5 100644 --- a/pkg/oauth/client.go +++ b/pkg/oauth/client.go @@ -7,8 +7,8 @@ import ( "go.opencensus.io/plugin/ochttp" "golang.org/x/oauth2" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/tracing/propagation/tracecontextb3" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/tracing/propagation/tracecontextb3" ) // NewClient returns a new HTTP client which have nested transports for handling oauth2 security, @@ -26,7 +26,7 @@ func NewClient(ctx context.Context, cfg *env.EventMeshConfig) *http.Client { // configure tracing transport client.Transport = &ochttp.Transport{ Base: client.Transport, - Propagation: tracecontextb3.TraceContextEgress, + Propagation: tracecontextb3.TraceContextEgress(), } return client diff --git a/pkg/oauth/client_test.go b/pkg/oauth/client_test.go index 0cc2b32..e3eb9f3 100644 --- a/pkg/oauth/client_test.go +++ b/pkg/oauth/client_test.go @@ -10,8 +10,8 @@ import ( "go.opencensus.io/plugin/ochttp" "golang.org/x/oauth2" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) func TestNewClient(t *testing.T) { diff --git a/pkg/oauth/config.go b/pkg/oauth/config.go index bf55a70..6f0bfba 100644 --- a/pkg/oauth/config.go +++ b/pkg/oauth/config.go @@ -3,7 +3,7 @@ package oauth import ( "golang.org/x/oauth2/clientcredentials" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" ) // Config returns a new oauth2 client credentials config instance. diff --git a/pkg/oauth/config_test.go b/pkg/oauth/config_test.go index c698c1e..3131914 100644 --- a/pkg/oauth/config_test.go +++ b/pkg/oauth/config_test.go @@ -3,7 +3,7 @@ package oauth import ( "testing" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" ) func TestConfig(t *testing.T) { diff --git a/pkg/receiver/receiver_test.go b/pkg/receiver/receiver_test.go index d67f411..dbeb2cc 100644 --- a/pkg/receiver/receiver_test.go +++ b/pkg/receiver/receiver_test.go @@ -9,7 +9,7 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/logger" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) // a mocked http.Handler. diff --git a/pkg/sender/common/backendpublisherror.go b/pkg/sender/common/backendpublisherror.go index b7d6520..d5d56ae 100644 --- a/pkg/sender/common/backendpublisherror.go +++ b/pkg/sender/common/backendpublisherror.go @@ -3,7 +3,7 @@ package common import ( "net/http" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" ) var _ sender.PublishError = &BackendPublishError{} diff --git a/pkg/sender/eventmesh/eventmesh.go b/pkg/sender/eventmesh/eventmesh.go index 97e20cd..3b1f829 100644 --- a/pkg/sender/eventmesh/eventmesh.go +++ b/pkg/sender/eventmesh/eventmesh.go @@ -11,24 +11,24 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/logger" "go.uber.org/zap" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/eventmesh" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/common" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents" + "github.com/kyma-project/eventing-publisher-proxy/pkg/eventmesh" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/common" ) var _ sender.GenericSender = &Sender{} -var ( - // additionalHeaders are the required headers by EMS for publish requests. - // Any alteration or removal of those headers might cause publish requests to fail. - additionalHeaders = http.Header{ +// additionalHeaders returns the required headers by EMS for publish requests. +// Any alteration or removal of those headers might cause publish requests to fail. +func additionalHeaders() http.Header { + return http.Header{ "qos": []string{string(eventmesh.QosAtLeastOnce)}, "Accept": []string{internal.ContentTypeApplicationJSON}, } -) +} const ( backend = "eventmesh" @@ -61,7 +61,7 @@ func (s *Sender) Send(ctx context.Context, event *cev2event.Event) sender.Publis message := binding.ToMessage(event) defer func() { _ = message.Finish(nil) }() - err = cloudevents.WriteRequestWithHeaders(ctx, message, request, additionalHeaders) + err = cloudevents.WriteRequestWithHeaders(ctx, message, request, additionalHeaders()) if err != nil { s.namedLogger().Error("error", err) e := common.ErrInternalBackendError diff --git a/pkg/sender/eventmesh/eventmesh_test.go b/pkg/sender/eventmesh/eventmesh_test.go index 65a283d..0b7a7be 100644 --- a/pkg/sender/eventmesh/eventmesh_test.go +++ b/pkg/sender/eventmesh/eventmesh_test.go @@ -12,11 +12,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/oauth" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/common" - testing2 "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/oauth" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/common" + testing2 "github.com/kyma-project/eventing-publisher-proxy/testing" ) const ( diff --git a/pkg/sender/jetstream/health.go b/pkg/sender/jetstream/health.go index 9f337b5..129ab00 100644 --- a/pkg/sender/jetstream/health.go +++ b/pkg/sender/jetstream/health.go @@ -3,7 +3,7 @@ package jetstream import ( "net/http" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" ) // ReadinessCheck returns an instance of http.HandlerFunc that checks the readiness of the given NATS Handler. diff --git a/pkg/sender/jetstream/jetstream.go b/pkg/sender/jetstream/jetstream.go index 86cdbc7..565e082 100644 --- a/pkg/sender/jetstream/jetstream.go +++ b/pkg/sender/jetstream/jetstream.go @@ -10,18 +10,18 @@ import ( "github.com/nats-io/nats.go" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" "github.com/kyma-project/kyma/components/eventing-controller/logger" "go.uber.org/zap" "github.com/cloudevents/sdk-go/v2/event" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/common" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender" + "github.com/kyma-project/eventing-publisher-proxy/pkg/sender/common" ) const ( @@ -35,11 +35,13 @@ const ( var _ sender.GenericSender = &Sender{} var _ health.Checker = &Sender{} -//nolint:lll // reads better this way var ( - ErrNotConnected = common.BackendPublishError{HTTPCode: http.StatusBadGateway, Info: "no connection to NATS JetStream server"} - ErrCannotSendToStream = common.BackendPublishError{HTTPCode: http.StatusGatewayTimeout, Info: "cannot send to stream"} - ErrNoSpaceLeftOnDevice = common.BackendPublishError{HTTPCode: http.StatusInsufficientStorage, Info: "insufficient resources on target stream"} + ErrNotConnected = common.BackendPublishError{HTTPCode: http.StatusBadGateway, + Info: "no connection to NATS JetStream server"} + ErrCannotSendToStream = common.BackendPublishError{HTTPCode: http.StatusGatewayTimeout, + Info: "cannot send to stream"} + ErrNoSpaceLeftOnDevice = common.BackendPublishError{HTTPCode: http.StatusInsufficientStorage, + Info: "insufficient resources on target stream"} ) // Sender is responsible for sending messages over HTTP. @@ -56,7 +58,8 @@ func (s *Sender) URL() string { } // NewSender returns a new NewSender instance with the given NATS connection. -func NewSender(ctx context.Context, connection *nats.Conn, envCfg *env.NATSConfig, opts *options.Options, logger *logger.Logger) *Sender { +func NewSender(ctx context.Context, connection *nats.Conn, envCfg *env.NATSConfig, opts *options.Options, + logger *logger.Logger) *Sender { return &Sender{ctx: ctx, connection: connection, envCfg: envCfg, opts: opts, logger: logger} } diff --git a/pkg/sender/jetstream/jetstream_test.go b/pkg/sender/jetstream/jetstream_test.go index 9d629f2..3e4c688 100644 --- a/pkg/sender/jetstream/jetstream_test.go +++ b/pkg/sender/jetstream/jetstream_test.go @@ -7,9 +7,11 @@ import ( "testing" "time" + natsgo "github.com/nats-io/nats.go" + "github.com/kyma-project/kyma/components/eventing-controller/logger" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options" + "github.com/kyma-project/eventing-publisher-proxy/pkg/options" "github.com/stretchr/testify/require" @@ -17,11 +19,10 @@ import ( cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/nats-io/nats-server/v2/server" - "github.com/nats-io/nats.go" "github.com/stretchr/testify/assert" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" - testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" + testingutils "github.com/kyma-project/eventing-publisher-proxy/testing" ) func TestJetStreamMessageSender(t *testing.T) { @@ -102,12 +103,12 @@ func TestJetStreamMessageSender(t *testing.T) { // helper functions and structs type TestEnvironment struct { - Connection *nats.Conn + Connection *natsgo.Conn Config *env.NATSConfig Logger *logger.Logger Sender *Sender Server *server.Server - JsContext *nats.JetStreamContext + JsContext *natsgo.JetStreamContext } // setupTestEnvironment sets up the resources and mocks required for testing. @@ -159,28 +160,28 @@ func createCloudEvent(t *testing.T) *event.Event { } // getStreamConfig inits a testing stream config. -func getStreamConfig(maxBytes int64) *nats.StreamConfig { - return &nats.StreamConfig{ +func getStreamConfig(maxBytes int64) *natsgo.StreamConfig { + return &natsgo.StreamConfig{ Name: testingutils.StreamName, Subjects: []string{fmt.Sprintf("%s.>", env.JetStreamSubjectPrefix)}, - Storage: nats.MemoryStorage, - Retention: nats.InterestPolicy, - Discard: nats.DiscardNew, + Storage: natsgo.MemoryStorage, + Retention: natsgo.InterestPolicy, + Discard: natsgo.DiscardNew, MaxBytes: maxBytes, } } -func getConsumerConfig() *nats.ConsumerConfig { - return &nats.ConsumerConfig{ +func getConsumerConfig() *natsgo.ConsumerConfig { + return &natsgo.ConsumerConfig{ Durable: "test", - DeliverPolicy: nats.DeliverAllPolicy, - AckPolicy: nats.AckExplicitPolicy, + DeliverPolicy: natsgo.DeliverAllPolicy, + AckPolicy: natsgo.AckExplicitPolicy, FilterSubject: fmt.Sprintf("%v.%v", env.JetStreamSubjectPrefix, testingutils.CloudEventTypeWithPrefix), } } // addStream creates a stream for the test events. -func addStream(t *testing.T, connection *nats.Conn, config *nats.StreamConfig) { +func addStream(t *testing.T, connection *natsgo.Conn, config *natsgo.StreamConfig) { js, err := connection.JetStream() assert.NoError(t, err) info, err := js.AddStream(config) @@ -188,7 +189,7 @@ func addStream(t *testing.T, connection *nats.Conn, config *nats.StreamConfig) { assert.NoError(t, err) } -func addConsumer(t *testing.T, connection *nats.Conn, sc *nats.StreamConfig, config *nats.ConsumerConfig) { +func addConsumer(t *testing.T, connection *natsgo.Conn, sc *natsgo.StreamConfig, config *natsgo.ConsumerConfig) { js, err := connection.JetStream() assert.NoError(t, err) info, err := js.AddConsumer(sc.Name, config) diff --git a/pkg/signals/signals.go b/pkg/signals/signals.go index 6877765..dcf01e0 100644 --- a/pkg/signals/signals.go +++ b/pkg/signals/signals.go @@ -9,6 +9,7 @@ import ( "time" ) +//nolint:gochecknoglobals // defining channels var ( // onlyOneSignalHandler to make sure that only one signal handler is registered. onlyOneSignalHandler = make(chan struct{}) diff --git a/pkg/subscribed/helpers.go b/pkg/subscribed/helpers.go index d19048d..e9e0711 100644 --- a/pkg/subscribed/helpers.go +++ b/pkg/subscribed/helpers.go @@ -16,21 +16,24 @@ import ( eventingv1alpha1 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha1" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers" + "github.com/kyma-project/eventing-publisher-proxy/pkg/informers" ) -var ( - GVR = schema.GroupVersionResource{ +func SubscriptionGVR() schema.GroupVersionResource { + return schema.GroupVersionResource{ Version: eventingv1alpha2.GroupVersion.Version, Group: eventingv1alpha2.GroupVersion.Group, Resource: "subscriptions", } - GVRV1alpha1 = schema.GroupVersionResource{ +} + +func SubscriptionV1alpha1GVR() schema.GroupVersionResource { + return schema.GroupVersionResource{ Version: eventingv1alpha1.GroupVersion.Version, Group: eventingv1alpha1.GroupVersion.Group, Resource: "subscriptions", } -) +} // ConvertRuntimeObjToSubscriptionV1alpha1 converts a runtime.Object to a v1alpha1 version of Subscription object // by converting to unstructured in between. @@ -66,7 +69,7 @@ func GenerateSubscriptionInfFactory(k8sConfig *rest.Config) dynamicinformer.Dyna v1.NamespaceAll, nil, ) - dFilteredSharedInfFactory.ForResource(GVR) + dFilteredSharedInfFactory.ForResource(SubscriptionGVR()) return dFilteredSharedInfFactory } @@ -133,7 +136,8 @@ func buildEvent(eventTypeAndVersion string) Event { // 1. if the eventType matches the format: .. // E.g. sap.kyma.custom.varkes.order.created.v0 // 2. if the eventSource matches BEBNamespace name. -func FilterEventTypeVersionsV1alpha1(eventTypePrefix, bebNs, appName string, filters *eventingv1alpha1.BEBFilters) []Event { +func FilterEventTypeVersionsV1alpha1(eventTypePrefix, bebNs, appName string, + filters *eventingv1alpha1.BEBFilters) []Event { events := make([]Event, 0) if filters == nil { return events diff --git a/pkg/subscribed/processor.go b/pkg/subscribed/processor.go index 4e8c678..fb27166 100644 --- a/pkg/subscribed/processor.go +++ b/pkg/subscribed/processor.go @@ -9,7 +9,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" ) const processorName = "processor" diff --git a/pkg/subscribed/response.go b/pkg/subscribed/response.go index 92414fe..744f58a 100644 --- a/pkg/subscribed/response.go +++ b/pkg/subscribed/response.go @@ -7,8 +7,8 @@ import ( "github.com/kyma-project/kyma/components/eventing-controller/logger" "go.uber.org/zap" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy" + "github.com/kyma-project/eventing-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/pkg/legacy" ) const responseName = "response" diff --git a/pkg/tracing/propagation/tracecontextb3/http_format.go b/pkg/tracing/propagation/tracecontextb3/http_format.go index bffcdab..45cf064 100644 --- a/pkg/tracing/propagation/tracecontextb3/http_format.go +++ b/pkg/tracing/propagation/tracecontextb3/http_format.go @@ -5,17 +5,19 @@ import ( "go.opencensus.io/plugin/ochttp/propagation/tracecontext" ocpropagation "go.opencensus.io/trace/propagation" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/tracing/propagation" + "github.com/kyma-project/eventing-publisher-proxy/pkg/tracing/propagation" ) -// TraceContextEgress is a propagation.HTTPFormat that reads both TraceContext and B3 tracing +// TraceContextEgress returns a propagation.HTTPFormat that reads both TraceContext and B3 tracing // formats, preferring TraceContext. It always writes TraceContext format exclusively. -var TraceContextEgress = &propagation.HTTPFormatSequence{ - Ingress: []ocpropagation.HTTPFormat{ - &tracecontext.HTTPFormat{}, - &b3.HTTPFormat{}, - }, - Egress: []ocpropagation.HTTPFormat{ - &tracecontext.HTTPFormat{}, - }, +func TraceContextEgress() *propagation.HTTPFormatSequence { + return &propagation.HTTPFormatSequence{ + Ingress: []ocpropagation.HTTPFormat{ + &tracecontext.HTTPFormat{}, + &b3.HTTPFormat{}, + }, + Egress: []ocpropagation.HTTPFormat{ + &tracecontext.HTTPFormat{}, + }, + } } diff --git a/testing/env_config.go b/testing/env_config.go index be40285..3eede3b 100644 --- a/testing/env_config.go +++ b/testing/env_config.go @@ -3,7 +3,7 @@ package testing import ( "time" - "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env" + "github.com/kyma-project/eventing-publisher-proxy/pkg/env" ) const ( diff --git a/testing/fixtures.go b/testing/fixtures.go index 054d83b..ac97b3f 100644 --- a/testing/fixtures.go +++ b/testing/fixtures.go @@ -9,7 +9,7 @@ import ( cev2 "github.com/cloudevents/sdk-go/v2/event" "github.com/stretchr/testify/assert" - "github.com/kyma-project/kyma/components/event-publisher-proxy/internal" + "github.com/kyma-project/eventing-publisher-proxy/internal" ) const ( diff --git a/testing/nats.go b/testing/nats.go index 698c84b..89a1471 100644 --- a/testing/nats.go +++ b/testing/nats.go @@ -3,13 +3,14 @@ package testing import ( "time" + "github.com/nats-io/nats.go" + "github.com/kyma-project/kyma/components/eventing-controller/logger" - pkgnats "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/nats" + pkgnats "github.com/kyma-project/eventing-publisher-proxy/pkg/nats" "github.com/nats-io/nats-server/v2/server" "github.com/nats-io/nats-server/v2/test" - "github.com/nats-io/nats.go" ) const ( diff --git a/testing/utils.go b/testing/utils.go index d7a78ca..7630eaf 100644 --- a/testing/utils.go +++ b/testing/utils.go @@ -47,7 +47,7 @@ func GeneratePortOrDie() int { } case <-timeout.C: { - log.Fatal("Failed to generate port") + log.Fatal("Failed to generate port") //nolint:gocritic // used only in tests. } } }