Skip to content

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.

feat: add zeus handler with profile and host apis (#10336)

Karan Balani473be1b17445
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index 05b20a15a8..a06a2eb0af 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -1920,6 +1920,63 @@ components:
format: date-time
type: string
type: object
+ ZeustypesGettableHost:
+ properties:
+ hosts:
+ items:
+ $ref: '#/components/schemas/ZeustypesHost'
+ nullable: true
+ type: array
+ name:
+ type: string
+ state:
+ type: string
+ tier:
+ type: string
+ type: object
+ ZeustypesHost:
+ properties:
+ is_default:
+ type: boolean
+ name:
+ type: string
+ url:
+ type: string
+ type: object
+ ZeustypesPostableHost:
+ properties:
+ name:
+ type: string
+ required:
+ - name
+ type: object
+ ZeustypesPostableProfile:
+ properties:
+ existing_observability_tool:
+ type: string
+ has_existing_observability_tool:
+ type: boolean
+ logs_scale_per_day_in_gb:
+ format: int64
+ type: integer
+ number_of_hosts:
+ format: int64
+ type: integer
+ number_of_services:
+ format: int64
+ type: integer
+ reasons_for_interest_in_signoz:
+ items:
+ type: string
+ nullable: true
+ type: array
+ timeline_for_migrating_to_signoz:
+ type: string
+ uses_otel:
+ type: boolean
+ where_did_you_discover_signoz:
+ type: string
+ type: object
securitySchemes:
api_key:
description: API Keys
@@ -5538,6 +5595,174 @@ paths:
summary: Rotate session
tags:
- sessions
+ /api/v2/zeus/hosts:
+ get:
+ deprecated: false
+ description: This endpoint gets the host info from zeus.
+ operationId: GetHosts
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ properties:
+ data:
+ $ref: '#/components/schemas/ZeustypesGettableHost'
+ status:
+ type: string
+ type: object
+ description: OK
+ "400":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Bad Request
+ "401":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Unauthorized
+ "403":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Forbidden
+ "404":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Not Found
+ "500":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Internal Server Error
+ security:
+ - api_key:
+ - ADMIN
+ - tokenizer:
+ - ADMIN
+ summary: Get host info from Zeus.
+ tags:
+ - zeus
+ put:
+ deprecated: false
+ description: This endpoint saves the host of a deployment to zeus.
+ operationId: PutHost
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ZeustypesPostableHost'
+ responses:
+ "204":
+ description: No Content
+ "400":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Bad Request
+ "401":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Unauthorized
+ "403":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Forbidden
+ "404":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Not Found
+ "409":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Conflict
+ "500":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Internal Server Error
+ security:
+ - api_key:
+ - ADMIN
+ - tokenizer:
+ - ADMIN
+ summary: Put host in Zeus for a deployment.
+ tags:
+ - zeus
+ /api/v2/zeus/profiles:
+ put:
+ deprecated: false
+ description: This endpoint saves the profile of a deployment to zeus.
+ operationId: PutProfile
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ZeustypesPostableProfile'
+ responses:
+ "204":
+ description: No Content
+ "400":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Bad Request
+ "401":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Unauthorized
+ "403":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Forbidden
+ "404":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Not Found
+ "409":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Conflict
+ "500":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Internal Server Error
+ security:
+ - api_key:
+ - ADMIN
+ - tokenizer:
+ - ADMIN
+ summary: Put profile in Zeus for a deployment.
+ tags:
+ - zeus
/api/v5/query_range:
post:
deprecated: false
diff --git a/ee/zeus/httpzeus/provider.go b/ee/zeus/httpzeus/provider.go
index ceb54d5980..83abdc013d 100644
--- a/ee/zeus/httpzeus/provider.go
+++ b/ee/zeus/httpzeus/provider.go
@@ -3,6 +3,7 @@ package httpzeus
import (
"bytes"
"context"
+ "encoding/json"
"io"
"net/http"
"net/url"
@@ -10,6 +11,7 @@ import (
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/factory"
"github.com/SigNoz/signoz/pkg/http/client"
+ "github.com/SigNoz/signoz/pkg/types/zeustypes"
"github.com/SigNoz/signoz/pkg/zeus"
"github.com/tidwall/gjson"
)
@@ -119,8 +121,13 @@ func (provider *Provider) PutMeters(ctx context.Context, key string, data []byte
return err
}
-func (provider *Provider) PutProfile(ctx context.Context, key string, body []byte) error {
- _, err := provider.do(
+func (provider *Provider) PutProfile(ctx context.Context, key string, profile *zeustypes.PostableProfile) error {
+ body, err := json.Marshal(profile)
+ if err != nil {
+ return err
+ }
+
+ _, err = provider.do(
ctx,
provider.config.URL.JoinPath("/v2/profiles/me"),
http.MethodPut,
@@ -131,10 +138,15 @@ func (provider *Provider) PutProfile(ctx context.Context, key string, body []byt
return err
}
-func (provider *Provider) PutHost(ctx context.Context, key string, body []byte) error {
- _, err := provider.do(
+func (provider *Provider) PutHost(ctx context.Context, key string, host *zeustypes.PostableHost) error {
+ body, err := json.Marshal(host)
+ if err != nil {
+ return err
+ }
+
+ _, err = provider.do(
ctx,
- provider.config.URL.JoinPath("/v2/deployments/me/hosts"),
+ provider.config.URL.JoinPath("/v2/deployments/me/host"),
http.MethodPut,
key,
body,
@@ -169,21 +181,28 @@ func (provider *Provider) do(ctx context.Context, url *url.URL, method string, k
return body, nil
}
- return nil, provider.errFromStatusCode(response.StatusCode)
+ errorMessage := gjson.GetBytes(body, "error").String()
+ if errorMessage == "" {
+ errorMessage = "an unknown error occurred"
+ }
+
+ return nil, provider.errFromStatusCode(response.StatusCode, errorMessage)
}
// This can be taken down to the client package
-func (provider *Provider) errFromStatusCode(statusCode int) error {
+func (provider *Provider) errFromStatusCode(statusCode int, errorMessage string) error {
switch statusCode {
case http.StatusBadRequest:
- return errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "bad request")
+ return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, errorMessage)
case http.StatusUnauthorized:
- return errors.Newf(errors.TypeUnauthenticated, errors.CodeUnauthenticated, "unauthenticated")
+ return errors.New(errors.TypeUnauthenticated, errors.CodeUnauthenticated, errorMessage)
case http.StatusForbidden:
- return errors.Newf(errors.TypeForbidden, errors.CodeForbidden, "forbidden")
+ return errors.New(errors.TypeForbidden, errors.CodeForbidden, errorMessage)
case http.StatusNotFound:
- return errors.Newf(errors.TypeNotFound, errors.CodeNotFound, "not found")
+ return errors.New(errors.TypeNotFound, errors.CodeNotFound, errorMessage)
+ case http.StatusConflict:
+ return errors.New(errors.TypeAlreadyExists, errors.CodeAlreadyExists, errorMessage)
}
- return errors.Newf(errors.TypeInternal, errors.CodeInternal, "internal")
+ return errors.New(errors.TypeInternal, errors.CodeInternal, errorMessage)
}
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index a140d4a115..099bf22352 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -2414,6 +2414,91 @@ export interface TypesUserDTO {
updatedAt?: Date;
}
+export interface ZeustypesGettableHostDTO {
+ /**
+ * @type array
+ * @nullable true
+ */
+ hosts?: ZeustypesHostDTO[] | null;
+ /**
+ * @type string
+ */
+ name?: string;
+ /**
+ * @type string
+ */
+ state?: string;
+ /**
+ * @type string
+ */
+ tier?: string;
+}
+
+export interface ZeustypesHostDTO {
+ /**
+ * @type boolean
+ */
+ is_default?: boolean;
+ /**
+ * @type string
+ */
+ name?: string;
+ /**
+ * @type string
+ */
+ url?: string;
+}
+
+export interface ZeustypesPostableHostDTO {
+ /**
+ * @type string
+ */
+ name: string;
+}
+
+export interface ZeustypesPostableProfileDTO {
+ /**
+ * @type string
+ */
+ existing_observability_tool?: string;
+ /**
+ * @type boolean
+ */
+ has_existing_observability_tool?: boolean;
+ /**
+ * @type integer
+ * @format int64
+ */
+ logs_scale_per_day_in_gb?: number;
+ /**
+ * @type integer
+ * @format int64
+ */
+ number_of_hosts?: number;
+ /**
+ * @type integer
+ * @format int64
+ */
+ number_of_services?: number;
+ /**
+ * @type array
+ * @nullable true
+ */
+ reasons_for_interest_in_signoz?: string[] | null;
+ /**
+ * @type string
+ */
+ timeline_for_migrating_to_signoz?: string;
+ /**
+ * @type boolean
+ */
+ uses_otel?: boolean;
+ /**
+ * @type string
+ */
+ where_did_you_discover_signoz?: string;
+}
+
export type ChangePasswordPathParameters = {
id: string;
};
@@ -3129,6 +3214,14 @@ export type RotateSession200 = {
status?: string;
};
+export type GetHosts200 = {
+ data?: ZeustypesGettableHostDTO;
+ /**
+ * @type string
+ */
+ status?: string;
+};
+
export type QueryRangeV5200 = {
data?: Querybuildertypesv5QueryRangeResponseDTO;
/**
diff --git a/frontend/src/api/generated/services/zeus/index.ts b/frontend/src/api/generated/services/zeus/index.ts
new file mode 100644
index 0000000000..b94b1a0b22
--- /dev/null
+++ b/frontend/src/api/generated/services/zeus/index.ts
@@ -0,0 +1,269 @@
+/**
+ * ! Do not edit manually
+ * * The file has been auto-generated using Orval for SigNoz
+ * * regenerate with 'yarn generate:api'
+ * SigNoz
+ */
+import type {
+ InvalidateOptions,
+ MutationFunction,
+ QueryClient,
+ QueryFunction,
+ QueryKey,
+ UseMutationOptions,
+ UseMutationResult,
+ UseQueryOptions,
+ UseQueryResult,
+} from 'react-query';
+import { useMutation, useQuery } from 'react-query';
+
+import { GeneratedAPIInstance } from '../../../index';
+import type {
+ GetHosts200,
+ RenderErrorResponseDTO,
+ ZeustypesPostableHostDTO,
+ ZeustypesPostableProfileDTO,
+} from '../sigNoz.schemas';
+
+type AwaitedInput<T> = PromiseLike<T> | T;
+
+type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
+
+/**
+ * This endpoint gets the host info from zeus.
+ * @summary Get host info from Zeus.
+ */
+export const getHosts = (signal?: AbortSignal) => {
+ return GeneratedAPIInstance<GetHosts200>({
+ url: `/api/v2/zeus/hosts`,
+ method: 'GET',
+ signal,
+ });
+};
+
+export const getGetHostsQueryKey = () => {
+ return ['getHosts'] as const;
+};
+
+export const getGetHostsQueryOptions = <
+ TData = Awaited<ReturnType<typeof getHosts>>,
+ TError = RenderErrorResponseDTO
+>(options?: {
+ query?: UseQueryOptions<Awaited<ReturnType<typeof getHosts>>, TError, TData>;
+}) => {
+ const { query: queryOptions } = options ?? {};
+
+ const queryKey = queryOptions?.queryKey ?? getGetHostsQueryKey();
+
+ const queryFn: QueryFunction<Awaited<ReturnType<typeof getHosts>>> = ({
+ signal,
+ }) => getHosts(signal);
+
+ return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
+ Awaited<ReturnType<typeof getHosts>>,
+ TError,
+ TData
+ > & { queryKey: QueryKey };
+};
+
+export type GetHostsQueryResult = NonNullable<
+ Awaited<ReturnType<typeof getHosts>>
+>;
+export type GetHostsQueryError = RenderErrorResponseDTO;
+
+/**
+ * @summary Get host info from Zeus.
+ */
+
+export function useGetHosts<
+ TData = Awaited<ReturnType<typeof getHosts>>,
+ TError = RenderErrorResponseDTO
+>(options?: {
+ query?: UseQueryOptions<Awaited<ReturnType<typeof getHosts>>, TError, TData>;
+}): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
+ const queryOptions = getGetHostsQueryOptions(options);
+
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
+ queryKey: QueryKey;
+ };
+
+ query.queryKey = queryOptions.queryKey;
+
+ return query;
+}
+
+/**
+ * @summary Get host info from Zeus.
+ */
+export const invalidateGetHosts = async (
+ queryClient: QueryClient,
+ options?: InvalidateOptions,
+): Promise<QueryClient> => {
+ await queryClient.invalidateQueries(
+ { queryKey: getGetHostsQueryKey() },
+ options,
+ );
+
+ return queryClient;
+};
+
+/**
+ * This endpoint saves the host of a deployment to zeus.
+ * @summary Put host in Zeus for a deployment.
+ */
+export const putHost = (zeustypesPostableHostDTO: ZeustypesPostableHostDTO) => {
+ return GeneratedAPIInstance<void>({
+ url: `/api/v2/zeus/hosts`,
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ data: zeustypesPostableHostDTO,
+ });
+};
+
+export const getPutHostMutationOptions = <
+ TError = RenderErrorResponseDTO,
+ TContext = unknown
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof putHost>>,
+ TError,
+ { data: ZeustypesPostableHostDTO },
+ TContext
+ >;
+}): UseMutationOptions<
+ Awaited<ReturnType<typeof putHost>>,
+ TError,
+ { data: ZeustypesPostableHostDTO },
+ TContext
+> => {
+ const mutationKey = ['putHost'];
+ const { mutation: mutationOptions } = options
+ ? options.mutation &&
+ 'mutationKey' in options.mutation &&
+ options.mutation.mutationKey
+ ? options
+ : { ...options, mutation: { ...options.mutation, mutationKey } }
+ : { mutation: { mutationKey } };
+
+ const mutationFn: MutationFunction<
+ Awaited<ReturnType<typeof putHost>>,
+ { data: ZeustypesPostableHostDTO }
+ > = (props) => {
+ const { data } = props ?? {};
+
+ return putHost(data);
+ };
+
+ return { mutationFn, ...mutationOptions };
+};
+
+export type PutHostMutationResult = NonNullable<
+ Awaited<ReturnType<typeof putHost>>
+>;
+export type PutHostMutationBody = ZeustypesPostableHostDTO;
+export type PutHostMutationError = RenderErrorResponseDTO;
+
+/**
+ * @summary Put host in Zeus for a deployment.
+ */
+export const usePutHost = <
+ TError = RenderErrorResponseDTO,
+ TContext = unknown
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof putHost>>,
+ TError,
+ { data: ZeustypesPostableHostDTO },
+ TContext
+ >;
+}): UseMutationResult<
+ Awaited<ReturnType<typeof putHost>>,
+ TError,
+ { data: ZeustypesPostableHostDTO },
+ TContext
+> => {
+ const mutationOptions = getPutHostMutationOptions(options);
+
+ return useMutation(mutationOptions);
+};
+/**
+ * This endpoint saves the profile of a deployment to zeus.
+ * @summary Put profile in Zeus for a deployment.
+ */
+export const putProfile = (
+ zeustypesPostableProfileDTO: ZeustypesPostableProfileDTO,
+) => {
+ return GeneratedAPIInstance<void>({
+ url: `/api/v2/zeus/profiles`,
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ data: zeustypesPostableProfileDTO,
+ });
+};
+
+export const getPutProfileMutationOptions = <
+ TError = RenderErrorResponseDTO,
+ TContext = unknown
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof putProfile>>,
+ TError,
+ { data: ZeustypesPostableProfileDTO },
+ TContext
+ >;
+}): UseMutationOptions<
+ Awaited<ReturnType<typeof putProfile>>,
+ TError,
+ { data: ZeustypesPostableProfileDTO },
+ TContext
+> => {
+ const mutationKey = ['putProfile'];
+ const { mutation: mutationOptions } = options
+ ? options.mutation &&
+ 'mutationKey' in options.mutation &&
+ options.mutation.mutationKey
+ ? options
+ : { ...options, mutation: { ...options.mutation, mutationKey } }
+ : { mutation: { mutationKey } };
+
+ const mutationFn: MutationFunction<
+ Awaited<ReturnType<typeof putProfile>>,
+ { data: ZeustypesPostableProfileDTO }
+ > = (props) => {
+ const { data } = props ?? {};
+
+ return putProfile(data);
+ };
+
+ return { mutationFn, ...mutationOptions };
+};
+
+export type PutProfileMutationResult = NonNullable<
+ Awaited<ReturnType<typeof putProfile>>
+>;
+export type PutProfileMutationBody = ZeustypesPostableProfileDTO;
+export type PutProfileMutationError = RenderErrorResponseDTO;
+
+/**
+ * @summary Put profile in Zeus for a deployment.
+ */
+export const usePutProfile = <
+ TError = RenderErrorResponseDTO,
+ TContext = unknown
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof putProfile>>,
+ TError,
+ { data: ZeustypesPostableProfileDTO },
+ TContext
+ >;
+}): UseMutationResult<
+ Awaited<ReturnType<typeof putProfile>>,
+ TError,
+ { data: ZeustypesPostableProfileDTO },
+ TContext
+> => {
+ const mutationOptions = getPutProfileMutationOptions(options);
+
+ return useMutation(mutationOptions);
+};
diff --git a/pkg/apiserver/signozapiserver/provider.go b/pkg/apiserver/signozapiserver/provider.go
index 36ee2a3714..474b8ecf23 100644
--- a/pkg/apiserver/signozapiserver/provider.go
+++ b/pkg/apiserver/signozapiserver/provider.go
@@ -22,6 +22,7 @@ import (
"github.com/SigNoz/signoz/pkg/modules/user"
"github.com/SigNoz/signoz/pkg/types"
"github.com/SigNoz/signoz/pkg/types/ctxtypes"
+ "github.com/SigNoz/signoz/pkg/zeus"
"github.com/gorilla/mux"
)
@@ -44,6 +45,7 @@ type provider struct {
gatewayHandler gateway.Handler
fieldsHandler fields.Handler
authzHandler authz.Handler
+ zeusHandler zeus.Handler
}
func NewFactory(
@@ -63,6 +65,7 @@ func NewFactory(
gatewayHandler gateway.Handler,
fieldsHandler fields.Handler,
authzHandler authz.Handler,
+ zeusHandler zeus.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(
@@ -85,6 +88,7 @@ func NewFactory(
gatewayHandler,
fieldsHandler,
authzHandler,
+ zeusHandler,
)
})
}
@@ -109,6 +113,7 @@ func newProvider(
gatewayHandler gateway.Handler,
fieldsHandler fields.Handler,
authzHandler authz.Handler,
+ zeusHandler zeus.Handler,
) (apiserver.APIServer, error) {
settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/apiserver/signozapiserver")
router := mux.NewRouter().UseEncodedPath()
@@ -131,6 +136,7 @@ func newProvider(
gatewayHandler: gatewayHandler,
fieldsHandler: fieldsHandler,
authzHandler: authzHandler,
+ zeusHandler: zeusHandler,
}
provider.authZ = middleware.NewAuthZ(settings.Logger(), orgGetter, authz)
@@ -199,6 +205,10 @@ func (provider *provider) AddToRouter(router *mux.Router) error {
return err
}
+ if err := provider.addZeusRoutes(router); err != nil {
+ return err
+ }
+
return nil
}
diff --git a/pkg/apiserver/signozapiserver/zeus.go b/pkg/apiserver/signozapiserver/zeus.go
new file mode 100644
index 0000000000..36ba8a3817
--- /dev/null
+++ b/pkg/apiserver/signozapiserver/zeus.go
@@ -0,0 +1,65 @@
+package signozapiserver
+
+import (
+ "net/http"
+
+ "github.com/SigNoz/signoz/pkg/http/handler"
+ "github.com/SigNoz/signoz/pkg/types"
+ "github.com/SigNoz/signoz/pkg/types/zeustypes"
+ "github.com/gorilla/mux"
+)
+
+func (provider *provider) addZeusRoutes(router *mux.Router) error {
+ if err := router.Handle("/api/v2/zeus/profiles", handler.New(provider.authZ.AdminAccess(provider.zeusHandler.PutProfile), handler.OpenAPIDef{
+ ID: "PutProfile",
+ Tags: []string{"zeus"},
+ Summary: "Put profile in Zeus for a deployment.",
+ Description: "This endpoint saves the profile of a deployment to zeus.",
+ Request: new(zeustypes.PostableProfile),
+ RequestContentType: "application/json",
+ Response: nil,
+ ResponseContentType: "",
+ SuccessStatusCode: http.StatusNoContent,
+ ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound, http.StatusConflict},
+ Deprecated: false,
+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),
+ })).Methods(http.MethodPut).GetError(); err != nil {
+ return err
+ }
+
+ if err := router.Handle("/api/v2/zeus/hosts", handler.New(provider.authZ.AdminAccess(provider.zeusHandler.GetHosts), handler.OpenAPIDef{
+ ID: "GetHosts",
+ Tags: []string{"zeus"},
+ Summary: "Get host info from Zeus.",
+ Description: "This endpoint gets the host info from zeus.",
+ Request: nil,
+ RequestContentType: "",
+ Response: new(zeustypes.GettableHost),
+ ResponseContentType: "application/json",
+ SuccessStatusCode: http.StatusOK,
+ ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound},
+ Deprecated: false,
+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),
+ })).Methods(http.MethodGet).GetError(); err != nil {
+ return err
+ }
+
+ if err := router.Handle("/api/v2/zeus/hosts", handler.New(provider.authZ.AdminAccess(provider.zeusHandler.PutHost), handler.OpenAPIDef{
+ ID: "PutHost",
+ Tags: []string{"zeus"},
+ Summary: "Put host in Zeus for a deployment.",
+ Description: "This endpoint saves the host of a deployment to zeus.",
+ Request: new(zeustypes.PostableHost),
+ RequestContentType: "application/json",
+ Response: nil,
+ ResponseContentType: "",
+ SuccessStatusCode: http.StatusNoContent,
+ ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound, http.StatusConflict},
+ Deprecated: false,
+ SecuritySchemes: newSecuritySchemes(types.RoleAdmin),
+ })).Methods(http.MethodPut).GetError(); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/pkg/signoz/handler.go b/pkg/signoz/handler.go
index f4774ffe3c..ccbf740ce0 100644
--- a/pkg/signoz/handler.go
+++ b/pkg/signoz/handler.go
@@ -31,6 +31,7 @@ import (
"github.com/SigNoz/signoz/pkg/modules/tracefunnel/impltracefunnel"
"github.com/SigNoz/signoz/pkg/querier"
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
+ "github.com/SigNoz/signoz/pkg/zeus"
)
type Handlers struct {
@@ -48,6 +49,7 @@ type Handlers struct {
GatewayHandler gateway.Handler
Fields fields.Handler
AuthzHandler authz.Handler
+ ZeusHandler zeus.Handler
}
func NewHandlers(
@@ -60,6 +62,7 @@ func NewHandlers(
gatewayService gateway.Gateway,
telemetryMetadataStore telemetrytypes.MetadataStore,
authz authz.AuthZ,
+ zeusService zeus.Zeus,
) Handlers {
return Handlers{
SavedView: implsavedview.NewHandler(modules.SavedView),
@@ -76,5 +79,6 @@ func NewHandlers(
GatewayHandler: gateway.NewHandler(gatewayService),
Fields: implfields.NewHandler(providerSettings, telemetryMetadataStore),
AuthzHandler: signozauthzapi.NewHandler(authz),
+ ZeusHandler: zeus.NewHandler(zeusService, licensing),
}
}
diff --git a/pkg/signoz/handler_test.go b/pkg/signoz/handler_test.go
index 33aef84a9f..66df95b016 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, nil, nil, nil)
+ handlers := NewHandlers(modules, providerSettings, nil, nil, nil, nil, nil, nil, nil, nil)
reflectVal := reflect.ValueOf(handlers)
for i := 0; i < reflectVal.NumField(); i++ {
f := reflectVal.Field(i)
diff --git a/pkg/signoz/openapi.go b/pkg/signoz/openapi.go
index 972d82634a..7caae4223b 100644
--- a/pkg/signoz/openapi.go
+++ b/pkg/signoz/openapi.go
@@ -28,6 +28,7 @@ import (
"github.com/SigNoz/signoz/pkg/querier"
"github.com/SigNoz/signoz/pkg/types/ctxtypes"
"github.com/gorilla/mux"
+ "github.com/SigNoz/signoz/pkg/zeus"
"github.com/swaggest/jsonschema-go"
"github.com/swaggest/openapi-go"
"github.com/swaggest/openapi-go/openapi3"
@@ -58,6 +59,7 @@ func NewOpenAPI(ctx context.Context, instrumentation instrumentation.Instrumenta
struct{ gateway.Handler }{},
struct{ fields.Handler }{},
struct{ authz.Handler }{},
+ struct{ zeus.Handler }{},
).New(ctx, instrumentation.ToProviderSettings(), apiserver.Config{})
if err != nil {
return nil, err
diff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.go
index 0263d06911..6fc1246dde 100644
--- a/pkg/signoz/provider.go
+++ b/pkg/signoz/provider.go
@@ -252,6 +252,7 @@ func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.Au
handlers.GatewayHandler,
handlers.Fields,
handlers.AuthzHandler,
+ handlers.ZeusHandler,
),
)
}
diff --git a/pkg/signoz/signoz.go b/pkg/signoz/signoz.go
index c26e7795d7..51d6de90a4 100644
--- a/pkg/signoz/signoz.go
+++ b/pkg/signoz/signoz.go
@@ -392,7 +392,7 @@ func New(
userService := impluser.NewService(providerSettings, impluser.NewStore(sqlstore, providerSettings), modules.User, orgGetter, authz, config.User.Root)
// Initialize all handlers for the modules
- handlers := NewHandlers(modules, providerSettings, querier, licensing, global, flagger, gateway, telemetryMetadataStore, authz)
+ handlers := NewHandlers(modules, providerSettings, querier, licensing, global, flagger, gateway, telemetryMetadataStore, authz, zeus)
// Initialize the API server
apiserver, err := factory.NewProviderFromNamedMap(
diff --git a/pkg/types/zeustypes/types.go b/pkg/types/zeustypes/types.go
new file mode 100644
index 0000000000..6d15115a5a
--- /dev/null
+++ b/pkg/types/zeustypes/types.go
@@ -0,0 +1,58 @@
+package zeustypes
+
+import (
+ "net/url"
+
+ "github.com/tidwall/gjson"
+)
+
+type PostableHost struct {
+ Name string `json:"name" required:"true"`
+}
+
+type PostableProfile struct {
+ UsesOtel bool `json:"uses_otel"`
+ HasExistingObservabilityTool bool `json:"has_existing_observability_tool"`
+ ExistingObservabilityTool string `json:"existing_observability_tool"`
+ ReasonsForInterestInSigNoz []string `json:"reasons_for_interest_in_signoz"`
+ LogsScalePerDayInGB int64 `json:"logs_scale_per_day_in_gb"`
+ NumberOfServices int64 `json:"number_of_services"`
+ NumberOfHosts int64 `json:"number_of_hosts"`
+ WhereDidYouDiscoverSigNoz string `json:"where_did_you_discover_signoz"`
+ TimelineForMigratingToSigNoz string `json:"timeline_for_migrating_to_signoz"`
+}
+
+type GettableHost struct {
+ Name string `json:"name"`
+ State string `json:"state"`
+ Tier string `json:"tier"`
+ Hosts []Host `json:"hosts"`
+}
+
+type Host struct {
+ Name string `json:"name"`
+ IsDefault bool `json:"is_default"`
+ URL string `json:"url"`
+}
+
+func NewGettableHost(data []byte) *GettableHost {
+ parsed := gjson.ParseBytes(data)
+ dns := parsed.Get("cluster.region.dns").String()
+
+ hostResults := parsed.Get("hosts").Array()
+ hosts := make([]Host, len(hostResults))
+
+ for i, h := range hostResults {
+ name := h.Get("name").String()
+ hosts[i].Name = name
+ hosts[i].IsDefault = h.Get("is_default").Bool()
+ hosts[i].URL = (&url.URL{Scheme: "https", Host: name + "." + dns}).String()
+ }
+
+ return &GettableHost{
+ Name: parsed.Get("name").String(),
+ State: parsed.Get("state").String(),
+ Tier: parsed.Get("tier").String(),
+ Hosts: hosts,
+ }
+}
diff --git a/pkg/zeus/handler.go b/pkg/zeus/handler.go
new file mode 100644
index 0000000000..b448ae526b
--- /dev/null
+++ b/pkg/zeus/handler.go
@@ -0,0 +1,114 @@
+package zeus
+
+import (
+ "net/http"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/http/binding"
+ "github.com/SigNoz/signoz/pkg/http/render"
+ "github.com/SigNoz/signoz/pkg/licensing"
+ "github.com/SigNoz/signoz/pkg/types/authtypes"
+ "github.com/SigNoz/signoz/pkg/types/zeustypes"
+ "github.com/SigNoz/signoz/pkg/valuer"
+)
+
+type handler struct {
+ zeus Zeus
+ licensing licensing.Licensing
+}
+
+func NewHandler(zeus Zeus, licensing licensing.Licensing) Handler {
+ return &handler{
+ zeus: zeus,
+ licensing: licensing,
+ }
+}
+
+func (h *handler) PutProfile(rw http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+
+ claims, err := authtypes.ClaimsFromContext(ctx)
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ req := new(zeustypes.PostableProfile)
+ if err := binding.JSON.BindBody(r.Body, req); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ if err := h.zeus.PutProfile(ctx, license.Key, req); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ render.Success(rw, http.StatusNoContent, nil)
+}
+
+func (h *handler) GetHosts(rw http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+
+ claims, err := authtypes.ClaimsFromContext(ctx)
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ deploymentBytes, err := h.zeus.GetDeployment(ctx, license.Key)
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ response := zeustypes.NewGettableHost(deploymentBytes)
+
+ render.Success(rw, http.StatusOK, response)
+}
+
+func (h *handler) PutHost(rw http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+
+ claims, err := authtypes.ClaimsFromContext(ctx)
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ req := new(zeustypes.PostableHost)
+ if err := binding.JSON.BindBody(r.Body, req); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ if req.Name == "" {
+ render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "name is required"))
+ return
+ }
+
+ if err := h.zeus.PutHost(ctx, license.Key, req); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ render.Success(rw, http.StatusNoContent, nil)
+}
diff --git a/pkg/zeus/noopzeus/provider.go b/pkg/zeus/noopzeus/provider.go
index b626ca61d7..f5fabfa756 100644
--- a/pkg/zeus/noopzeus/provider.go
+++ b/pkg/zeus/noopzeus/provider.go
@@ -5,6 +5,7 @@ import (
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/factory"
+ "github.com/SigNoz/signoz/pkg/types/zeustypes"
"github.com/SigNoz/signoz/pkg/zeus"
)
@@ -40,10 +41,10 @@ func (provider *provider) PutMeters(_ context.Context, _ string, _ []byte) error
return errors.New(errors.TypeUnsupported, zeus.ErrCodeUnsupported, "putting meters is not supported")
}
-func (provider *provider) PutProfile(_ context.Context, _ string, _ []byte) error {
+func (provider *provider) PutProfile(_ context.Context, _ string, _ *zeustypes.PostableProfile) error {
return errors.New(errors.TypeUnsupported, zeus.ErrCodeUnsupported, "putting profile is not supported")
}
-func (provider *provider) PutHost(_ context.Context, _ string, _ []byte) error {
+func (provider *provider) PutHost(_ context.Context, _ string, _ *zeustypes.PostableHost) error {
return errors.New(errors.TypeUnsupported, zeus.ErrCodeUnsupported, "putting host is not supported")
}
diff --git a/pkg/zeus/zeus.go b/pkg/zeus/zeus.go
index 94c07f4735..a96c558a57 100644
--- a/pkg/zeus/zeus.go
+++ b/pkg/zeus/zeus.go
@@ -2,8 +2,10 @@ package zeus
import (
"context"
+ "net/http"
"github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/types/zeustypes"
)
var (
@@ -28,8 +30,19 @@ type Zeus interface {
PutMeters(context.Context, string, []byte) error
// Put profile for the given license key.
- PutProfile(context.Context, string, []byte) error
+ PutProfile(context.Context, string, *zeustypes.PostableProfile) error
// Put host for the given license key.
- PutHost(context.Context, string, []byte) error
+ PutHost(context.Context, string, *zeustypes.PostableHost) error
+}
+
+type Handler interface {
+ // API level handler for PutProfile
+ PutProfile(http.ResponseWriter, *http.Request)
+
+ // API level handler for getting hosts a slim wrapper around GetDeployment
+ GetHosts(http.ResponseWriter, *http.Request)
+
+ // API level handler for PutHost
+ PutHost(http.ResponseWriter, *http.Request)
}