From f0276743bd9da7efb6a5feaaae734d6d6e3297f9 Mon Sep 17 00:00:00 2001 From: Ildar Nurislamov Date: Mon, 8 Jan 2024 21:53:58 +0400 Subject: [PATCH] ingest: added /api/s/s2s/batch s2s only endpoint --- ingest/router.go | 6 +++++- ingest/router_batch_handler.go | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ingest/router.go b/ingest/router.go index 3f5b7ef..e81344d 100644 --- a/ingest/router.go +++ b/ingest/router.go @@ -82,6 +82,7 @@ func NewRouter(appContext *Context) *Router { "/projects/:writeKey/settings", "/b", "/batch", + "/api/s/s2s/batch", "/api/s/:tp", "/api/s/s2s/:tp", }) @@ -118,8 +119,11 @@ func NewRouter(appContext *Context) *Router { fast.Match([]string{"OPTIONS", "POST"}, "/v1/b", router.BatchHandler) fast.Match([]string{"OPTIONS", "POST"}, "/batch", router.BatchHandler) fast.Match([]string{"OPTIONS", "POST"}, "/b", router.BatchHandler) + fast.Match([]string{"OPTIONS", "POST"}, "/api/s/s2s/batch", router.BatchHandler) + fast.Match([]string{"OPTIONS", "POST"}, "/api/s/:tp", router.IngestHandler) fast.Match([]string{"OPTIONS", "POST"}, "/api/s/s2s/:tp", router.IngestHandler) + fast.Match([]string{"GET", "HEAD", "OPTIONS"}, "/p.js", router.ScriptHandler) engine.GET("/health", func(c *gin.Context) { @@ -199,7 +203,7 @@ func patchEvent(c *gin.Context, messageId string, event *AnalyticsServerEvent, t } } if !eventTypesSet.Contains(typeFixed) { - return fmt.Errorf("Unknown event type: %s", tp) + return fmt.Errorf("Unknown event type: %s", typeFixed) } if typeFixed == "track" { //check event name diff --git a/ingest/router_batch_handler.go b/ingest/router_batch_handler.go index af2fbd3..90e1baa 100644 --- a/ingest/router_batch_handler.go +++ b/ingest/router_batch_handler.go @@ -45,7 +45,13 @@ func (r *Router) BatchHandler(c *gin.Context) { rError = r.ResponseError(c, http.StatusOK, "error parsing message", false, err, true) return } - loc, err := r.getDataLocator(c, IngestTypeWriteKeyDefined, func() string { return payload.WriteKey }) + var ingestType IngestType + if c.FullPath() == "/api/s/s2s/batch" { + ingestType = IngestTypeS2S + } else { + ingestType = IngestTypeWriteKeyDefined + } + loc, err := r.getDataLocator(c, ingestType, func() string { return payload.WriteKey }) if err != nil { rError = r.ResponseError(c, http.StatusOK, "error processing message", false, err, true) return