SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat: gateway apis (#10010)
Karan Balani26d3d6b1e434
diff --git a/cmd/community/server.go b/cmd/community/server.goindex bb33627712..8fd00e445b 100644--- a/cmd/community/server.go+++ b/cmd/community/server.go@@ -12,6 +12,8 @@ import ("github.com/SigNoz/signoz/pkg/authn""github.com/SigNoz/signoz/pkg/authz""github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/gateway"+ "github.com/SigNoz/signoz/pkg/gateway/noopgateway""github.com/SigNoz/signoz/pkg/licensing""github.com/SigNoz/signoz/pkg/licensing/nooplicensing""github.com/SigNoz/signoz/pkg/modules/dashboard"@@ -90,6 +92,9 @@ func runServer(ctx context.Context, config signoz.Config, logger *slog.Logger) efunc(store sqlstore.SQLStore, settings factory.ProviderSettings, analytics analytics.Analytics, orgGetter organization.Getter, _ role.Module, queryParser queryparser.QueryParser, _ querier.Querier, _ licensing.Licensing) dashboard.Module {return impldashboard.NewModule(impldashboard.NewStore(store), settings, analytics, orgGetter, queryParser)},+ func(_ licensing.Licensing) factory.ProviderFactory[gateway.Gateway, gateway.Config] {+ return noopgateway.NewProviderFactory()+ },)if err != nil {logger.ErrorContext(ctx, "failed to create signoz", "error", err)diff --git a/cmd/enterprise/server.go b/cmd/enterprise/server.goindex 5bac2dcb90..52b50fe78e 100644--- a/cmd/enterprise/server.go+++ b/cmd/enterprise/server.go@@ -10,6 +10,7 @@ import ("github.com/SigNoz/signoz/ee/authn/callbackauthn/samlcallbackauthn""github.com/SigNoz/signoz/ee/authz/openfgaauthz""github.com/SigNoz/signoz/ee/authz/openfgaschema"+ "github.com/SigNoz/signoz/ee/gateway/httpgateway"enterpriselicensing "github.com/SigNoz/signoz/ee/licensing""github.com/SigNoz/signoz/ee/licensing/httplicensing""github.com/SigNoz/signoz/ee/modules/dashboard/impldashboard"@@ -22,6 +23,7 @@ import ("github.com/SigNoz/signoz/pkg/authn""github.com/SigNoz/signoz/pkg/authz""github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/licensing""github.com/SigNoz/signoz/pkg/modules/dashboard"pkgimpldashboard "github.com/SigNoz/signoz/pkg/modules/dashboard/impldashboard"@@ -120,6 +122,9 @@ func runServer(ctx context.Context, config signoz.Config, logger *slog.Logger) efunc(store sqlstore.SQLStore, settings factory.ProviderSettings, analytics analytics.Analytics, orgGetter organization.Getter, role role.Module, queryParser queryparser.QueryParser, querier querier.Querier, licensing licensing.Licensing) dashboard.Module {return impldashboard.NewModule(pkgimpldashboard.NewStore(store), settings, analytics, orgGetter, role, queryParser, querier, licensing)},+ func(licensing licensing.Licensing) factory.ProviderFactory[gateway.Gateway, gateway.Config] {+ return httpgateway.NewProviderFactory(licensing)+ },)if err != nil {logger.ErrorContext(ctx, "failed to create signoz", "error", err)diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex 3f8c919f40..9a1bf240d0 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -2067,6 +2067,361 @@ paths:summary: Get featurestags:- features+ /api/v2/gateway/ingestion_keys:+ get:+ deprecated: false+ description: This endpoint returns the ingestion keys for a workspace+ operationId: GetIngestionKeys+ responses:+ "200":+ content:+ application/json:+ schema:+ properties:+ data:+ $ref: '#/components/schemas/GatewaytypesGettableIngestionKeys'+ status:+ type: string+ type: object+ description: OK+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Get ingestion keys for workspace+ tags:+ - gateway+ post:+ deprecated: false+ description: This endpoint creates an ingestion key for the workspace+ operationId: CreateIngestionKey+ requestBody:+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/GatewaytypesPostableIngestionKey'+ responses:+ "200":+ content:+ application/json:+ schema:+ properties:+ data:+ $ref: '#/components/schemas/GatewaytypesGettableCreatedIngestionKey'+ status:+ type: string+ type: object+ description: OK+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Create ingestion key for workspace+ tags:+ - gateway+ /api/v2/gateway/ingestion_keys/{keyId}:+ delete:+ deprecated: false+ description: This endpoint deletes an ingestion key for the workspace+ operationId: DeleteIngestionKey+ parameters:+ - in: path+ name: keyId+ required: true+ schema:+ type: string+ responses:+ "204":+ description: No Content+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Delete ingestion key for workspace+ tags:+ - gateway+ patch:+ deprecated: false+ description: This endpoint updates an ingestion key for the workspace+ operationId: UpdateIngestionKey+ parameters:+ - in: path+ name: keyId+ required: true+ schema:+ type: string+ requestBody:+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/GatewaytypesPostableIngestionKey'+ responses:+ "204":+ description: No Content+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Update ingestion key for workspace+ tags:+ - gateway+ /api/v2/gateway/ingestion_keys/{keyId}/limits:+ post:+ deprecated: false+ description: This endpoint creates an ingestion key limit+ operationId: CreateIngestionKeyLimit+ parameters:+ - in: path+ name: keyId+ required: true+ schema:+ type: string+ requestBody:+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/GatewaytypesPostableIngestionKeyLimit'+ responses:+ "201":+ content:+ application/json:+ schema:+ properties:+ data:+ $ref: '#/components/schemas/GatewaytypesGettableCreatedIngestionKeyLimit'+ status:+ type: string+ type: object+ description: Created+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Create limit for the ingestion key+ tags:+ - gateway+ /api/v2/gateway/ingestion_keys/limits/{limitId}:+ delete:+ deprecated: false+ description: This endpoint deletes an ingestion key limit+ operationId: DeleteIngestionKeyLimit+ parameters:+ - in: path+ name: limitId+ required: true+ schema:+ type: string+ responses:+ "204":+ description: No Content+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Delete limit for the ingestion key+ tags:+ - gateway+ patch:+ deprecated: false+ description: This endpoint updates an ingestion key limit+ operationId: UpdateIngestionKeyLimit+ parameters:+ - in: path+ name: limitId+ required: true+ schema:+ type: string+ requestBody:+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/GatewaytypesUpdatableIngestionKeyLimit'+ responses:+ "204":+ description: No Content+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Update limit for the ingestion key+ tags:+ - gateway+ /api/v2/gateway/ingestion_keys/search:+ get:+ deprecated: false+ description: This endpoint returns the ingestion keys for a workspace+ operationId: SearchIngestionKeys+ responses:+ "200":+ content:+ application/json:+ schema:+ properties:+ data:+ $ref: '#/components/schemas/GatewaytypesGettableIngestionKeys'+ status:+ type: string+ type: object+ description: OK+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - ADMIN+ - tokenizer:+ - ADMIN+ summary: Search ingestion keys for workspace+ tags:+ - gateway/api/v2/metric/alerts:get:deprecated: false@@ -3051,6 +3406,160 @@ components:nullable: truetype: objecttype: object+ GatewaytypesGettableCreatedIngestionKey:+ properties:+ id:+ type: string+ value:+ type: string+ type: object+ GatewaytypesGettableCreatedIngestionKeyLimit:+ properties:+ id:+ type: string+ type: object+ GatewaytypesGettableIngestionKeys:+ properties:+ _pagination:+ $ref: '#/components/schemas/GatewaytypesPagination'+ keys:+ items:+ $ref: '#/components/schemas/GatewaytypesIngestionKey'+ nullable: true+ type: array+ type: object+ GatewaytypesIngestionKey:+ properties:+ created_at:+ format: date-time+ type: string+ expires_at:+ format: date-time+ type: string+ id:+ type: string+ limits:+ items:+ $ref: '#/components/schemas/GatewaytypesLimit'+ nullable: true+ type: array+ name:+ type: string+ tags:+ items:+ type: string+ nullable: true+ type: array+ updated_at:+ format: date-time+ type: string+ value:+ type: string+ workspace_id:+ type: string+ type: object+ GatewaytypesLimit:+ properties:+ config:+ $ref: '#/components/schemas/GatewaytypesLimitConfig'+ created_at:+ format: date-time+ type: string+ id:+ type: string+ key_id:+ type: string+ metric:+ $ref: '#/components/schemas/GatewaytypesLimitMetric'+ signal:+ type: string+ tags:+ items:+ type: string+ nullable: true+ type: array+ updated_at:+ format: date-time+ type: string+ type: object+ GatewaytypesLimitConfig:+ properties:+ day:+ $ref: '#/components/schemas/GatewaytypesLimitValue'+ second:+ $ref: '#/components/schemas/GatewaytypesLimitValue'+ type: object+ GatewaytypesLimitMetric:+ properties:+ day:+ $ref: '#/components/schemas/GatewaytypesLimitMetricValue'+ second:+ $ref: '#/components/schemas/GatewaytypesLimitMetricValue'+ type: object+ GatewaytypesLimitMetricValue:+ properties:+ count:+ format: int64+ type: integer+ size:+ format: int64+ type: integer+ type: object+ GatewaytypesLimitValue:+ properties:+ count:+ format: int64+ type: integer+ size:+ format: int64+ type: integer+ type: object+ GatewaytypesPagination:+ properties:+ page:+ type: integer+ pages:+ type: integer+ per_page:+ type: integer+ total:+ type: integer+ type: object+ GatewaytypesPostableIngestionKey:+ properties:+ expires_at:+ format: date-time+ type: string+ name:+ type: string+ tags:+ items:+ type: string+ nullable: true+ type: array+ type: object+ GatewaytypesPostableIngestionKeyLimit:+ properties:+ config:+ $ref: '#/components/schemas/GatewaytypesLimitConfig'+ signal:+ type: string+ tags:+ items:+ type: string+ nullable: true+ type: array+ type: object+ GatewaytypesUpdatableIngestionKeyLimit:+ properties:+ config:+ $ref: '#/components/schemas/GatewaytypesLimitConfig'+ tags:+ items:+ type: string+ nullable: true+ type: array+ type: objectMetricsexplorertypesMetricAlert:properties:alertId:diff --git a/ee/gateway/httpgateway/provider.go b/ee/gateway/httpgateway/provider.gonew file mode 100644index 0000000000..944db4046e--- /dev/null+++ b/ee/gateway/httpgateway/provider.go@@ -0,0 +1,282 @@+package httpgateway++import (+ "bytes"+ "context"+ "encoding/json"+ "io"+ "net/http"+ "net/url"+ "strconv"+ "time"++ "github.com/SigNoz/signoz/pkg/errors"+ "github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/gateway"+ "github.com/SigNoz/signoz/pkg/http/client"+ "github.com/SigNoz/signoz/pkg/licensing"+ "github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/SigNoz/signoz/pkg/valuer"+ "github.com/tidwall/gjson"+)++type Provider struct {+ settings factory.ScopedProviderSettings+ config gateway.Config+ httpClient *client.Client+ licensing licensing.Licensing+}++func NewProviderFactory(licensing licensing.Licensing) factory.ProviderFactory[gateway.Gateway, gateway.Config] {+ return factory.NewProviderFactory(factory.MustNewName("http"), func(ctx context.Context, ps factory.ProviderSettings, c gateway.Config) (gateway.Gateway, error) {+ return New(ctx, ps, c, licensing)+ })+}++func New(ctx context.Context, providerSettings factory.ProviderSettings, config gateway.Config, licensing licensing.Licensing) (gateway.Gateway, error) {+ settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/ee/gateway/httpgateway")++ httpClient, err := client.New(+ settings.Logger(),+ providerSettings.TracerProvider,+ providerSettings.MeterProvider,+ client.WithRequestResponseLog(true),+ client.WithRetryCount(3),+ )+ if err != nil {+ return nil, err+ }++ return &Provider{+ settings: settings,+ config: config,+ httpClient: httpClient,+ licensing: licensing,+ }, nil+}++func (provider *Provider) GetIngestionKeys(ctx context.Context, orgID valuer.UUID, page, perPage int) (*gatewaytypes.GettableIngestionKeys, error) {+ qParams := url.Values{}+ qParams.Add("page", strconv.Itoa(page))+ qParams.Add("per_page", strconv.Itoa(perPage))++ responseBody, err := provider.do(ctx, orgID, http.MethodGet, "/v1/workspaces/me/keys", qParams, nil)+ if err != nil {+ return nil, err+ }++ var ingestionKeys []gatewaytypes.IngestionKey+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "data").String()), &ingestionKeys); err != nil {+ return nil, err+ }++ var pagination gatewaytypes.Pagination+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "_pagination").String()), &pagination); err != nil {+ return nil, err+ }++ return &gatewaytypes.GettableIngestionKeys{+ Keys: ingestionKeys,+ Pagination: pagination,+ }, nil+}++func (provider *Provider) SearchIngestionKeysByName(ctx context.Context, orgID valuer.UUID, name string, page, perPage int) (*gatewaytypes.GettableIngestionKeys, error) {+ qParams := url.Values{}+ qParams.Add("name", name)+ qParams.Add("page", strconv.Itoa(page))+ qParams.Add("per_page", strconv.Itoa(perPage))++ responseBody, err := provider.do(ctx, orgID, http.MethodGet, "/v1/workspaces/me/keys/search", qParams, nil)+ if err != nil {+ return nil, err+ }++ var ingestionKeys []gatewaytypes.IngestionKey+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "data").String()), &ingestionKeys); err != nil {+ return nil, err+ }++ var pagination gatewaytypes.Pagination+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "_pagination").String()), &pagination); err != nil {+ return nil, err+ }++ return &gatewaytypes.GettableIngestionKeys{+ Keys: ingestionKeys,+ Pagination: pagination,+ }, nil+}++func (provider *Provider) CreateIngestionKey(ctx context.Context, orgID valuer.UUID, name string, tags []string, expiresAt time.Time) (*gatewaytypes.GettableCreatedIngestionKey, error) {+ requestBody := gatewaytypes.PostableIngestionKey{+ Name: name,+ Tags: tags,+ ExpiresAt: expiresAt,+ }+ requestBodyBytes, err := json.Marshal(requestBody)+ if err != nil {+ return nil, err+ }++ responseBody, err := provider.do(ctx, orgID, http.MethodPost, "/v1/workspaces/me/keys", nil, requestBodyBytes)+ if err != nil {+ return nil, err+ }++ var createdKeyResponse gatewaytypes.GettableCreatedIngestionKey+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "data").String()), &createdKeyResponse); err != nil {+ return nil, err+ }++ return &createdKeyResponse, nil+}++func (provider *Provider) UpdateIngestionKey(ctx context.Context, orgID valuer.UUID, keyID string, name string, tags []string, expiresAt time.Time) error {+ requestBody := gatewaytypes.PostableIngestionKey{+ Name: name,+ Tags: tags,+ ExpiresAt: expiresAt,+ }+ requestBodyBytes, err := json.Marshal(requestBody)+ if err != nil {+ return err+ }++ _, err = provider.do(ctx, orgID, http.MethodPatch, "/v1/workspaces/me/keys/"+keyID, nil, requestBodyBytes)+ if err != nil {+ return err+ }++ return nil+}++func (provider *Provider) DeleteIngestionKey(ctx context.Context, orgID valuer.UUID, keyID string) error {+ _, err := provider.do(ctx, orgID, http.MethodDelete, "/v1/workspaces/me/keys/"+keyID, nil, nil)+ if err != nil {+ return err+ }++ return nil+}++func (provider *Provider) CreateIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, keyID string, signal string, limitConfig gatewaytypes.LimitConfig, tags []string) (*gatewaytypes.GettableCreatedIngestionKeyLimit, error) {+ requestBody := gatewaytypes.PostableIngestionKeyLimit{+ Signal: signal,+ Config: limitConfig,+ Tags: tags,+ }+ requestBodyBytes, err := json.Marshal(requestBody)+ if err != nil {+ return nil, err+ }++ responseBody, err := provider.do(ctx, orgID, http.MethodPost, "/v1/workspaces/me/keys/"+keyID+"/limits", nil, requestBodyBytes)+ if err != nil {+ return nil, err+ }++ var createdIngestionKeyLimitResponse gatewaytypes.GettableCreatedIngestionKeyLimit+ if err := json.Unmarshal([]byte(gjson.GetBytes(responseBody, "data").String()), &createdIngestionKeyLimitResponse); err != nil {+ return nil, err+ }++ return &createdIngestionKeyLimitResponse, nil+}++func (provider *Provider) UpdateIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, limitID string, limitConfig gatewaytypes.LimitConfig, tags []string) error {+ requestBody := gatewaytypes.UpdatableIngestionKeyLimit{+ Config: limitConfig,+ Tags: tags,+ }+ requestBodyBytes, err := json.Marshal(requestBody)+ if err != nil {+ return err+ }++ _, err = provider.do(ctx, orgID, http.MethodPatch, "/v1/workspaces/me/limits/"+limitID, nil, requestBodyBytes)+ if err != nil {+ return err+ }++ return nil+}++func (provider *Provider) DeleteIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, limitID string) error {+ _, err := provider.do(ctx, orgID, http.MethodDelete, "/v1/workspaces/me/limits/"+limitID, nil, nil)+ if err != nil {+ return err+ }++ return nil+}++func (provider *Provider) do(ctx context.Context, orgID valuer.UUID, method string, path string, queryParams url.Values, body []byte) ([]byte, error) {+ license, err := provider.licensing.GetActive(ctx, orgID)+ if err != nil {+ return nil, errors.New(errors.TypeLicenseUnavailable, errors.CodeLicenseUnavailable, "no valid license found").WithAdditional("this feature requires a valid license").WithAdditional(err.Error())+ }++ // build url+ requestURL := provider.config.URL.JoinPath(path)++ // add query params to the url+ if queryParams != nil {+ requestURL.RawQuery = queryParams.Encode()+ }++ // build request+ request, err := http.NewRequestWithContext(ctx, method, requestURL.String(), bytes.NewBuffer(body))+ if err != nil {+ return nil, err+ }++ // add headers needed to call gateway+ request.Header.Set("Content-Type", "application/json")+ request.Header.Set("X-Signoz-Cloud-Api-Key", license.Key)+ request.Header.Set("X-Consumer-Username", "lid:00000000-0000-0000-0000-000000000000")+ request.Header.Set("X-Consumer-Groups", "ns:default")++ // execute request+ response, err := provider.httpClient.Do(request)+ if err != nil {+ return nil, err+ }++ // read response+ defer response.Body.Close()+ responseBody, err := io.ReadAll(response.Body)+ if err != nil {+ return nil, err+ }++ // only 2XX+ if response.StatusCode/100 == 2 {+ return responseBody, nil+ }++ errorMessage := gjson.GetBytes(responseBody, "error").String()+ if errorMessage == "" {+ errorMessage = "an unknown error occurred"+ }++ // return error for non 2XX+ return nil, provider.errFromStatusCode(response.StatusCode, errorMessage)+}++func (provider *Provider) errFromStatusCode(code int, errorMessage string) error {+ switch code {+ case http.StatusBadRequest:+ return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, errorMessage)+ case http.StatusUnauthorized:+ return errors.New(errors.TypeUnauthenticated, errors.CodeUnauthenticated, errorMessage)+ case http.StatusForbidden:+ return errors.New(errors.TypeForbidden, errors.CodeForbidden, errorMessage)+ case http.StatusNotFound:+ return errors.New(errors.TypeNotFound, errors.CodeNotFound, errorMessage)+ case http.StatusConflict:+ return errors.New(errors.TypeAlreadyExists, errors.CodeAlreadyExists, errorMessage)+ }++ return errors.New(errors.TypeInternal, errors.CodeInternal, errorMessage)+}diff --git a/pkg/apiserver/signozapiserver/gateway.go b/pkg/apiserver/signozapiserver/gateway.gonew file mode 100644index 0000000000..197bbe635d--- /dev/null+++ b/pkg/apiserver/signozapiserver/gateway.go@@ -0,0 +1,150 @@+package signozapiserver++import (+ "net/http"++ "github.com/SigNoz/signoz/pkg/http/handler"+ "github.com/SigNoz/signoz/pkg/types"+ "github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/gorilla/mux"+)++func (provider *provider) addGatewayRoutes(router *mux.Router) error {+ if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.GetIngestionKeys), handler.OpenAPIDef{+ ID: "GetIngestionKeys",+ Tags: []string{"gateway"},+ Summary: "Get ingestion keys for workspace",+ Description: "This endpoint returns the ingestion keys for a workspace",+ Request: nil,+ RequestContentType: "",+ Response: new(gatewaytypes.GettableIngestionKeys),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodGet).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/search", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.SearchIngestionKeys), handler.OpenAPIDef{+ ID: "SearchIngestionKeys",+ Tags: []string{"gateway"},+ Summary: "Search ingestion keys for workspace",+ Description: "This endpoint returns the ingestion keys for a workspace",+ Request: nil,+ RequestContentType: "",+ Response: new(gatewaytypes.GettableIngestionKeys),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodGet).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.CreateIngestionKey), handler.OpenAPIDef{+ ID: "CreateIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Create ingestion key for workspace",+ Description: "This endpoint creates an ingestion key for the workspace",+ Request: new(gatewaytypes.PostableIngestionKey),+ RequestContentType: "application/json",+ Response: new(gatewaytypes.GettableCreatedIngestionKey),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodPost).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.UpdateIngestionKey), handler.OpenAPIDef{+ ID: "UpdateIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Update ingestion key for workspace",+ Description: "This endpoint updates an ingestion key for the workspace",+ Request: new(gatewaytypes.PostableIngestionKey),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodPatch).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.DeleteIngestionKey), handler.OpenAPIDef{+ ID: "DeleteIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Delete ingestion key for workspace",+ Description: "This endpoint deletes an ingestion key for the workspace",+ Request: nil,+ RequestContentType: "",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodDelete).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}/limits", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.CreateIngestionKeyLimit), handler.OpenAPIDef{+ ID: "CreateIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Create limit for the ingestion key",+ Description: "This endpoint creates an ingestion key limit",+ Request: new(gatewaytypes.PostableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: new(gatewaytypes.GettableCreatedIngestionKeyLimit),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusCreated,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodPost).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.UpdateIngestionKeyLimit), handler.OpenAPIDef{+ ID: "UpdateIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Update limit for the ingestion key",+ Description: "This endpoint updates an ingestion key limit",+ Request: new(gatewaytypes.UpdatableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodPatch).GetError(); err != nil {+ return err+ }++ if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(provider.authZ.AdminAccess(provider.gatewayHandler.DeleteIngestionKeyLimit), handler.OpenAPIDef{+ ID: "DeleteIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Delete limit for the ingestion key",+ Description: "This endpoint deletes an ingestion key limit",+ Request: nil,+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),+ })).Methods(http.MethodDelete).GetError(); err != nil {+ return err+ }++ return nil+}diff --git a/pkg/apiserver/signozapiserver/provider.go b/pkg/apiserver/signozapiserver/provider.goindex ca7eb0b197..9cb43cb386 100644--- a/pkg/apiserver/signozapiserver/provider.go+++ b/pkg/apiserver/signozapiserver/provider.go@@ -7,6 +7,7 @@ import ("github.com/SigNoz/signoz/pkg/authz""github.com/SigNoz/signoz/pkg/factory""github.com/SigNoz/signoz/pkg/flagger"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/http/handler""github.com/SigNoz/signoz/pkg/http/middleware"@@ -39,6 +40,7 @@ type provider struct {dashboardModule dashboard.ModuledashboardHandler dashboard.HandlermetricsExplorerHandler metricsexplorer.Handler+ gatewayHandler gateway.Handler}func NewFactory(@@ -55,9 +57,10 @@ func NewFactory(dashboardModule dashboard.Module,dashboardHandler dashboard.Handler,metricsExplorerHandler metricsexplorer.Handler,+ gatewayHandler gateway.Handler,) factory.ProviderFactory[apiserver.APIServer, apiserver.Config] {return factory.NewProviderFactory(factory.MustNewName("signoz"), func(ctx context.Context, providerSettings factory.ProviderSettings, config apiserver.Config) (apiserver.APIServer, error) {- return newProvider(ctx, providerSettings, config, orgGetter, authz, orgHandler, userHandler, sessionHandler, authDomainHandler, preferenceHandler, globalHandler, promoteHandler, flaggerHandler, dashboardModule, dashboardHandler, metricsExplorerHandler)+ return newProvider(ctx, providerSettings, config, orgGetter, authz, orgHandler, userHandler, sessionHandler, authDomainHandler, preferenceHandler, globalHandler, promoteHandler, flaggerHandler, dashboardModule, dashboardHandler, metricsExplorerHandler, gatewayHandler)})}@@ -78,6 +81,7 @@ func newProvider(dashboardModule dashboard.Module,dashboardHandler dashboard.Handler,metricsExplorerHandler metricsexplorer.Handler,+ gatewayHandler gateway.Handler,) (apiserver.APIServer, error) {settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/apiserver/signozapiserver")router := mux.NewRouter().UseEncodedPath()@@ -97,6 +101,7 @@ func newProvider(dashboardModule: dashboardModule,dashboardHandler: dashboardHandler,metricsExplorerHandler: metricsExplorerHandler,+ gatewayHandler: gatewayHandler,}provider.authZ = middleware.NewAuthZ(settings.Logger(), orgGetter, authz)@@ -153,6 +158,10 @@ func (provider *provider) AddToRouter(router *mux.Router) error {return err}+ if err := provider.addGatewayRoutes(router); err != nil {+ return err+ }+return nil}diff --git a/pkg/gateway/config.go b/pkg/gateway/config.goindex e9a79b40c3..a3e5d1e9b5 100644--- a/pkg/gateway/config.go+++ b/pkg/gateway/config.go@@ -4,14 +4,9 @@ import ("net/url""github.com/SigNoz/signoz/pkg/errors"-"github.com/SigNoz/signoz/pkg/factory")-var (- ErrCodeInvalidGatewayConfig = errors.MustNewCode("invalid_gateway_config")-)-type Config struct {URL *url.URL `mapstructure:"url"`}diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.gonew file mode 100644index 0000000000..3ea7fba855--- /dev/null+++ b/pkg/gateway/gateway.go@@ -0,0 +1,60 @@+package gateway++import (+ "context"+ "net/http"+ "time"++ "github.com/SigNoz/signoz/pkg/errors"+ "github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/SigNoz/signoz/pkg/valuer"+)++var (+ ErrCodeGatewayUnsupported = errors.MustNewCode("gateway_unsupported")+ ErrCodeInvalidGatewayConfig = errors.MustNewCode("invalid_gateway_config")+)++type Gateway interface {+ // Get Ingestions Keys (this is supposed to be for the current user but for now in gateway code this is ignoring the consumer user)+ GetIngestionKeys(ctx context.Context, orgID valuer.UUID, page, perPage int) (*gatewaytypes.GettableIngestionKeys, error)++ // Search Ingestion Keys by Name (this is supposed to be for the current user but for now in gateway code this is ignoring the consumer user)+ SearchIngestionKeysByName(ctx context.Context, orgID valuer.UUID, name string, page, perPage int) (*gatewaytypes.GettableIngestionKeys, error)++ // Create Ingestion Key+ CreateIngestionKey(ctx context.Context, orgID valuer.UUID, name string, tags []string, expiresAt time.Time) (*gatewaytypes.GettableCreatedIngestionKey, error)++ // Update Ingestion Key+ UpdateIngestionKey(ctx context.Context, orgID valuer.UUID, keyID string, name string, tags []string, expiresAt time.Time) error++ // Delete Ingestion Key+ DeleteIngestionKey(ctx context.Context, orgID valuer.UUID, keyID string) error++ // Create Ingestion Key Limit+ CreateIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, keyID string, signal string, limitConfig gatewaytypes.LimitConfig, tags []string) (*gatewaytypes.GettableCreatedIngestionKeyLimit, error)++ // Update Ingestion Key Limit+ UpdateIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, limitID string, limitConfig gatewaytypes.LimitConfig, tags []string) error++ // Delete Ingestion Key Limit+ DeleteIngestionKeyLimit(ctx context.Context, orgID valuer.UUID, limitID string) error+}++type Handler interface {+ GetIngestionKeys(http.ResponseWriter, *http.Request)++ SearchIngestionKeys(http.ResponseWriter, *http.Request)++ CreateIngestionKey(http.ResponseWriter, *http.Request)++ UpdateIngestionKey(http.ResponseWriter, *http.Request)++ DeleteIngestionKey(http.ResponseWriter, *http.Request)++ CreateIngestionKeyLimit(http.ResponseWriter, *http.Request)++ UpdateIngestionKeyLimit(http.ResponseWriter, *http.Request)++ DeleteIngestionKeyLimit(http.ResponseWriter, *http.Request)+}diff --git a/pkg/gateway/handler.go b/pkg/gateway/handler.gonew file mode 100644index 0000000000..0a89d081e0--- /dev/null+++ b/pkg/gateway/handler.go@@ -0,0 +1,287 @@+package gateway++import (+ "encoding/json"+ "net/http"+ "strconv"++ "github.com/SigNoz/signoz/pkg/errors"+ "github.com/SigNoz/signoz/pkg/http/render"+ "github.com/SigNoz/signoz/pkg/types/authtypes"+ "github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/SigNoz/signoz/pkg/valuer"+ "github.com/gorilla/mux"+)++const (+ DefaultPage = 1+ DefaultPageSize = 10+)++type handler struct {+ gateway Gateway+}++func NewHandler(gateway Gateway) Handler {+ return &handler{+ gateway: gateway,+ }+}++func (handler *handler) GetIngestionKeys(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ pageString := r.URL.Query().Get("page")+ perPageString := r.URL.Query().Get("per_page")++ page, err := parseIntWithDefaultValue(pageString, DefaultPage)+ if err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "page must be a valid integer"))+ return+ }++ perPage, err := parseIntWithDefaultValue(perPageString, DefaultPageSize)+ if err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "per_page must be a valid integer"))+ return+ }++ response, err := handler.gateway.GetIngestionKeys(ctx, orgID, page, perPage)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusOK, response)+}++func (handler *handler) SearchIngestionKeys(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ pageString := r.URL.Query().Get("page")+ perPageString := r.URL.Query().Get("per_page")+ name := r.URL.Query().Get("name")++ page, err := parseIntWithDefaultValue(pageString, DefaultPage)+ if err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "page must be a valid integer"))+ return+ }++ perPage, err := parseIntWithDefaultValue(perPageString, DefaultPageSize)+ if err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "per_page must be a valid integer"))+ return+ }++ response, err := handler.gateway.SearchIngestionKeysByName(ctx, orgID, name, page, perPage)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusOK, response)+}++func (handler *handler) CreateIngestionKey(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ var req gatewaytypes.PostableIngestionKey+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid request body"))+ return+ }++ response, err := handler.gateway.CreateIngestionKey(ctx, orgID, req.Name, req.Tags, req.ExpiresAt)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusOK, response)+}++func (handler *handler) UpdateIngestionKey(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ keyID := mux.Vars(r)["keyId"]+ if keyID == "" {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "keyId is required"))+ return+ }++ var req gatewaytypes.PostableIngestionKey+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid request body"))+ return+ }++ err = handler.gateway.UpdateIngestionKey(ctx, orgID, keyID, req.Name, req.Tags, req.ExpiresAt)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusNoContent, nil)+}++func (handler *handler) DeleteIngestionKey(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ keyID := mux.Vars(r)["keyId"]+ if keyID == "" {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "keyId is required"))+ return+ }++ err = handler.gateway.DeleteIngestionKey(ctx, orgID, keyID)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusNoContent, nil)+}++func (handler *handler) CreateIngestionKeyLimit(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ keyID := mux.Vars(r)["keyId"]+ if keyID == "" {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "keyId is required"))+ return+ }++ var req gatewaytypes.PostableIngestionKeyLimit+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid request body"))+ return+ }++ response, err := handler.gateway.CreateIngestionKeyLimit(ctx, orgID, keyID, req.Signal, req.Config, req.Tags)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusCreated, response)+}++func (handler *handler) UpdateIngestionKeyLimit(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ limitID := mux.Vars(r)["limitId"]+ if limitID == "" {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "limitId is required"))+ return+ }++ var req gatewaytypes.UpdatableIngestionKeyLimit+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid request body"))+ return+ }++ err = handler.gateway.UpdateIngestionKeyLimit(ctx, orgID, limitID, req.Config, req.Tags)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusNoContent, nil)+}++func (handler *handler) DeleteIngestionKeyLimit(rw http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ claims, err := authtypes.ClaimsFromContext(ctx)+ if err != nil {+ render.Error(rw, err)+ return+ }++ orgID := valuer.MustNewUUID(claims.OrgID)++ limitID := mux.Vars(r)["limitId"]+ if limitID == "" {+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "limitId is required"))+ return+ }++ err = handler.gateway.DeleteIngestionKeyLimit(ctx, orgID, limitID)+ if err != nil {+ render.Error(rw, err)+ return+ }++ render.Success(rw, http.StatusNoContent, nil)+}++func parseIntWithDefaultValue(value string, defaultValue int) (int, error) {+ if value == "" {+ return defaultValue, nil+ }++ result, err := strconv.Atoi(value)+ if err != nil {+ return 0, err+ }++ return result, nil+}diff --git a/pkg/gateway/noopgateway/provider.go b/pkg/gateway/noopgateway/provider.gonew file mode 100644index 0000000000..4609fed65d--- /dev/null+++ b/pkg/gateway/noopgateway/provider.go@@ -0,0 +1,56 @@+package noopgateway++import (+ "context"+ "time"++ "github.com/SigNoz/signoz/pkg/errors"+ "github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/gateway"+ "github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/SigNoz/signoz/pkg/valuer"+)++type provider struct{}++func NewProviderFactory() factory.ProviderFactory[gateway.Gateway, gateway.Config] {+ return factory.NewProviderFactory(factory.MustNewName("noop"), func(ctx context.Context, ps factory.ProviderSettings, c gateway.Config) (gateway.Gateway, error) {+ return New(ctx, ps, c)+ })+}++func New(_ context.Context, _ factory.ProviderSettings, _ gateway.Config) (gateway.Gateway, error) {+ return &provider{}, nil+}++func (p *provider) GetIngestionKeys(_ context.Context, _ valuer.UUID, _, _ int) (*gatewaytypes.GettableIngestionKeys, error) {+ return nil, errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) SearchIngestionKeysByName(_ context.Context, _ valuer.UUID, _ string, _, _ int) (*gatewaytypes.GettableIngestionKeys, error) {+ return nil, errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) CreateIngestionKey(_ context.Context, _ valuer.UUID, _ string, _ []string, _ time.Time) (*gatewaytypes.GettableCreatedIngestionKey, error) {+ return nil, errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) UpdateIngestionKey(_ context.Context, _ valuer.UUID, _ string, _ string, _ []string, _ time.Time) error {+ return errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) DeleteIngestionKey(_ context.Context, _ valuer.UUID, _ string) error {+ return errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) CreateIngestionKeyLimit(_ context.Context, _ valuer.UUID, _ string, _ string, _ gatewaytypes.LimitConfig, _ []string) (*gatewaytypes.GettableCreatedIngestionKeyLimit, error) {+ return nil, errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) UpdateIngestionKeyLimit(_ context.Context, _ valuer.UUID, _ string, _ gatewaytypes.LimitConfig, _ []string) error {+ return errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}++func (p *provider) DeleteIngestionKeyLimit(_ context.Context, _ valuer.UUID, _ string) error {+ return errors.New(errors.TypeUnsupported, gateway.ErrCodeGatewayUnsupported, "unsupported call")+}diff --git a/pkg/signoz/handler.go b/pkg/signoz/handler.goindex d439e6b18c..50bd761475 100644--- a/pkg/signoz/handler.go+++ b/pkg/signoz/handler.go@@ -3,6 +3,7 @@ package signozimport ("github.com/SigNoz/signoz/pkg/factory""github.com/SigNoz/signoz/pkg/flagger"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/global/signozglobal""github.com/SigNoz/signoz/pkg/licensing"@@ -39,9 +40,10 @@ type Handlers struct {MetricsExplorer metricsexplorer.HandlerGlobal global.HandlerFlaggerHandler flagger.Handler+ GatewayHandler gateway.Handler}-func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, querier querier.Querier, licensing licensing.Licensing, global global.Global, flaggerService flagger.Flagger) Handlers {+func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, querier querier.Querier, licensing licensing.Licensing, global global.Global, flaggerService flagger.Flagger, gatewayService gateway.Gateway) Handlers {return Handlers{SavedView: implsavedview.NewHandler(modules.SavedView),Apdex: implapdex.NewHandler(modules.Apdex),@@ -54,5 +56,6 @@ func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, queSpanPercentile: implspanpercentile.NewHandler(modules.SpanPercentile),Global: signozglobal.NewHandler(global),FlaggerHandler: flagger.NewHandler(flaggerService),+ GatewayHandler: gateway.NewHandler(gatewayService),}}diff --git a/pkg/signoz/handler_test.go b/pkg/signoz/handler_test.goindex 758b7df6a8..7ff1bade2e 100644--- a/pkg/signoz/handler_test.go+++ b/pkg/signoz/handler_test.go@@ -42,7 +42,7 @@ func TestNewHandlers(t *testing.T) {dashboardModule := impldashboard.NewModule(impldashboard.NewStore(sqlstore), providerSettings, nil, orgGetter, queryParser)modules := NewModules(sqlstore, tokenizer, emailing, providerSettings, orgGetter, alertmanager, nil, nil, nil, nil, nil, nil, nil, queryParser, Config{}, dashboardModule)- handlers := NewHandlers(modules, providerSettings, nil, nil, nil, nil)+ handlers := NewHandlers(modules, providerSettings, nil, nil, nil, nil, nil)reflectVal := reflect.ValueOf(handlers)for i := 0; i < reflectVal.NumField(); i++ {diff --git a/pkg/signoz/openapi.go b/pkg/signoz/openapi.goindex 453aea1d32..6a341f93d5 100644--- a/pkg/signoz/openapi.go+++ b/pkg/signoz/openapi.go@@ -9,6 +9,7 @@ import ("github.com/SigNoz/signoz/pkg/apiserver/signozapiserver""github.com/SigNoz/signoz/pkg/authz""github.com/SigNoz/signoz/pkg/flagger"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/http/handler""github.com/SigNoz/signoz/pkg/instrumentation"@@ -47,6 +48,7 @@ func NewOpenAPI(ctx context.Context, instrumentation instrumentation.Instrumentastruct{ dashboard.Module }{},struct{ dashboard.Handler }{},struct{ metricsexplorer.Handler }{},+ struct{ gateway.Handler }{},).New(ctx, instrumentation.ToProviderSettings(), apiserver.Config{})if err != nil {return nil, errdiff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.goindex e0fe00b39e..93e21565dd 100644--- a/pkg/signoz/provider.go+++ b/pkg/signoz/provider.go@@ -241,6 +241,7 @@ func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.Aumodules.Dashboard,handlers.Dashboard,handlers.MetricsExplorer,+ handlers.GatewayHandler,),)}diff --git a/pkg/signoz/signoz.go b/pkg/signoz/signoz.goindex 42a86bf2e1..113f29e236 100644--- a/pkg/signoz/signoz.go+++ b/pkg/signoz/signoz.go@@ -15,6 +15,7 @@ import ("github.com/SigNoz/signoz/pkg/emailing""github.com/SigNoz/signoz/pkg/factory""github.com/SigNoz/signoz/pkg/flagger"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/instrumentation""github.com/SigNoz/signoz/pkg/licensing""github.com/SigNoz/signoz/pkg/modules/dashboard"@@ -71,6 +72,7 @@ type SigNoz struct {Handlers HandlersQueryParser queryparser.QueryParserFlagger flagger.Flagger+ Gateway gateway.Gateway}func New(@@ -89,6 +91,7 @@ func New(authNsCallback func(ctx context.Context, providerSettings factory.ProviderSettings, store authtypes.AuthNStore, licensing licensing.Licensing) (map[authtypes.AuthNProvider]authn.AuthN, error),authzCallback func(context.Context, sqlstore.SQLStore) factory.ProviderFactory[authz.AuthZ, authz.Config],dashboardModuleCallback func(sqlstore.SQLStore, factory.ProviderSettings, analytics.Analytics, organization.Getter, role.Module, queryparser.QueryParser, querier.Querier, licensing.Licensing) dashboard.Module,+ gatewayProviderFactory func(licensing.Licensing) factory.ProviderFactory[gateway.Gateway, gateway.Config],) (*SigNoz, error) {// Initialize instrumentationinstrumentation, err := instrumentation.New(ctx, config.Instrumentation, version.Info, "signoz")@@ -336,6 +339,12 @@ func New(return nil, err}+ gatewayFactory := gatewayProviderFactory(licensing)+ gateway, err := gatewayFactory.New(ctx, providerSettings, config.Gateway)+ if err != nil {+ return nil, err+ }+// Initialize authnsstore := sqlauthnstore.NewStore(sqlstore)authNs, err := authNsCallback(ctx, providerSettings, store, licensing)@@ -382,7 +391,7 @@ func New(modules := NewModules(sqlstore, tokenizer, emailing, providerSettings, orgGetter, alertmanager, analytics, querier, telemetrystore, telemetryMetadataStore, authNs, authz, cache, queryParser, config, dashboardModule)// Initialize all handlers for the modules- handlers := NewHandlers(modules, providerSettings, querier, licensing, global, flagger)+ handlers := NewHandlers(modules, providerSettings, querier, licensing, global, flagger, gateway)// Initialize the API serverapiserver, err := factory.NewProviderFromNamedMap(@@ -457,5 +466,6 @@ func New(Handlers: handlers,QueryParser: queryParser,Flagger: flagger,+ Gateway: gateway,}, nil}diff --git a/pkg/types/gatewaytypes/ingestionkey.go b/pkg/types/gatewaytypes/ingestionkey.gonew file mode 100644index 0000000000..170414e81b--- /dev/null+++ b/pkg/types/gatewaytypes/ingestionkey.go@@ -0,0 +1,86 @@+package gatewaytypes++import (+ "time"+)++type IngestionKey struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Value string `json:"value"`+ ExpiresAt time.Time `json:"expires_at"`+ Tags []string `json:"tags"`+ CreatedAt time.Time `json:"created_at"`+ UpdatedAt time.Time `json:"updated_at"`+ WorkspaceID string `json:"workspace_id"`+ Limits []Limit `json:"limits"`+}++type Limit struct {+ ID string `json:"id"`+ Signal string `json:"signal"` // "logs", "traces", "metrics"+ Config LimitConfig `json:"config"`+ Tags []string `json:"tags"`+ CreatedAt time.Time `json:"created_at"`+ UpdatedAt time.Time `json:"updated_at"`+ KeyID string `json:"key_id"`+ Metric LimitMetric `json:"metric"`+}++type LimitConfig struct {+ Day *LimitValue `json:"day,omitempty"`+ Second *LimitValue `json:"second,omitempty"`+}++type LimitValue struct {+ Size int64 `json:"size,omitempty"`+ Count int64 `json:"count,omitempty"`+}++type LimitMetric struct {+ Day *LimitMetricValue `json:"day,omitempty"`+ Second *LimitMetricValue `json:"second,omitempty"`+}++type LimitMetricValue struct {+ Count int64 `json:"count"`+ Size int64 `json:"size"`+}++type Pagination struct {+ Page int `json:"page"`+ PerPage int `json:"per_page"`+ Pages int `json:"pages"`+ Total int `json:"total"`+}++type GettableIngestionKeys struct {+ Keys []IngestionKey `json:"keys"`+ Pagination Pagination `json:"_pagination"`+}++type PostableIngestionKey struct {+ Name string `json:"name"`+ Tags []string `json:"tags"`+ ExpiresAt time.Time `json:"expires_at"`+}++type GettableCreatedIngestionKey struct {+ ID string `json:"id"`+ Value string `json:"value"`+}++type PostableIngestionKeyLimit struct {+ Signal string `json:"signal"`+ Config LimitConfig `json:"config"`+ Tags []string `json:"tags"`+}++type GettableCreatedIngestionKeyLimit struct {+ ID string `json:"id"`+}++type UpdatableIngestionKeyLimit struct {+ Config LimitConfig `json:"config"`+ Tags []string `json:"tags"`+}