diff --git a/internal/notification/handlers/telemetry_pusher.go b/internal/notification/handlers/telemetry_pusher.go index 514477f1b6..48f6c723d5 100644 --- a/internal/notification/handlers/telemetry_pusher.go +++ b/internal/notification/handlers/telemetry_pusher.go @@ -2,7 +2,6 @@ package handlers import ( "context" - "encoding/json" "fmt" "net/http" @@ -77,17 +76,7 @@ func (t *telemetryPusher) reducers() []handler.AggregateReducer { }} } -// TODO: Remove -func printEvent(event eventstore.Event) { - bytes, err := json.MarshalIndent(event, "", " ") - if err != nil { - panic(err) - } - fmt.Println(event.Type(), string(bytes)) -} - func (t *telemetryPusher) pushMilestones(event eventstore.Event) (*handler.Statement, error) { - printEvent(event) ctx := call.WithTimestamp(context.Background()) scheduledEvent, ok := event.(*pseudo.ScheduledEvent) if !ok { @@ -133,7 +122,7 @@ func (t *telemetryPusher) pushMilestones(event eventstore.Event) (*handler.State func (t *telemetryPusher) pushMilestone(ctx context.Context, event *pseudo.ScheduledEvent, ms *query.Milestone) error { ctx = authz.WithInstanceID(ctx, ms.InstanceID) - alreadyHandled, err := t.queries.IsAlreadyHandled(ctx, event, map[string]interface{}{"type": ms.Type}, milestone.AggregateType, milestone.PushedEventType) + alreadyHandled, err := t.queries.IsAlreadyHandled(ctx, event, map[string]interface{}{"type": ms.Type.String()}, milestone.AggregateType, milestone.PushedEventType) if err != nil { return err } diff --git a/internal/query/projection/projection.go b/internal/query/projection/projection.go index 085875b3aa..6da0638347 100644 --- a/internal/query/projection/projection.go +++ b/internal/query/projection/projection.go @@ -194,7 +194,7 @@ func applyCustomConfig(config crdb.StatementHandlerConfig, customConfig CustomCo // as setup and start currently create them individually, we make sure we get the right one // will be refactored when changing to new id based projections // -// Event handlers NotificationsProjection, NotificationsQuotaProjection and NotificationsProjection are not added here, because the do not statement based / have no proprietary projection table +// Event handlers NotificationsProjection, NotificationsQuotaProjection and NotificationsProjection are not added here, because they do not reduce to database statements func newProjectionsList() { projections = []projection{ OrgProjection, diff --git a/internal/repository/milestone/type.go b/internal/repository/milestone/type.go index 9466051cbd..f57bb032ee 100644 --- a/internal/repository/milestone/type.go +++ b/internal/repository/milestone/type.go @@ -2,6 +2,11 @@ package milestone +import ( + "fmt" + "strings" +) + type Type int const ( @@ -24,3 +29,31 @@ func AllTypes() []Type { } return types } + +func (t *Type) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.String())), nil +} + +func (t *Type) UnmarshalJSON(data []byte) error { + *t = typeFromString(strings.Trim(string(data), `"`)) + return nil +} + +func typeFromString(t string) Type { + switch t { + case InstanceCreated.String(): + return InstanceCreated + case AuthenticationSucceededOnInstance.String(): + return AuthenticationSucceededOnInstance + case ProjectCreated.String(): + return ProjectCreated + case ApplicationCreated.String(): + return ApplicationCreated + case AuthenticationSucceededOnApplication.String(): + return AuthenticationSucceededOnApplication + case InstanceDeleted.String(): + return InstanceDeleted + default: + return unknown + } +}