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
refactor: remove legacy /api/gateway reverse proxy (#10374)
Pandey5a69f16410c7
diff --git a/ee/query-service/app/api/api.go b/ee/query-service/app/api/api.goindex 45de8cc5d8..f835653608 100644--- a/ee/query-service/app/api/api.go+++ b/ee/query-service/app/api/api.go@@ -2,11 +2,9 @@ package apiimport ("net/http"- "net/http/httputil""time""github.com/SigNoz/signoz/ee/licensing/httplicensing"- "github.com/SigNoz/signoz/ee/query-service/integrations/gateway""github.com/SigNoz/signoz/ee/query-service/usage""github.com/SigNoz/signoz/pkg/alertmanager""github.com/SigNoz/signoz/pkg/global"@@ -31,7 +29,6 @@ type APIHandlerOptions struct {IntegrationsController *integrations.ControllerCloudIntegrationsController *cloudintegrations.ControllerLogsParsingPipelineController *logparsingpipeline.LogParsingPipelineController- Gateway *httputil.ReverseProxyGatewayUrl string// Querier Influx IntervalFluxInterval time.Duration@@ -77,10 +74,6 @@ func (ah *APIHandler) UM() *usage.Manager {return ah.opts.UsageManager}-func (ah *APIHandler) Gateway() *httputil.ReverseProxy {- return ah.opts.Gateway-}-// RegisterRoutes registers routes for this handler on the given routerfunc (ah *APIHandler) RegisterRoutes(router *mux.Router, am *middleware.AuthZ) {// note: add ee override methods first@@ -103,9 +96,6 @@ func (ah *APIHandler) RegisterRoutes(router *mux.Router, am *middleware.AuthZ) {// v4router.HandleFunc("/api/v4/query_range", am.ViewAccess(ah.queryRangeV4)).Methods(http.MethodPost)- // Gateway- router.PathPrefix(gateway.RoutePrefix).HandlerFunc(am.EditAccess(ah.ServeGatewayHTTP))-ah.APIHandler.RegisterRoutes(router, am)}diff --git a/ee/query-service/app/api/gateway.go b/ee/query-service/app/api/gateway.godeleted file mode 100644index fa1d52153f..0000000000--- a/ee/query-service/app/api/gateway.go+++ /dev/null@@ -1,58 +0,0 @@-package api--import (- "net/http"- "strings"-- "github.com/SigNoz/signoz/ee/query-service/integrations/gateway"- "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/valuer"-)--func (ah *APIHandler) ServeGatewayHTTP(rw http.ResponseWriter, req *http.Request) {- ctx := req.Context()- claims, err := authtypes.ClaimsFromContext(ctx)- if err != nil {- render.Error(rw, err)- return- }-- orgID, err := valuer.NewUUID(claims.OrgID)- if err != nil {- render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "orgId is invalid"))- return- }-- validPath := false- for _, allowedPrefix := range gateway.AllowedPrefix {- if strings.HasPrefix(req.URL.Path, gateway.RoutePrefix+allowedPrefix) {- validPath = true- break- }- }-- if !validPath {- rw.WriteHeader(http.StatusNotFound)- return- }-- license, err := ah.Signoz.Licensing.GetActive(ctx, orgID)- if err != nil {- render.Error(rw, err)- return- }-- //Create headers- var licenseKey string- if license != nil {- licenseKey = license.Key- }-- req.Header.Set("X-Signoz-Cloud-Api-Key", licenseKey)- req.Header.Set("X-Consumer-Username", "lid:00000000-0000-0000-0000-000000000000")- req.Header.Set("X-Consumer-Groups", "ns:default")-- ah.Gateway().ServeHTTP(rw, req)-}diff --git a/ee/query-service/app/server.go b/ee/query-service/app/server.goindex c270f6589d..389d08d3e4 100644--- a/ee/query-service/app/server.go+++ b/ee/query-service/app/server.go@@ -19,7 +19,6 @@ import ("github.com/gorilla/handlers""github.com/SigNoz/signoz/ee/query-service/app/api"- "github.com/SigNoz/signoz/ee/query-service/integrations/gateway""github.com/SigNoz/signoz/ee/query-service/rules""github.com/SigNoz/signoz/ee/query-service/usage""github.com/SigNoz/signoz/pkg/alertmanager"@@ -72,11 +71,6 @@ type Server struct {// NewServer creates and initializes Serverfunc NewServer(config signoz.Config, signoz *signoz.SigNoz) (*Server, error) {- gatewayProxy, err := gateway.NewProxy(config.Gateway.URL.String(), gateway.RoutePrefix)- if err != nil {- return nil, err- }-cacheForTraceDetail, err := memorycache.New(context.TODO(), signoz.Instrumentation.ToProviderSettings(), cache.Config{Provider: "memory",Memory: cache.Memory{@@ -170,7 +164,6 @@ func NewServer(config signoz.Config, signoz *signoz.SigNoz) (*Server, error) {CloudIntegrationsController: cloudIntegrationsController,LogsParsingPipelineController: logParsingPipelineController,FluxInterval: config.Querier.FluxInterval,- Gateway: gatewayProxy,GatewayUrl: config.Gateway.URL.String(),GlobalConfig: config.Global,}diff --git a/ee/query-service/integrations/gateway/noop.go b/ee/query-service/integrations/gateway/noop.godeleted file mode 100644index ccb5d3269a..0000000000--- a/ee/query-service/integrations/gateway/noop.go+++ /dev/null@@ -1,9 +0,0 @@-package gateway--import (- "net/http/httputil"-)--func NewNoopProxy() (*httputil.ReverseProxy, error) {- return &httputil.ReverseProxy{}, nil-}diff --git a/ee/query-service/integrations/gateway/proxy.go b/ee/query-service/integrations/gateway/proxy.godeleted file mode 100644index 06cb08c33a..0000000000--- a/ee/query-service/integrations/gateway/proxy.go+++ /dev/null@@ -1,66 +0,0 @@-package gateway--import (- "net/http"- "net/http/httputil"- "net/url"- "path"- "strings"-)--var (- RoutePrefix string = "/api/gateway"- AllowedPrefix []string = []string{"/v1/workspaces/me", "/v2/profiles/me", "/v2/deployments/me"}-)--type proxy struct {- url *url.URL- stripPath string-}--func NewProxy(u string, stripPath string) (*httputil.ReverseProxy, error) {- url, err := url.Parse(u)- if err != nil {- return nil, err- }-- proxy := &proxy{url: url, stripPath: stripPath}-- return &httputil.ReverseProxy{- Rewrite: proxy.rewrite,- ModifyResponse: proxy.modifyResponse,- ErrorHandler: proxy.errorHandler,- }, nil-}--func (p *proxy) rewrite(pr *httputil.ProxyRequest) {- pr.SetURL(p.url)- pr.SetXForwarded()- pr.Out.URL.Path = cleanPath(strings.ReplaceAll(pr.Out.URL.Path, p.stripPath, ""))-}--func (p *proxy) modifyResponse(res *http.Response) error {- return nil-}--func (p *proxy) errorHandler(rw http.ResponseWriter, req *http.Request, err error) {- rw.WriteHeader(http.StatusBadGateway)-}--func cleanPath(p string) string {- if p == "" {- return "/"- }- if p[0] != '/' {- p = "/" + p- }- np := path.Clean(p)- if p[len(p)-1] == '/' && np != "/" {- if len(p) == len(np)+1 && strings.HasPrefix(p, np) {- np = p- } else {- np += "/"- }- }- return np-}diff --git a/ee/query-service/integrations/gateway/proxy_test.go b/ee/query-service/integrations/gateway/proxy_test.godeleted file mode 100644index 45f5211efe..0000000000--- a/ee/query-service/integrations/gateway/proxy_test.go+++ /dev/null@@ -1,61 +0,0 @@-package gateway--import (- "context"- "net/http"- "net/http/httputil"- "net/url"- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-)--func TestProxyRewrite(t *testing.T) {- testCases := []struct {- name string- url *url.URL- stripPath string- in *url.URL- expected *url.URL- }{- {- name: "SamePathAdded",- url: &url.URL{Scheme: "http", Host: "backend", Path: "/path1"},- stripPath: "/strip",- in: &url.URL{Scheme: "http", Host: "localhost", Path: "/strip/path1"},- expected: &url.URL{Scheme: "http", Host: "backend", Path: "/path1/path1"},- },- {- name: "NoStripPathInput",- url: &url.URL{Scheme: "http", Host: "backend"},- stripPath: "",- in: &url.URL{Scheme: "http", Host: "localhost", Path: "/strip/path1"},- expected: &url.URL{Scheme: "http", Host: "backend", Path: "/strip/path1"},- },- {- name: "NoStripPathPresentInReq",- url: &url.URL{Scheme: "http", Host: "backend"},- stripPath: "/not-found",- in: &url.URL{Scheme: "http", Host: "localhost", Path: "/strip/path1"},- expected: &url.URL{Scheme: "http", Host: "backend", Path: "/strip/path1"},- },- }-- for _, tc := range testCases {- proxy, err := NewProxy(tc.url.String(), tc.stripPath)- require.NoError(t, err)- inReq, err := http.NewRequest(http.MethodGet, tc.in.String(), nil)- require.NoError(t, err)- proxyReq := &httputil.ProxyRequest{- In: inReq,- Out: inReq.Clone(context.Background()),- }- proxy.Rewrite(proxyReq)-- assert.Equal(t, tc.expected.Host, proxyReq.Out.URL.Host)- assert.Equal(t, tc.expected.Scheme, proxyReq.Out.URL.Scheme)- assert.Equal(t, tc.expected.Path, proxyReq.Out.URL.Path)- assert.Equal(t, tc.expected.Query(), proxyReq.Out.URL.Query())- }-}diff --git a/frontend/src/api/IngestionKeys/createIngestionKey.ts b/frontend/src/api/IngestionKeys/createIngestionKey.tsdeleted file mode 100644index 77556ed20a..0000000000--- a/frontend/src/api/IngestionKeys/createIngestionKey.ts+++ /dev/null@@ -1,29 +0,0 @@-import { GatewayApiV1Instance } from 'api';-import { ErrorResponseHandler } from 'api/ErrorResponseHandler';-import { AxiosError } from 'axios';-import { ErrorResponse, SuccessResponse } from 'types/api';-import {- CreateIngestionKeyProps,- IngestionKeyProps,-} from 'types/api/ingestionKeys/types';--const createIngestionKey = async (- props: CreateIngestionKeyProps,-): Promise<SuccessResponse<IngestionKeyProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.post('/workspaces/me/keys', {- ...props,- });-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- return ErrorResponseHandler(error as AxiosError);- }-};--export default createIngestionKey;diff --git a/frontend/src/api/IngestionKeys/deleteIngestionKey.ts b/frontend/src/api/IngestionKeys/deleteIngestionKey.tsdeleted file mode 100644index 5f4e7e02c7..0000000000--- a/frontend/src/api/IngestionKeys/deleteIngestionKey.ts+++ /dev/null@@ -1,26 +0,0 @@-import { GatewayApiV1Instance } from 'api';-import { ErrorResponseHandler } from 'api/ErrorResponseHandler';-import { AxiosError } from 'axios';-import { ErrorResponse, SuccessResponse } from 'types/api';-import { AllIngestionKeyProps } from 'types/api/ingestionKeys/types';--const deleteIngestionKey = async (- id: string,-): Promise<SuccessResponse<AllIngestionKeyProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.delete(- `/workspaces/me/keys/${id}`,- );-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- return ErrorResponseHandler(error as AxiosError);- }-};--export default deleteIngestionKey;diff --git a/frontend/src/api/IngestionKeys/getAllIngestionKeys.ts b/frontend/src/api/IngestionKeys/getAllIngestionKeys.tsdeleted file mode 100644index e202917445..0000000000--- a/frontend/src/api/IngestionKeys/getAllIngestionKeys.ts+++ /dev/null@@ -1,21 +0,0 @@-import { GatewayApiV1Instance } from 'api';-import { AxiosResponse } from 'axios';-import {- AllIngestionKeyProps,- GetIngestionKeyProps,-} from 'types/api/ingestionKeys/types';--export const getAllIngestionKeys = (- props: GetIngestionKeyProps,-): Promise<AxiosResponse<AllIngestionKeyProps>> => {- // eslint-disable-next-line @typescript-eslint/naming-convention- const { search, per_page, page } = props;-- const BASE_URL = '/workspaces/me/keys';- const URL_QUERY_PARAMS =- search && search.length > 0- ? `/search?name=${search}&page=1&per_page=100`- : `?page=${page}&per_page=${per_page}`;-- return GatewayApiV1Instance.get(`${BASE_URL}${URL_QUERY_PARAMS}`);-};diff --git a/frontend/src/api/IngestionKeys/limits/createLimitsForKey.ts b/frontend/src/api/IngestionKeys/limits/createLimitsForKey.tsdeleted file mode 100644index 75128b9b78..0000000000--- a/frontend/src/api/IngestionKeys/limits/createLimitsForKey.ts+++ /dev/null@@ -1,65 +0,0 @@-/* eslint-disable @typescript-eslint/no-throw-literal */-import { GatewayApiV1Instance } from 'api';-import axios from 'axios';-import {- AddLimitProps,- LimitSuccessProps,-} from 'types/api/ingestionKeys/limits/types';--interface SuccessResponse<T> {- statusCode: number;- error: null;- message: string;- payload: T;-}--interface ErrorResponse {- statusCode: number;- error: string;- message: string;- payload: null;-}--const createLimitForIngestionKey = async (- props: AddLimitProps,-): Promise<SuccessResponse<LimitSuccessProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.post(- `/workspaces/me/keys/${props.keyID}/limits`,- {- ...props,- },- );-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- if (axios.isAxiosError(error)) {- // Axios error- const errResponse: ErrorResponse = {- statusCode: error.response?.status || 500,- error: error.response?.data?.error,- message: error.response?.data?.status || 'An error occurred',- payload: null,- };-- throw errResponse;- } else {- // Non-Axios error- const errResponse: ErrorResponse = {- statusCode: 500,- error: 'Unknown error',- message: 'An unknown error occurred',- payload: null,- };-- throw errResponse;- }- }-};--export default createLimitForIngestionKey;diff --git a/frontend/src/api/IngestionKeys/limits/deleteLimitsForIngestionKey.ts b/frontend/src/api/IngestionKeys/limits/deleteLimitsForIngestionKey.tsdeleted file mode 100644index c0b3480c45..0000000000--- a/frontend/src/api/IngestionKeys/limits/deleteLimitsForIngestionKey.ts+++ /dev/null@@ -1,26 +0,0 @@-import { GatewayApiV1Instance } from 'api';-import { ErrorResponseHandler } from 'api/ErrorResponseHandler';-import { AxiosError } from 'axios';-import { ErrorResponse, SuccessResponse } from 'types/api';-import { AllIngestionKeyProps } from 'types/api/ingestionKeys/types';--const deleteLimitsForIngestionKey = async (- id: string,-): Promise<SuccessResponse<AllIngestionKeyProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.delete(- `/workspaces/me/limits/${id}`,- );-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- return ErrorResponseHandler(error as AxiosError);- }-};--export default deleteLimitsForIngestionKey;diff --git a/frontend/src/api/IngestionKeys/limits/updateLimitsForIngestionKey.ts b/frontend/src/api/IngestionKeys/limits/updateLimitsForIngestionKey.tsdeleted file mode 100644index 89f3031e08..0000000000--- a/frontend/src/api/IngestionKeys/limits/updateLimitsForIngestionKey.ts+++ /dev/null@@ -1,65 +0,0 @@-/* eslint-disable @typescript-eslint/no-throw-literal */-import { GatewayApiV1Instance } from 'api';-import axios from 'axios';-import {- LimitSuccessProps,- UpdateLimitProps,-} from 'types/api/ingestionKeys/limits/types';--interface SuccessResponse<T> {- statusCode: number;- error: null;- message: string;- payload: T;-}--interface ErrorResponse {- statusCode: number;- error: string;- message: string;- payload: null;-}--const updateLimitForIngestionKey = async (- props: UpdateLimitProps,-): Promise<SuccessResponse<LimitSuccessProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.patch(- `/workspaces/me/limits/${props.limitID}`,- {- config: props.config,- },- );-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- if (axios.isAxiosError(error)) {- // Axios error- const errResponse: ErrorResponse = {- statusCode: error.response?.status || 500,- error: error.response?.data?.error,- message: error.response?.data?.status || 'An error occurred',- payload: null,- };-- throw errResponse;- } else {- // Non-Axios error- const errResponse: ErrorResponse = {- statusCode: 500,- error: 'Unknown error',- message: 'An unknown error occurred',- payload: null,- };-- throw errResponse;- }- }-};--export default updateLimitForIngestionKey;diff --git a/frontend/src/api/IngestionKeys/updateIngestionKey.ts b/frontend/src/api/IngestionKeys/updateIngestionKey.tsdeleted file mode 100644index c4777ef97f..0000000000--- a/frontend/src/api/IngestionKeys/updateIngestionKey.ts+++ /dev/null@@ -1,32 +0,0 @@-import { GatewayApiV1Instance } from 'api';-import { ErrorResponseHandler } from 'api/ErrorResponseHandler';-import { AxiosError } from 'axios';-import { ErrorResponse, SuccessResponse } from 'types/api';-import {- IngestionKeysPayloadProps,- UpdateIngestionKeyProps,-} from 'types/api/ingestionKeys/types';--const updateIngestionKey = async (- props: UpdateIngestionKeyProps,-): Promise<SuccessResponse<IngestionKeysPayloadProps> | ErrorResponse> => {- try {- const response = await GatewayApiV1Instance.patch(- `/workspaces/me/keys/${props.id}`,- {- ...props.data,- },- );-- return {- statusCode: 200,- error: null,- message: response.data.status,- payload: response.data.data,- };- } catch (error) {- return ErrorResponseHandler(error as AxiosError);- }-};--export default updateIngestionKey;diff --git a/frontend/src/api/apiV1.ts b/frontend/src/api/apiV1.tsindex f7f15f0cce..a451c56f98 100644--- a/frontend/src/api/apiV1.ts+++ b/frontend/src/api/apiV1.ts@@ -4,8 +4,6 @@ export const apiV2 = '/api/v2/';export const apiV3 = '/api/v3/';export const apiV4 = '/api/v4/';export const apiV5 = '/api/v5/';-export const gatewayApiV1 = '/api/gateway/v1/';-export const gatewayApiV2 = '/api/gateway/v2/';export const apiAlertManager = '/api/alertmanager/';export default apiV1;diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.tsindex e20fbbde2c..06ce86944a 100644--- a/frontend/src/api/index.ts+++ b/frontend/src/api/index.ts@@ -15,15 +15,7 @@ import { Events } from 'constants/events';import { LOCALSTORAGE } from 'constants/localStorage';import { eventEmitter } from 'utils/getEventEmitter';-import apiV1, {- apiAlertManager,- apiV2,- apiV3,- apiV4,- apiV5,- gatewayApiV1,- gatewayApiV2,-} from './apiV1';+import apiV1, { apiAlertManager, apiV2, apiV3, apiV4, apiV5 } from './apiV1';import { Logout } from './utils';const RESPONSE_TIMEOUT_THRESHOLD = 5000; // 5 seconds@@ -211,24 +203,6 @@ LogEventAxiosInstance.interceptors.response.use(LogEventAxiosInstance.interceptors.request.use(interceptorsRequestResponse);//-// gateway Api V1-export const GatewayApiV1Instance = axios.create({- baseURL: `${ENVIRONMENT.baseURL}${gatewayApiV1}`,-});--GatewayApiV1Instance.interceptors.response.use(- interceptorsResponse,- interceptorRejected,-);--GatewayApiV1Instance.interceptors.request.use(interceptorsRequestResponse);-//--// gateway Api V2-export const GatewayApiV2Instance = axios.create({- baseURL: `${ENVIRONMENT.baseURL}${gatewayApiV2}`,-});-// generated API Instanceexport const GeneratedAPIInstance = axios.create({baseURL: ENVIRONMENT.baseURL,@@ -240,14 +214,6 @@ GeneratedAPIInstance.interceptors.response.use(interceptorRejected,);-GatewayApiV2Instance.interceptors.response.use(- interceptorsResponse,- interceptorRejected,-);--GatewayApiV2Instance.interceptors.request.use(interceptorsRequestResponse);-//-AxiosAlertManagerInstance.interceptors.response.use(interceptorsResponse,interceptorRejected,diff --git a/frontend/src/hooks/IngestionKeys/useGetAllIngestionKeys.ts b/frontend/src/hooks/IngestionKeys/useGetAllIngestionKeys.tsdeleted file mode 100644index 1f48df4eb3..0000000000--- a/frontend/src/hooks/IngestionKeys/useGetAllIngestionKeys.ts+++ /dev/null@@ -1,15 +0,0 @@-import { useQuery, UseQueryResult } from 'react-query';-import { getAllIngestionKeys } from 'api/IngestionKeys/getAllIngestionKeys';-import { AxiosError, AxiosResponse } from 'axios';-import {- AllIngestionKeyProps,- GetIngestionKeyProps,-} from 'types/api/ingestionKeys/types';--export const useGetAllIngestionsKeys = (- props: GetIngestionKeyProps,-): UseQueryResult<AxiosResponse<AllIngestionKeyProps>, AxiosError> =>- useQuery<AxiosResponse<AllIngestionKeyProps>, AxiosError>({- queryKey: [`IngestionKeys-${props.page}-${props.search}`],- queryFn: () => getAllIngestionKeys(props),- });