From 9b768003b7ed5d73211e5ae5a9fa6ae643125add Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Thu, 6 Jul 2023 19:31:08 +0200 Subject: [PATCH] feat: improve milestone format (#6150) * feat: milestone format * feat: push external domain * cleanup * Revert "remove prerelease" This reverts commit 7417fdbeb3ba4ebd65584059a80bfdf34172841b. * fix branch * remove prerelease --- cmd/start/start.go | 2 +- internal/notification/handlers/queries.go | 3 +++ .../notification/handlers/telemetry_pusher.go | 16 +++++++++++++++- .../telemetry_pusher_integration_test.go | 4 ++-- internal/notification/projections.go | 3 ++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cmd/start/start.go b/cmd/start/start.go index f970698bf2..1a90cda42a 100644 --- a/cmd/start/start.go +++ b/cmd/start/start.go @@ -214,7 +214,7 @@ func startZitadel(config *Config, masterKey string, server chan<- *Server) error } actions.SetLogstoreService(actionsLogstoreSvc) - notification.Start(ctx, config.Projections.Customizations["notifications"], config.Projections.Customizations["notificationsquotas"], config.Projections.Customizations["telemetry"], *config.Telemetry, config.ExternalPort, config.ExternalSecure, commands, queries, eventstoreClient, assets.AssetAPIFromDomain(config.ExternalSecure, config.ExternalPort), config.SystemDefaults.Notifications.FileSystemPath, keys.User, keys.SMTP, keys.SMS) + notification.Start(ctx, config.Projections.Customizations["notifications"], config.Projections.Customizations["notificationsquotas"], config.Projections.Customizations["telemetry"], *config.Telemetry, config.ExternalDomain, config.ExternalPort, config.ExternalSecure, commands, queries, eventstoreClient, assets.AssetAPIFromDomain(config.ExternalSecure, config.ExternalPort), config.SystemDefaults.Notifications.FileSystemPath, keys.User, keys.SMTP, keys.SMS) router := mux.NewRouter() tlsConfig, err := config.TLS.Config() diff --git a/internal/notification/handlers/queries.go b/internal/notification/handlers/queries.go index 63e0ab4d41..96880445bf 100644 --- a/internal/notification/handlers/queries.go +++ b/internal/notification/handlers/queries.go @@ -12,6 +12,7 @@ import ( type NotificationQueries struct { *query.Queries es *eventstore.Eventstore + externalDomain string externalPort uint16 externalSecure bool fileSystemPath string @@ -24,6 +25,7 @@ type NotificationQueries struct { func NewNotificationQueries( baseQueries *query.Queries, es *eventstore.Eventstore, + externalDomain string, externalPort uint16, externalSecure bool, fileSystemPath string, @@ -35,6 +37,7 @@ func NewNotificationQueries( return &NotificationQueries{ Queries: baseQueries, es: es, + externalDomain: externalDomain, externalPort: externalPort, externalSecure: externalSecure, fileSystemPath: fileSystemPath, diff --git a/internal/notification/handlers/telemetry_pusher.go b/internal/notification/handlers/telemetry_pusher.go index 8a0de424f1..000bbe1c7f 100644 --- a/internal/notification/handlers/telemetry_pusher.go +++ b/internal/notification/handlers/telemetry_pusher.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "time" "github.com/zitadel/logging" @@ -128,6 +129,7 @@ func (t *telemetryPusher) pushMilestone(ctx context.Context, event *pseudo.Sched if alreadyHandled { return nil } + for _, endpoint := range t.cfg.Endpoints { if err := types.SendJSON( ctx, @@ -138,7 +140,19 @@ func (t *telemetryPusher) pushMilestone(ctx context.Context, event *pseudo.Sched }, t.queries.GetFileSystemProvider, t.queries.GetLogProvider, - ms, + &struct { + InstanceID string `json:"instanceId"` + ExternalDomain string `json:"externalDomain"` + PrimaryDomain string `json:"primaryDomain"` + Type milestone.Type `json:"type"` + ReachedDate time.Time `json:"reached"` + }{ + InstanceID: ms.InstanceID, + ExternalDomain: t.queries.externalDomain, + PrimaryDomain: ms.PrimaryDomain, + Type: ms.Type, + ReachedDate: ms.ReachedDate, + }, event, t.metricSuccessfulDeliveriesJSON, t.metricFailedDeliveriesJSON, diff --git a/internal/notification/handlers/telemetry_pusher_integration_test.go b/internal/notification/handlers/telemetry_pusher_integration_test.go index 86ed3d106d..e3709db171 100644 --- a/internal/notification/handlers/telemetry_pusher_integration_test.go +++ b/internal/notification/handlers/telemetry_pusher_integration_test.go @@ -73,8 +73,8 @@ func awaitMilestone(t *testing.T, bodies chan []byte, primaryDomain, expectMiles } t.Log("received milestone", plain.String()) milestone := struct { - Type string - PrimaryDomain string + Type string `json:"type"` + PrimaryDomain string `json:"primaryDomain"` }{} if err := json.Unmarshal(body, &milestone); err != nil { t.Error(err) diff --git a/internal/notification/projections.go b/internal/notification/projections.go index a2b06aadd4..0a6f6f659c 100644 --- a/internal/notification/projections.go +++ b/internal/notification/projections.go @@ -31,6 +31,7 @@ func Start( quotaHandlerCustomConfig projection.CustomConfig, telemetryHandlerCustomConfig projection.CustomConfig, telemetryCfg handlers.TelemetryPusherConfig, + externalDomain string, externalPort uint16, externalSecure bool, commands *command.Commands, @@ -56,7 +57,7 @@ func Start( logging.WithFields("metric", metricSuccessfulDeliveriesJSON).OnError(err).Panic("unable to register counter") err = metrics.RegisterCounter(metricFailedDeliveriesJSON, "Failed JSON message deliveries") logging.WithFields("metric", metricFailedDeliveriesJSON).OnError(err).Panic("unable to register counter") - q := handlers.NewNotificationQueries(queries, es, externalPort, externalSecure, fileSystemPath, userEncryption, smtpEncryption, smsEncryption, statikFS) + q := handlers.NewNotificationQueries(queries, es, externalDomain, externalPort, externalSecure, fileSystemPath, userEncryption, smtpEncryption, smsEncryption, statikFS) handlers.NewUserNotifier( ctx, projection.ApplyCustomConfig(userHandlerCustomConfig),