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
fix: omit unset limit values in gateway update api payload (#10388)
Karan Balaniddecf05d9f20
diff --git a/.github/workflows/integrationci.yaml b/.github/workflows/integrationci.yamlindex 6087fa1058..d354e530ca 100644--- a/.github/workflows/integrationci.yaml+++ b/.github/workflows/integrationci.yaml@@ -48,6 +48,7 @@ jobs:- role- ttl- alerts+ - ingestionkeyssqlstore-provider:- postgres- sqlitediff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex 0f050106db..4236246e77 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -460,10 +460,10 @@ components:GatewaytypesLimitValue:properties:count:- format: int64+ nullable: truetype: integersize:- format: int64+ nullable: truetype: integertype: objectGatewaytypesPagination:@@ -5091,7 +5091,7 @@ paths:schema:$ref: '#/components/schemas/GatewaytypesPostableIngestionKey'responses:- "200":+ "201":content:application/json:schema:@@ -5104,7 +5104,7 @@ paths:- status- datatype: object- description: OK+ description: Created"401":content:application/json:diff --git a/frontend/src/api/generated/services/gateway/index.ts b/frontend/src/api/generated/services/gateway/index.tsindex ecad87ed23..61d2a2b45f 100644--- a/frontend/src/api/generated/services/gateway/index.ts+++ b/frontend/src/api/generated/services/gateway/index.ts@@ -20,7 +20,7 @@ import { useMutation, useQuery } from 'react-query';import type { BodyType, ErrorType } from '../../../generatedAPIInstance';import { GeneratedAPIInstance } from '../../../generatedAPIInstance';import type {- CreateIngestionKey200,+ CreateIngestionKey201,CreateIngestionKeyLimit201,CreateIngestionKeyLimitPathParameters,DeleteIngestionKeyLimitPathParameters,@@ -151,7 +151,7 @@ export const createIngestionKey = (gatewaytypesPostableIngestionKeyDTO: BodyType<GatewaytypesPostableIngestionKeyDTO>,signal?: AbortSignal,) => {- return GeneratedAPIInstance<CreateIngestionKey200>({+ return GeneratedAPIInstance<CreateIngestionKey201>({url: `/api/v2/gateway/ingestion_keys`,method: 'POST',headers: { 'Content-Type': 'application/json' },diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.tsindex 9ee79ae687..9869a5f11f 100644--- a/frontend/src/api/generated/services/sigNoz.schemas.ts+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts@@ -623,14 +623,14 @@ export interface GatewaytypesLimitMetricValueDTO {export interface GatewaytypesLimitValueDTO {/*** @type integer- * @format int64+ * @nullable true*/- count?: number;+ count?: number | null;/*** @type integer- * @format int64+ * @nullable true*/- size?: number;+ size?: number | null;}export interface GatewaytypesPaginationDTO {@@ -3137,7 +3137,7 @@ export type GetIngestionKeys200 = {status: string;};-export type CreateIngestionKey200 = {+export type CreateIngestionKey201 = {data: GatewaytypesGettableCreatedIngestionKeyDTO;/*** @type stringdiff --git a/pkg/apiserver/signozapiserver/gateway.go b/pkg/apiserver/signozapiserver/gateway.goindex 2f746beb96..339d877577 100644--- a/pkg/apiserver/signozapiserver/gateway.go+++ b/pkg/apiserver/signozapiserver/gateway.go@@ -55,7 +55,7 @@ func (provider *provider) addGatewayRoutes(router *mux.Router) error {RequestContentType: "application/json",Response: new(gatewaytypes.GettableCreatedIngestionKey),ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,+ SuccessStatusCode: http.StatusCreated,ErrorStatusCodes: []int{},Deprecated: false,SecuritySchemes: newSecuritySchemes(types.RoleAdmin),diff --git a/pkg/gateway/handler.go b/pkg/gateway/handler.goindex 0a89d081e0..ab61caf4dd 100644--- a/pkg/gateway/handler.go+++ b/pkg/gateway/handler.go@@ -122,7 +122,7 @@ func (handler *handler) CreateIngestionKey(rw http.ResponseWriter, r *http.Requereturn}- render.Success(rw, http.StatusOK, response)+ render.Success(rw, http.StatusCreated, response)}func (handler *handler) UpdateIngestionKey(rw http.ResponseWriter, r *http.Request) {diff --git a/pkg/types/gatewaytypes/ingestionkey.go b/pkg/types/gatewaytypes/ingestionkey.goindex c4fe835dbc..a8e9c4b752 100644--- a/pkg/types/gatewaytypes/ingestionkey.go+++ b/pkg/types/gatewaytypes/ingestionkey.go@@ -33,8 +33,8 @@ type LimitConfig struct {}type LimitValue struct {- Size int64 `json:"size"`- Count int64 `json:"count"`+ Size *int64 `json:"size,omitempty"`+ Count *int64 `json:"count,omitempty"`}type LimitMetric struct {diff --git a/tests/integration/fixtures/gatewayutils.py b/tests/integration/fixtures/gatewayutils.pynew file mode 100644index 0000000000..6a65c788d2--- /dev/null+++ b/tests/integration/fixtures/gatewayutils.py@@ -0,0 +1,48 @@+import json+from typing import Optional++import requests+from wiremock.client import WireMockMatchers++from fixtures import types++TEST_KEY_ID = "test-key-id-001"+TEST_LIMIT_ID = "test-limit-id-001"+++def common_gateway_headers():+ """Common headers expected on requests forwarded to the gateway."""+ return {+ "X-Signoz-Cloud-Api-Key": {WireMockMatchers.EQUAL_TO: "secret-key"},+ "X-Consumer-Username": {+ WireMockMatchers.EQUAL_TO: "lid:00000000-0000-0000-0000-000000000000"+ },+ "X-Consumer-Groups": {WireMockMatchers.EQUAL_TO: "ns:default"},+ }+++def get_gateway_requests(signoz: types.SigNoz, method: str, url: str) -> list:+ """Return captured requests from the WireMock gateway journal.++ Returns an empty list when no requests match or the admin API is unreachable.+ """+ response = requests.post(+ signoz.gateway.host_configs["8080"].get("/__admin/requests/find"),+ json={"method": method, "url": url},+ timeout=5,+ )+ return response.json().get("requests", [])+++def get_latest_gateway_request_body(+ signoz: types.SigNoz, method: str, url: str+) -> Optional[dict]:+ """Return the parsed JSON body of the most recent matching gateway request.++ WireMock returns requests in reverse chronological order, so ``matched[0]``+ is always the latest. Returns ``None`` when no matching request is found.+ """+ matched = get_gateway_requests(signoz, method, url)+ if not matched:+ return None+ return json.loads(matched[0]["body"])diff --git a/tests/integration/src/ingestionkeys/01_ingestion_keys.py b/tests/integration/src/ingestionkeys/01_ingestion_keys.pynew file mode 100644index 0000000000..a5a86c7911--- /dev/null+++ b/tests/integration/src/ingestionkeys/01_ingestion_keys.py@@ -0,0 +1,424 @@+from http import HTTPStatus+from typing import Callable, List++import requests+from wiremock.client import (+ HttpMethods,+ Mapping,+ MappingRequest,+ MappingResponse,+)++from fixtures import types+from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD, add_license+from fixtures.gatewayutils import (+ TEST_KEY_ID,+ common_gateway_headers,+ get_gateway_requests,+ get_latest_gateway_request_body,+)+from fixtures.logger import setup_logger++logger = setup_logger(__name__)+++def test_apply_license(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, List[Mapping]], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Activate a license so that all subsequent gateway calls succeed."""+ add_license(signoz, make_http_mocks, get_token)+++# ---------------------------------------------------------------------------+# Ingestion key CRUD+# ---------------------------------------------------------------------------+++def test_create_ingestion_key(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """POST /api/v2/gateway/ingestion_keys creates a key via the gateway."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.POST,+ url="/v1/workspaces/me/keys",+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=201,+ json_body={+ "status": "success",+ "data": {+ "id": TEST_KEY_ID,+ "value": "ingestion-key-secret-value",+ },+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.post(+ signoz.self.host_configs["8080"].get("/api/v2/gateway/ingestion_keys"),+ json={+ "name": "my-test-key",+ "tags": ["env:test", "team:platform"],+ "expires_at": "2030-01-01T00:00:00Z",+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.CREATED+ ), f"Expected 201, got {response.status_code}: {response.text}"++ data = response.json()["data"]+ assert data["id"] == TEST_KEY_ID+ assert data["value"] == "ingestion-key-secret-value"++ # Verify the body forwarded to the gateway+ body = get_latest_gateway_request_body(signoz, "POST", "/v1/workspaces/me/keys")+ assert body is not None, "Expected a POST request to reach the gateway"+ assert body["name"] == "my-test-key"+ assert body["tags"] == ["env:test", "team:platform"]+++def test_get_ingestion_keys(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """GET /api/v2/gateway/ingestion_keys lists keys via the gateway."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ # Default page=1, per_page=10 → gateway gets ?page=1&per_page=10+ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url="/v1/workspaces/me/keys?page=1&per_page=10",+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "data": [+ {+ "id": TEST_KEY_ID,+ "name": "my-test-key",+ "value": "secret",+ "expires_at": "2030-01-01T00:00:00Z",+ "tags": ["env:test"],+ "created_at": "2024-01-01T00:00:00Z",+ "updated_at": "2024-01-01T00:00:00Z",+ "workspace_id": "ws-1",+ "limits": [],+ }+ ],+ "_pagination": {+ "page": 1,+ "per_page": 10,+ "pages": 1,+ "total": 1,+ },+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.get(+ signoz.self.host_configs["8080"].get("/api/v2/gateway/ingestion_keys"),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.OK+ ), f"Expected 200, got {response.status_code}: {response.text}"++ data = response.json()["data"]+ assert len(data["keys"]) == 1+ assert data["keys"][0]["id"] == TEST_KEY_ID+ assert data["keys"][0]["name"] == "my-test-key"+ assert data["_pagination"]["total"] == 1+++def test_get_ingestion_keys_custom_pagination(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """GET /api/v2/gateway/ingestion_keys with custom pagination params."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url="/v1/workspaces/me/keys?page=2&per_page=5",+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "data": [],+ "_pagination": {+ "page": 2,+ "per_page": 5,+ "pages": 1,+ "total": 3,+ },+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.get(+ signoz.self.host_configs["8080"].get(+ "/api/v2/gateway/ingestion_keys?page=2&per_page=5"+ ),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.OK+ ), f"Expected 200, got {response.status_code}: {response.text}"++ data = response.json()["data"]+ assert len(data["keys"]) == 0+ assert data["_pagination"]["page"] == 2+ assert data["_pagination"]["per_page"] == 5+++def test_search_ingestion_keys(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """GET /api/v2/gateway/ingestion_keys/search searches keys by name."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ # name, page, per_page are sorted alphabetically by Go url.Values.Encode()+ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url="/v1/workspaces/me/keys/search?name=my-test&page=1&per_page=10",+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "data": [+ {+ "id": TEST_KEY_ID,+ "name": "my-test-key",+ "value": "secret",+ "expires_at": "2030-01-01T00:00:00Z",+ "tags": ["env:test"],+ "created_at": "2024-01-01T00:00:00Z",+ "updated_at": "2024-01-01T00:00:00Z",+ "workspace_id": "ws-1",+ "limits": [],+ }+ ],+ "_pagination": {+ "page": 1,+ "per_page": 10,+ "pages": 1,+ "total": 1,+ },+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.get(+ signoz.self.host_configs["8080"].get(+ "/api/v2/gateway/ingestion_keys/search?name=my-test"+ ),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.OK+ ), f"Expected 200, got {response.status_code}: {response.text}"++ data = response.json()["data"]+ assert len(data["keys"]) == 1+ assert data["keys"][0]["name"] == "my-test-key"+++def test_search_ingestion_keys_empty(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Search returns an empty list when no keys match."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url="/v1/workspaces/me/keys/search?name=nonexistent&page=1&per_page=10",+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "data": [],+ "_pagination": {+ "page": 1,+ "per_page": 10,+ "pages": 0,+ "total": 0,+ },+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.get(+ signoz.self.host_configs["8080"].get(+ "/api/v2/gateway/ingestion_keys/search?name=nonexistent"+ ),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.OK+ ), f"Expected 200, got {response.status_code}: {response.text}"++ data = response.json()["data"]+ assert len(data["keys"]) == 0+ assert data["_pagination"]["total"] == 0+++def test_update_ingestion_key(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """PATCH /api/v2/gateway/ingestion_keys/{keyId} updates a key via the gateway."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/keys/{TEST_KEY_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.PATCH,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.patch(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/{TEST_KEY_ID}"+ ),+ json={+ "name": "renamed-key",+ "tags": ["env:prod"],+ "expires_at": "2031-06-15T00:00:00Z",+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ # Verify the body forwarded to the gateway+ body = get_latest_gateway_request_body(signoz, "PATCH", gateway_url)+ assert body is not None, "Expected a PATCH request to reach the gateway"+ assert body["name"] == "renamed-key"+ assert body["tags"] == ["env:prod"]+++def test_delete_ingestion_key(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """DELETE /api/v2/gateway/ingestion_keys/{keyId} deletes a key via the gateway."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/keys/{TEST_KEY_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.DELETE,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.delete(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/{TEST_KEY_ID}"+ ),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ # Verify at least one DELETE reached the gateway+ matched = get_gateway_requests(signoz, "DELETE", gateway_url)+ assert len(matched) >= 1, "Expected a DELETE request to reach the gateway"diff --git a/tests/integration/src/ingestionkeys/02_ingestion_keys_limits.py b/tests/integration/src/ingestionkeys/02_ingestion_keys_limits.pynew file mode 100644index 0000000000..e3531004f3--- /dev/null+++ b/tests/integration/src/ingestionkeys/02_ingestion_keys_limits.py@@ -0,0 +1,418 @@+from http import HTTPStatus+from typing import Callable, List++import requests+from wiremock.client import (+ HttpMethods,+ Mapping,+ MappingRequest,+ MappingResponse,+)++from fixtures import types+from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD, add_license+from fixtures.gatewayutils import (+ TEST_KEY_ID,+ TEST_LIMIT_ID,+ common_gateway_headers,+ get_gateway_requests,+ get_latest_gateway_request_body,+)+from fixtures.logger import setup_logger++logger = setup_logger(__name__)+++def test_apply_license(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, List[Mapping]], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Activate a license so that all subsequent gateway calls succeed."""+ add_license(signoz, make_http_mocks, get_token)+++# ---------------------------------------------------------------------------+# Create ingestion key limit+# ---------------------------------------------------------------------------+++def test_create_ingestion_key_limit_only_size(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Creating a limit with only size omits count from the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/keys/{TEST_KEY_ID}/limits"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.POST,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=201,+ json_body={+ "status": "success",+ "data": {"id": "limit-created-1"},+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.post(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/{TEST_KEY_ID}/limits"+ ),+ json={+ "signal": "logs",+ "config": {"day": {"size": 1000}},+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.CREATED+ ), f"Expected 201, got {response.status_code}: {response.text}"++ assert response.json()["data"]["id"] == "limit-created-1"++ body = get_latest_gateway_request_body(signoz, "POST", gateway_url)+ assert body is not None, "Expected a POST request to reach the gateway"+ assert body["signal"] == "logs"+ assert body["config"]["day"]["size"] == 1000+ assert "count" not in body["config"]["day"], "count should be absent when not set"+ assert "second" not in body["config"], "second should be absent when not set"+ assert body["tags"] == ["test"]+++def test_create_ingestion_key_limit_only_count(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Creating a limit with only count omits size from the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/keys/{TEST_KEY_ID}/limits"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.POST,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=201,+ json_body={+ "status": "success",+ "data": {"id": "limit-created-2"},+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.post(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/{TEST_KEY_ID}/limits"+ ),+ json={+ "signal": "traces",+ "config": {"day": {"count": 500}},+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.CREATED+ ), f"Expected 201, got {response.status_code}: {response.text}"++ body = get_latest_gateway_request_body(signoz, "POST", gateway_url)+ assert body is not None, "Expected a POST request to reach the gateway"+ assert body["signal"] == "traces"+ assert body["config"]["day"]["count"] == 500+ assert "size" not in body["config"]["day"], "size should be absent when not set"+ assert body["tags"] == ["test"]+++def test_create_ingestion_key_limit_both_size_and_count(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Creating a limit with both size and count includes both in the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/keys/{TEST_KEY_ID}/limits"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.POST,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=201,+ json_body={+ "status": "success",+ "data": {"id": "limit-created-3"},+ },+ ),+ persistent=False,+ ),+ ],+ )++ response = requests.post(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/{TEST_KEY_ID}/limits"+ ),+ json={+ "signal": "metrics",+ "config": {+ "day": {"size": 2000, "count": 750},+ "second": {"size": 100, "count": 50},+ },+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.CREATED+ ), f"Expected 201, got {response.status_code}: {response.text}"++ body = get_latest_gateway_request_body(signoz, "POST", gateway_url)+ assert body is not None, "Expected a POST request to reach the gateway"+ assert body["signal"] == "metrics"+ assert body["config"]["day"]["size"] == 2000+ assert body["config"]["day"]["count"] == 750+ assert body["config"]["second"]["size"] == 100+ assert body["config"]["second"]["count"] == 50+ assert body["tags"] == ["test"]+++# ---------------------------------------------------------------------------+# Update ingestion key limit+# ---------------------------------------------------------------------------+++def test_update_ingestion_key_limit_only_size(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Updating a limit with only size omits count from the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/limits/{TEST_LIMIT_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.PATCH,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.patch(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/limits/{TEST_LIMIT_ID}"+ ),+ json={+ "config": {"day": {"size": 2000}},+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ body = get_latest_gateway_request_body(signoz, "PATCH", gateway_url)+ assert body is not None, "Expected a PATCH request to reach the gateway"+ assert body["config"]["day"]["size"] == 2000+ assert "count" not in body["config"]["day"], "count should be absent when not set"+ assert "second" not in body["config"], "second should be absent when not set"+ assert body["tags"] == ["test"]+++def test_update_ingestion_key_limit_only_count(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Updating a limit with only count omits size from the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/limits/{TEST_LIMIT_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.PATCH,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.patch(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/limits/{TEST_LIMIT_ID}"+ ),+ json={+ "config": {"day": {"count": 750}},+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ body = get_latest_gateway_request_body(signoz, "PATCH", gateway_url)+ assert body is not None, "Expected a PATCH request to reach the gateway"+ assert body["config"]["day"]["count"] == 750+ assert "size" not in body["config"]["day"], "size should be absent when not set"+ assert body["tags"] == ["test"]+++def test_update_ingestion_key_limit_both_size_and_count(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """Updating a limit with both size and count includes both in the gateway payload."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/limits/{TEST_LIMIT_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.PATCH,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.patch(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/limits/{TEST_LIMIT_ID}"+ ),+ json={+ "config": {"day": {"size": 1000, "count": 500}},+ "tags": ["test"],+ },+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ body = get_latest_gateway_request_body(signoz, "PATCH", gateway_url)+ assert body is not None, "Expected a PATCH request to reach the gateway"+ assert body["config"]["day"]["size"] == 1000+ assert body["config"]["day"]["count"] == 500+ assert body["tags"] == ["test"]+++# ---------------------------------------------------------------------------+# Delete ingestion key limit+# ---------------------------------------------------------------------------+++def test_delete_ingestion_key_limit(+ signoz: types.SigNoz,+ create_user_admin: types.Operation, # pylint: disable=unused-argument+ make_http_mocks: Callable[[types.TestContainerDocker, list], None],+ get_token: Callable[[str, str], str],+) -> None:+ """DELETE /api/v2/gateway/ingestion_keys/limits/{limitId} deletes a limit."""+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ gateway_url = f"/v1/workspaces/me/limits/{TEST_LIMIT_ID}"++ make_http_mocks(+ signoz.gateway,+ [+ Mapping(+ request=MappingRequest(+ method=HttpMethods.DELETE,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(status=204),+ persistent=False,+ ),+ ],+ )++ response = requests.delete(+ signoz.self.host_configs["8080"].get(+ f"/api/v2/gateway/ingestion_keys/limits/{TEST_LIMIT_ID}"+ ),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=10,+ )++ assert (+ response.status_code == HTTPStatus.NO_CONTENT+ ), f"Expected 204, got {response.status_code}: {response.text}"++ # Verify at least one DELETE reached the gateway+ matched = get_gateway_requests(signoz, "DELETE", gateway_url)+ assert len(matched) >= 1, "Expected a DELETE request to reach the gateway"diff --git a/tests/integration/src/ingestionkeys/__init__.py b/tests/integration/src/ingestionkeys/__init__.pynew file mode 100644index 0000000000..e69de29bb2