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(infra-monitoring): v2 daemonsets list api (#11149)

Nikhil Mantri72a58c634bf3
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index dbd83f2842..5a72245290 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -2580,6 +2580,76 @@ components:
- requiredMetricsCheck
- endTimeBeforeRetention
type: object
+ InframonitoringtypesDaemonSetRecord:
+ properties:
+ currentNodes:
+ type: integer
+ daemonSetCPU:
+ format: double
+ type: number
+ daemonSetCPULimit:
+ format: double
+ type: number
+ daemonSetCPURequest:
+ format: double
+ type: number
+ daemonSetMemory:
+ format: double
+ type: number
+ daemonSetMemoryLimit:
+ format: double
+ type: number
+ daemonSetMemoryRequest:
+ format: double
+ type: number
+ daemonSetName:
+ type: string
+ desiredNodes:
+ type: integer
+ meta:
+ additionalProperties:
+ type: string
+ nullable: true
+ type: object
+ podCountsByPhase:
+ $ref: '#/components/schemas/InframonitoringtypesPodCountsByPhase'
+ required:
+ - daemonSetName
+ - daemonSetCPU
+ - daemonSetCPURequest
+ - daemonSetCPULimit
+ - daemonSetMemory
+ - daemonSetMemoryRequest
+ - daemonSetMemoryLimit
+ - desiredNodes
+ - currentNodes
+ - podCountsByPhase
+ - meta
+ type: object
+ InframonitoringtypesDaemonSets:
+ properties:
+ endTimeBeforeRetention:
+ type: boolean
+ records:
+ items:
+ $ref: '#/components/schemas/InframonitoringtypesDaemonSetRecord'
+ nullable: true
+ type: array
+ requiredMetricsCheck:
+ $ref: '#/components/schemas/InframonitoringtypesRequiredMetricsCheck'
+ total:
+ type: integer
+ type:
+ $ref: '#/components/schemas/InframonitoringtypesResponseType'
+ warning:
+ $ref: '#/components/schemas/Querybuildertypesv5QueryWarnData'
+ required:
+ - type
+ - records
+ - total
+ - requiredMetricsCheck
+ - endTimeBeforeRetention
+ type: object
InframonitoringtypesDeploymentRecord:
properties:
availablePods:
@@ -3056,6 +3126,32 @@ components:
- end
- limit
type: object
+ InframonitoringtypesPostableDaemonSets:
+ properties:
+ end:
+ format: int64
+ type: integer
+ filter:
+ $ref: '#/components/schemas/Querybuildertypesv5Filter'
+ groupBy:
+ items:
+ $ref: '#/components/schemas/Querybuildertypesv5GroupByKey'
+ nullable: true
+ type: array
+ limit:
+ type: integer
+ offset:
+ type: integer
+ orderBy:
+ $ref: '#/components/schemas/Querybuildertypesv5OrderBy'
+ start:
+ format: int64
+ type: integer
+ required:
+ - start
+ - end
+ - limit
+ type: object
InframonitoringtypesPostableDeployments:
properties:
end:
@@ -12275,6 +12371,83 @@ paths:
summary: List Clusters for Infra Monitoring
tags:
- inframonitoring
+ /api/v2/infra_monitoring/daemonsets:
+ post:
+ deprecated: false
+ description: 'Returns a paginated list of Kubernetes DaemonSets with key aggregated
+ pod metrics: CPU usage and memory working set summed across pods owned by
+ the daemonset, plus average CPU/memory request and limit utilization (daemonSetCPURequest,
+ daemonSetCPULimit, daemonSetMemoryRequest, daemonSetMemoryLimit). Each row
+ also reports the latest known node-level counters from kube-state-metrics:
+ desiredNodes (k8s.daemonset.desired_scheduled_nodes, the number of nodes the
+ daemonset wants to run on) and currentNodes (k8s.daemonset.current_scheduled_nodes,
+ the number of nodes the daemonset currently runs on) — note these are node
+ counts, not pod counts. It also reports per-group podCountsByPhase ({ pending,
+ running, succeeded, failed, unknown } from each pod''s latest k8s.pod.phase
+ value). Each daemonset includes metadata attributes (k8s.daemonset.name, k8s.namespace.name,
+ k8s.cluster.name). The response type is ''list'' for the default k8s.daemonset.name
+ grouping or ''grouped_list'' for custom groupBy keys; in both modes every
+ row aggregates pods owned by daemonsets in the group. Supports filtering via
+ a filter expression, custom groupBy, ordering by cpu / cpu_request / cpu_limit
+ / memory / memory_request / memory_limit / desired_nodes / current_nodes,
+ and pagination via offset/limit. Also reports missing required metrics and
+ whether the requested time range falls before the data retention boundary.
+ Numeric metric fields (daemonSetCPU, daemonSetCPURequest, daemonSetCPULimit,
+ daemonSetMemory, daemonSetMemoryRequest, daemonSetMemoryLimit, desiredNodes,
+ currentNodes) return -1 as a sentinel when no data is available for that field.'
+ operationId: ListDaemonSets
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/InframonitoringtypesPostableDaemonSets'
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ properties:
+ data:
+ $ref: '#/components/schemas/InframonitoringtypesDaemonSets'
+ status:
+ type: string
+ required:
+ - status
+ - data
+ 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
+ "500":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenderErrorResponse'
+ description: Internal Server Error
+ security:
+ - api_key:
+ - VIEWER
+ - tokenizer:
+ - VIEWER
+ summary: List DaemonSets for Infra Monitoring
+ tags:
+ - inframonitoring
/api/v2/infra_monitoring/deployments:
post:
deprecated: false
diff --git a/frontend/src/api/generated/services/inframonitoring/index.ts b/frontend/src/api/generated/services/inframonitoring/index.ts
index 969699289d..c84b8b61f6 100644
--- a/frontend/src/api/generated/services/inframonitoring/index.ts
+++ b/frontend/src/api/generated/services/inframonitoring/index.ts
@@ -14,6 +14,7 @@ import type {
import type {
InframonitoringtypesPostableClustersDTO,
+ InframonitoringtypesPostableDaemonSetsDTO,
InframonitoringtypesPostableDeploymentsDTO,
InframonitoringtypesPostableHostsDTO,
InframonitoringtypesPostableJobsDTO,
@@ -23,6 +24,7 @@ import type {
InframonitoringtypesPostableStatefulSetsDTO,
InframonitoringtypesPostableVolumesDTO,
ListClusters200,
+ ListDaemonSets200,
ListDeployments200,
ListHosts200,
ListJobs200,
@@ -120,6 +122,89 @@ export const useListClusters = <
> => {
return useMutation(getListClustersMutationOptions(options));
};
+/**
+ * Returns a paginated list of Kubernetes DaemonSets with key aggregated pod metrics: CPU usage and memory working set summed across pods owned by the daemonset, plus average CPU/memory request and limit utilization (daemonSetCPURequest, daemonSetCPULimit, daemonSetMemoryRequest, daemonSetMemoryLimit). Each row also reports the latest known node-level counters from kube-state-metrics: desiredNodes (k8s.daemonset.desired_scheduled_nodes, the number of nodes the daemonset wants to run on) and currentNodes (k8s.daemonset.current_scheduled_nodes, the number of nodes the daemonset currently runs on) — note these are node counts, not pod counts. It also reports per-group podCountsByPhase ({ pending, running, succeeded, failed, unknown } from each pod's latest k8s.pod.phase value). Each daemonset includes metadata attributes (k8s.daemonset.name, k8s.namespace.name, k8s.cluster.name). The response type is 'list' for the default k8s.daemonset.name grouping or 'grouped_list' for custom groupBy keys; in both modes every row aggregates pods owned by daemonsets in the group. Supports filtering via a filter expression, custom groupBy, ordering by cpu / cpu_request / cpu_limit / memory / memory_request / memory_limit / desired_nodes / current_nodes, and pagination via offset/limit. Also reports missing required metrics and whether the requested time range falls before the data retention boundary. Numeric metric fields (daemonSetCPU, daemonSetCPURequest, daemonSetCPULimit, daemonSetMemory, daemonSetMemoryRequest, daemonSetMemoryLimit, desiredNodes, currentNodes) return -1 as a sentinel when no data is available for that field.
+ * @summary List DaemonSets for Infra Monitoring
+ */
+export const listDaemonSets = (
+ inframonitoringtypesPostableDaemonSetsDTO?: BodyType<InframonitoringtypesPostableDaemonSetsDTO>,
+ signal?: AbortSignal,
+) => {
+ return GeneratedAPIInstance<ListDaemonSets200>({
+ url: `/api/v2/infra_monitoring/daemonsets`,
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ data: inframonitoringtypesPostableDaemonSetsDTO,
+ signal,
+ });
+};
+
+export const getListDaemonSetsMutationOptions = <
+ TError = ErrorType<RenderErrorResponseDTO>,
+ TContext = unknown,
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof listDaemonSets>>,
+ TError,
+ { data?: BodyType<InframonitoringtypesPostableDaemonSetsDTO> },
+ TContext
+ >;
+}): UseMutationOptions<
+ Awaited<ReturnType<typeof listDaemonSets>>,
+ TError,
+ { data?: BodyType<InframonitoringtypesPostableDaemonSetsDTO> },
+ TContext
+> => {
+ const mutationKey = ['listDaemonSets'];
+ 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 listDaemonSets>>,
+ { data?: BodyType<InframonitoringtypesPostableDaemonSetsDTO> }
+ > = (props) => {
+ const { data } = props ?? {};
+
+ return listDaemonSets(data);
+ };
+
+ return { mutationFn, ...mutationOptions };
+};
+
+export type ListDaemonSetsMutationResult = NonNullable<
+ Awaited<ReturnType<typeof listDaemonSets>>
+>;
+export type ListDaemonSetsMutationBody =
+ | BodyType<InframonitoringtypesPostableDaemonSetsDTO>
+ | undefined;
+export type ListDaemonSetsMutationError = ErrorType<RenderErrorResponseDTO>;
+
+/**
+ * @summary List DaemonSets for Infra Monitoring
+ */
+export const useListDaemonSets = <
+ TError = ErrorType<RenderErrorResponseDTO>,
+ TContext = unknown,
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof listDaemonSets>>,
+ TError,
+ { data?: BodyType<InframonitoringtypesPostableDaemonSetsDTO> },
+ TContext
+ >;
+}): UseMutationResult<
+ Awaited<ReturnType<typeof listDaemonSets>>,
+ TError,
+ { data?: BodyType<InframonitoringtypesPostableDaemonSetsDTO> },
+ TContext
+> => {
+ return useMutation(getListDaemonSetsMutationOptions(options));
+};
/**
* Returns a paginated list of Kubernetes Deployments with key aggregated pod metrics: CPU usage and memory working set summed across pods owned by the deployment, plus average CPU/memory request and limit utilization (deploymentCPURequest, deploymentCPULimit, deploymentMemoryRequest, deploymentMemoryLimit). Each row also reports the latest known desiredPods (k8s.deployment.desired) and availablePods (k8s.deployment.available) replica counts and per-group podCountsByPhase ({ pending, running, succeeded, failed, unknown } from each pod's latest k8s.pod.phase value). Each deployment includes metadata attributes (k8s.deployment.name, k8s.namespace.name, k8s.cluster.name). The response type is 'list' for the default k8s.deployment.name grouping or 'grouped_list' for custom groupBy keys; in both modes every row aggregates pods owned by deployments in the group. Supports filtering via a filter expression, custom groupBy, ordering by cpu / cpu_request / cpu_limit / memory / memory_request / memory_limit / desired_pods / available_pods, and pagination via offset/limit. Also reports missing required metrics and whether the requested time range falls before the data retention boundary. Numeric metric fields (deploymentCPU, deploymentCPURequest, deploymentCPULimit, deploymentMemory, deploymentMemoryRequest, deploymentMemoryLimit, desiredPods, availablePods) return -1 as a sentinel when no data is available for that field.
* @summary List Deployments for Infra Monitoring
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index bfcf93574b..52612924bf 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -3376,6 +3376,84 @@ export interface InframonitoringtypesClustersDTO {
warning?: Querybuildertypesv5QueryWarnDataDTO;
}
+export type InframonitoringtypesDaemonSetRecordDTOMetaAnyOf = {
+ [key: string]: string;
+};
+
+/**
+ * @nullable
+ */
+export type InframonitoringtypesDaemonSetRecordDTOMeta =
+ InframonitoringtypesDaemonSetRecordDTOMetaAnyOf | null;
+
+export interface InframonitoringtypesDaemonSetRecordDTO {
+ /**
+ * @type integer
+ */
+ currentNodes: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetCPU: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetCPULimit: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetCPURequest: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetMemory: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetMemoryLimit: number;
+ /**
+ * @type number
+ * @format double
+ */
+ daemonSetMemoryRequest: number;
+ /**
+ * @type string
+ */
+ daemonSetName: string;
+ /**
+ * @type integer
+ */
+ desiredNodes: number;
+ /**
+ * @type object,null
+ */
+ meta: InframonitoringtypesDaemonSetRecordDTOMeta;
+ podCountsByPhase: InframonitoringtypesPodCountsByPhaseDTO;
+}
+
+export interface InframonitoringtypesDaemonSetsDTO {
+ /**
+ * @type boolean
+ */
+ endTimeBeforeRetention: boolean;
+ /**
+ * @type array,null
+ */
+ records: InframonitoringtypesDaemonSetRecordDTO[] | null;
+ requiredMetricsCheck: InframonitoringtypesRequiredMetricsCheckDTO;
+ /**
+ * @type integer
+ */
+ total: number;
+ type: InframonitoringtypesResponseTypeDTO;
+ warning?: Querybuildertypesv5QueryWarnDataDTO;
+}
+
export type InframonitoringtypesDeploymentRecordDTOMetaAnyOf = {
[key: string]: string;
};
@@ -3926,6 +4004,33 @@ export interface InframonitoringtypesPostableClustersDTO {
start: number;
}
+export interface InframonitoringtypesPostableDaemonSetsDTO {
+ /**
+ * @type integer
+ * @format int64
+ */
+ end: number;
+ filter?: Querybuildertypesv5FilterDTO;
+ /**
+ * @type array,null
+ */
+ groupBy?: Querybuildertypesv5GroupByKeyDTO[] | null;
+ /**
+ * @type integer
+ */
+ limit: number;
+ /**
+ * @type integer
+ */
+ offset?: number;
+ orderBy?: Querybuildertypesv5OrderByDTO;
+ /**
+ * @type integer
+ * @format int64
+ */
+ start: number;
+}
+
export interface InframonitoringtypesPostableDeploymentsDTO {
/**
* @type integer
@@ -8430,6 +8535,14 @@ export type ListClusters200 = {
status: string;
};
+export type ListDaemonSets200 = {
+ data: InframonitoringtypesDaemonSetsDTO;
+ /**
+ * @type string
+ */
+ status: string;
+};
+
export type ListDeployments200 = {
data: InframonitoringtypesDeploymentsDTO;
/**
diff --git a/pkg/apiserver/signozapiserver/inframonitoring.go b/pkg/apiserver/signozapiserver/inframonitoring.go
index 3e034f421f..89269b9c68 100644
--- a/pkg/apiserver/signozapiserver/inframonitoring.go
+++ b/pkg/apiserver/signozapiserver/inframonitoring.go
@@ -181,5 +181,24 @@ func (provider *provider) addInfraMonitoringRoutes(router *mux.Router) error {
return err
}
+ if err := router.Handle("/api/v2/infra_monitoring/daemonsets", handler.New(
+ provider.authzMiddleware.ViewAccess(provider.infraMonitoringHandler.ListDaemonSets),
+ handler.OpenAPIDef{
+ ID: "ListDaemonSets",
+ Tags: []string{"inframonitoring"},
+ Summary: "List DaemonSets for Infra Monitoring",
+ Description: "Returns a paginated list of Kubernetes DaemonSets with key aggregated pod metrics: CPU usage and memory working set summed across pods owned by the daemonset, plus average CPU/memory request and limit utilization (daemonSetCPURequest, daemonSetCPULimit, daemonSetMemoryRequest, daemonSetMemoryLimit). Each row also reports the latest known node-level counters from kube-state-metrics: desiredNodes (k8s.daemonset.desired_scheduled_nodes, the number of nodes the daemonset wants to run on) and currentNodes (k8s.daemonset.current_scheduled_nodes, the number of nodes the daemonset currently runs on) — note these are node counts, not pod counts. It also reports per-group podCountsByPhase ({ pending, running, succeeded, failed, unknown } from each pod's latest k8s.pod.phase value). Each daemonset includes metadata attributes (k8s.daemonset.name, k8s.namespace.name, k8s.cluster.name). The response type is 'list' for the default k8s.daemonset.name grouping or 'grouped_list' for custom groupBy keys; in both modes every row aggregates pods owned by daemonsets in the group. Supports filtering via a filter expression, custom groupBy, ordering by cpu / cpu_request / cpu_limit / memory / memory_request / memory_limit / desired_nodes / current_nodes, and pagination via offset/limit. Also reports missing required metrics and whether the requested time range falls before the data retention boundary. Numeric metric fields (daemonSetCPU, daemonSetCPURequest, daemonSetCPULimit, daemonSetMemory, daemonSetMemoryRequest, daemonSetMemoryLimit, desiredNodes, currentNodes) return -1 as a sentinel when no data is available for that field.",
+ Request: new(inframonitoringtypes.PostableDaemonSets),
+ RequestContentType: "application/json",
+ Response: new(inframonitoringtypes.DaemonSets),
+ ResponseContentType: "application/json",
+ SuccessStatusCode: http.StatusOK,
+ ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusUnauthorized},
+ Deprecated: false,
+ SecuritySchemes: newSecuritySchemes(types.RoleViewer),
+ })).Methods(http.MethodPost).GetError(); err != nil {
+ return err
+ }
+
return nil
}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/daemonsets.go b/pkg/modules/inframonitoring/implinframonitoring/daemonsets.go
new file mode 100644
index 0000000000..ee31a8a99a
--- /dev/null
+++ b/pkg/modules/inframonitoring/implinframonitoring/daemonsets.go
@@ -0,0 +1,148 @@
+package implinframonitoring
+
+import (
+ "context"
+ "slices"
+
+ "github.com/SigNoz/signoz/pkg/types/inframonitoringtypes"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+ "github.com/SigNoz/signoz/pkg/valuer"
+)
+
+// buildDaemonSetRecords assembles the page records. Pod phase counts come from
+// phaseCounts in both modes; every row is a group of pods (one daemonset in
+// list mode, an arbitrary roll-up in grouped_list mode), so there's no
+// per-row "current phase" concept.
+func buildDaemonSetRecords(
+ resp *qbtypes.QueryRangeResponse,
+ pageGroups []map[string]string,
+ groupBy []qbtypes.GroupByKey,
+ metadataMap map[string]map[string]string,
+ phaseCounts map[string]podPhaseCounts,
+) []inframonitoringtypes.DaemonSetRecord {
+ metricsMap := parseFullQueryResponse(resp, groupBy)
+
+ records := make([]inframonitoringtypes.DaemonSetRecord, 0, len(pageGroups))
+ for _, labels := range pageGroups {
+ compositeKey := compositeKeyFromLabels(labels, groupBy)
+ daemonSetName := labels[daemonSetNameAttrKey]
+
+ record := inframonitoringtypes.DaemonSetRecord{ // initialize with default values
+ DaemonSetName: daemonSetName,
+ DaemonSetCPU: -1,
+ DaemonSetCPURequest: -1,
+ DaemonSetCPULimit: -1,
+ DaemonSetMemory: -1,
+ DaemonSetMemoryRequest: -1,
+ DaemonSetMemoryLimit: -1,
+ DesiredNodes: -1,
+ CurrentNodes: -1,
+ Meta: map[string]string{},
+ }
+
+ if metrics, ok := metricsMap[compositeKey]; ok {
+ if v, exists := metrics["A"]; exists {
+ record.DaemonSetCPU = v
+ }
+ if v, exists := metrics["B"]; exists {
+ record.DaemonSetCPURequest = v
+ }
+ if v, exists := metrics["C"]; exists {
+ record.DaemonSetCPULimit = v
+ }
+ if v, exists := metrics["D"]; exists {
+ record.DaemonSetMemory = v
+ }
+ if v, exists := metrics["E"]; exists {
+ record.DaemonSetMemoryRequest = v
+ }
+ if v, exists := metrics["F"]; exists {
+ record.DaemonSetMemoryLimit = v
+ }
+ if v, exists := metrics["H"]; exists {
+ record.DesiredNodes = int(v)
+ }
+ if v, exists := metrics["I"]; exists {
+ record.CurrentNodes = int(v)
+ }
+ }
+
+ if phaseCountsForGroup, ok := phaseCounts[compositeKey]; ok {
+ record.PodCountsByPhase = inframonitoringtypes.PodCountsByPhase{
+ Pending: phaseCountsForGroup.Pending,
+ Running: phaseCountsForGroup.Running,
+ Succeeded: phaseCountsForGroup.Succeeded,
+ Failed: phaseCountsForGroup.Failed,
+ Unknown: phaseCountsForGroup.Unknown,
+ }
+ }
+
+ if attrs, ok := metadataMap[compositeKey]; ok {
+ for k, v := range attrs {
+ record.Meta[k] = v
+ }
+ }
+
+ records = append(records, record)
+ }
+ return records
+}
+
+func (m *module) getTopDaemonSetGroups(
+ ctx context.Context,
+ orgID valuer.UUID,
+ req *inframonitoringtypes.PostableDaemonSets,
+ metadataMap map[string]map[string]string,
+) ([]map[string]string, error) {
+ orderByKey := req.OrderBy.Key.Name
+ queryNamesForOrderBy := orderByToDaemonSetsQueryNames[orderByKey]
+ rankingQueryName := queryNamesForOrderBy[len(queryNamesForOrderBy)-1]
+
+ topReq := &qbtypes.QueryRangeRequest{
+ Start: uint64(req.Start),
+ End: uint64(req.End),
+ RequestType: qbtypes.RequestTypeScalar,
+ CompositeQuery: qbtypes.CompositeQuery{
+ Queries: make([]qbtypes.QueryEnvelope, 0, len(queryNamesForOrderBy)),
+ },
+ }
+
+ for _, envelope := range m.newDaemonSetsTableListQuery().CompositeQuery.Queries {
+ if !slices.Contains(queryNamesForOrderBy, envelope.GetQueryName()) {
+ continue
+ }
+ copied := envelope
+ if copied.Type == qbtypes.QueryTypeBuilder {
+ existingExpr := ""
+ if f := copied.GetFilter(); f != nil {
+ existingExpr = f.Expression
+ }
+ reqFilterExpr := ""
+ if req.Filter != nil {
+ reqFilterExpr = req.Filter.Expression
+ }
+ merged := mergeFilterExpressions(existingExpr, reqFilterExpr)
+ copied.SetFilter(&qbtypes.Filter{Expression: merged})
+ copied.SetGroupBy(req.GroupBy)
+ }
+ topReq.CompositeQuery.Queries = append(topReq.CompositeQuery.Queries, copied)
+ }
+
+ resp, err := m.querier.QueryRange(ctx, orgID, topReq)
+ if err != nil {
+ return nil, err
+ }
+
+ allMetricGroups := parseAndSortGroups(resp, rankingQueryName, req.GroupBy, req.OrderBy.Direction)
+ return paginateWithBackfill(allMetricGroups, metadataMap, req.GroupBy, req.Offset, req.Limit), nil
+}
+
+func (m *module) getDaemonSetsTableMetadata(ctx context.Context, req *inframonitoringtypes.PostableDaemonSets) (map[string]map[string]string, error) {
+ var nonGroupByAttrs []string
+ for _, key := range daemonSetAttrKeysForMetadata {
+ if !isKeyInGroupByAttrs(req.GroupBy, key) {
+ nonGroupByAttrs = append(nonGroupByAttrs, key)
+ }
+ }
+ return m.getMetadata(ctx, daemonSetsTableMetricNamesList, req.GroupBy, nonGroupByAttrs, req.Filter, req.Start, req.End)
+}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/daemonsets_constants.go b/pkg/modules/inframonitoring/implinframonitoring/daemonsets_constants.go
new file mode 100644
index 0000000000..fc3c3c8d2c
--- /dev/null
+++ b/pkg/modules/inframonitoring/implinframonitoring/daemonsets_constants.go
@@ -0,0 +1,237 @@
+package implinframonitoring
+
+import (
+ "github.com/SigNoz/signoz/pkg/types/inframonitoringtypes"
+ "github.com/SigNoz/signoz/pkg/types/metrictypes"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+ "github.com/SigNoz/signoz/pkg/types/telemetrytypes"
+)
+
+const (
+ daemonSetNameAttrKey = "k8s.daemonset.name"
+ daemonSetsBaseFilterExpr = "k8s.daemonset.name != ''"
+)
+
+var daemonSetNameGroupByKey = qbtypes.GroupByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: daemonSetNameAttrKey,
+ FieldContext: telemetrytypes.FieldContextResource,
+ FieldDataType: telemetrytypes.FieldDataTypeString,
+ },
+}
+
+// daemonSetsTableMetricNamesList drives the existence/retention check.
+// Includes k8s.pod.phase even though phase isn't part of the QB composite query —
+// it is queried separately via getPerGroupPodPhaseCounts, and we want the
+// response to short-circuit cleanly when the phase metric is absent.
+var daemonSetsTableMetricNamesList = []string{
+ "k8s.pod.phase",
+ "k8s.pod.cpu.usage",
+ "k8s.pod.cpu_request_utilization",
+ "k8s.pod.cpu_limit_utilization",
+ "k8s.pod.memory.working_set",
+ "k8s.pod.memory_request_utilization",
+ "k8s.pod.memory_limit_utilization",
+ "k8s.daemonset.desired_scheduled_nodes",
+ "k8s.daemonset.current_scheduled_nodes",
+}
+
+// Carried forward from v1 daemonSetAttrsToEnrich
+// (pkg/query-service/app/inframetrics/daemonsets.go:29-33).
+var daemonSetAttrKeysForMetadata = []string{
+ "k8s.daemonset.name",
+ "k8s.namespace.name",
+ "k8s.cluster.name",
+}
+
+// orderByToDaemonSetsQueryNames maps the orderBy column to the query name
+// used for ranking daemonset groups. v2 B/C/E/F are direct metrics, no
+// formula deps — so unlike v1 we don't carry A/D.
+var orderByToDaemonSetsQueryNames = map[string][]string{
+ inframonitoringtypes.DaemonSetsOrderByCPU: {"A"},
+ inframonitoringtypes.DaemonSetsOrderByCPURequest: {"B"},
+ inframonitoringtypes.DaemonSetsOrderByCPULimit: {"C"},
+ inframonitoringtypes.DaemonSetsOrderByMemory: {"D"},
+ inframonitoringtypes.DaemonSetsOrderByMemoryRequest: {"E"},
+ inframonitoringtypes.DaemonSetsOrderByMemoryLimit: {"F"},
+ inframonitoringtypes.DaemonSetsOrderByDesiredNodes: {"H"},
+ inframonitoringtypes.DaemonSetsOrderByCurrentNodes: {"I"},
+}
+
+// newDaemonSetsTableListQuery builds the composite QB v5 request for the daemonsets list.
+// Eight builder queries: A..F roll up pod-level metrics by daemonset, H/I take the
+// latest daemonset-level desired/current scheduled-node counts. Restarts (v1 query G)
+// is intentionally omitted to match the v2 pods/deployments/statefulsets/jobs pattern.
+//
+// Every builder query carries the base filter `daemonSetsBaseFilterExpr`. Reason:
+// pod-level metrics (A..F) are emitted for every pod regardless of whether the
+// pod belongs to a DaemonSet; only DaemonSet-owned pods carry the
+// `k8s.daemonset.name` resource attribute. Without this filter, standalone pods
+// and pods owned by other workloads (Deployment/StatefulSet/Job/...) collapse into
+// a single empty-string group under the default groupBy. v1's GetDaemonSetList
+// applied the same filter via FilterOperatorExists.
+func (m *module) newDaemonSetsTableListQuery() *qbtypes.QueryRangeRequest {
+ queries := []qbtypes.QueryEnvelope{
+ // Query A: k8s.pod.cpu.usage — sum of pod CPU within the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "A",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.cpu.usage",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query B: k8s.pod.cpu_request_utilization — avg across pods in the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "B",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.cpu_request_utilization",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationAvg,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query C: k8s.pod.cpu_limit_utilization — avg across pods in the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "C",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.cpu_limit_utilization",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationAvg,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query D: k8s.pod.memory.working_set — sum of pod memory within the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "D",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.memory.working_set",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query E: k8s.pod.memory_request_utilization — avg across pods in the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "E",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.memory_request_utilization",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationAvg,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query F: k8s.pod.memory_limit_utilization — avg across pods in the group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "F",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.pod.memory_limit_utilization",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationAvg,
+ ReduceTo: qbtypes.ReduceToAvg,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query H: k8s.daemonset.desired_scheduled_nodes — latest known desired node count per group.
+ // v1 used TimeAggregationAnyLast (v3) → mapped to TimeAggregationLatest in v5;
+ // SpaceAggregationSum + ReduceToLast preserve v1's "latest, summed across the group".
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "H",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.daemonset.desired_scheduled_nodes",
+ TimeAggregation: metrictypes.TimeAggregationLatest,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query I: k8s.daemonset.current_scheduled_nodes — latest known currently scheduled node count per group.
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "I",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.daemonset.current_scheduled_nodes",
+ TimeAggregation: metrictypes.TimeAggregationLatest,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{Expression: daemonSetsBaseFilterExpr},
+ GroupBy: []qbtypes.GroupByKey{daemonSetNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ }
+
+ return &qbtypes.QueryRangeRequest{
+ RequestType: qbtypes.RequestTypeScalar,
+ CompositeQuery: qbtypes.CompositeQuery{
+ Queries: queries,
+ },
+ }
+}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/handler.go b/pkg/modules/inframonitoring/implinframonitoring/handler.go
index d6b93df1f9..fbc438d2df 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/handler.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/handler.go
@@ -237,3 +237,27 @@ func (h *handler) ListJobs(rw http.ResponseWriter, req *http.Request) {
render.Success(rw, http.StatusOK, result)
}
+
+func (h *handler) ListDaemonSets(rw http.ResponseWriter, req *http.Request) {
+ claims, err := authtypes.ClaimsFromContext(req.Context())
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ orgID := valuer.MustNewUUID(claims.OrgID)
+
+ var parsedReq inframonitoringtypes.PostableDaemonSets
+ if err := binding.JSON.BindBody(req.Body, &parsedReq); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ result, err := h.module.ListDaemonSets(req.Context(), orgID, &parsedReq)
+ if err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ render.Success(rw, http.StatusOK, result)
+}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/module.go b/pkg/modules/inframonitoring/implinframonitoring/module.go
index 4c1ae0a014..8400dceec3 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/module.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/module.go
@@ -900,3 +900,100 @@ func (m *module) ListJobs(ctx context.Context, orgID valuer.UUID, req *inframoni
return resp, nil
}
+
+func (m *module) ListDaemonSets(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableDaemonSets) (*inframonitoringtypes.DaemonSets, error) {
+ if err := req.Validate(); err != nil {
+ return nil, err
+ }
+
+ resp := &inframonitoringtypes.DaemonSets{}
+
+ if req.OrderBy == nil {
+ req.OrderBy = &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: inframonitoringtypes.DaemonSetsOrderByCPU,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ }
+ }
+
+ if len(req.GroupBy) == 0 {
+ req.GroupBy = []qbtypes.GroupByKey{daemonSetNameGroupByKey}
+ resp.Type = inframonitoringtypes.ResponseTypeList
+ } else {
+ resp.Type = inframonitoringtypes.ResponseTypeGroupedList
+ }
+
+ // Bake the workload base filter into req.Filter so all downstream helpers pick it up.
+ if req.Filter == nil {
+ req.Filter = &qbtypes.Filter{}
+ }
+ req.Filter.Expression = mergeFilterExpressions(daemonSetsBaseFilterExpr, req.Filter.Expression)
+
+ missingMetrics, minFirstReportedUnixMilli, err := m.getMetricsExistenceAndEarliestTime(ctx, daemonSetsTableMetricNamesList)
+ if err != nil {
+ return nil, err
+ }
+ if len(missingMetrics) > 0 {
+ resp.RequiredMetricsCheck = inframonitoringtypes.RequiredMetricsCheck{MissingMetrics: missingMetrics}
+ resp.Records = []inframonitoringtypes.DaemonSetRecord{}
+ resp.Total = 0
+ return resp, nil
+ }
+ if req.End < int64(minFirstReportedUnixMilli) {
+ resp.EndTimeBeforeRetention = true
+ resp.Records = []inframonitoringtypes.DaemonSetRecord{}
+ resp.Total = 0
+ return resp, nil
+ }
+ resp.RequiredMetricsCheck = inframonitoringtypes.RequiredMetricsCheck{MissingMetrics: []string{}}
+
+ metadataMap, err := m.getDaemonSetsTableMetadata(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp.Total = len(metadataMap)
+
+ pageGroups, err := m.getTopDaemonSetGroups(ctx, orgID, req, metadataMap)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(pageGroups) == 0 {
+ resp.Records = []inframonitoringtypes.DaemonSetRecord{}
+ return resp, nil
+ }
+
+ filterExpr := ""
+ if req.Filter != nil {
+ filterExpr = req.Filter.Expression
+ }
+
+ fullQueryReq := buildFullQueryRequest(req.Start, req.End, filterExpr, req.GroupBy, pageGroups, m.newDaemonSetsTableListQuery())
+ queryResp, err := m.querier.QueryRange(ctx, orgID, fullQueryReq)
+ if err != nil {
+ return nil, err
+ }
+
+ // Reuse the pods phase-counts CTE function via a temp struct — it reads only
+ // Start/End/Filter/GroupBy from PostablePods. Pods owned by a DaemonSet carry
+ // k8s.daemonset.name as a resource attribute, so default-groupBy gives
+ // per-daemonset phase counts automatically.
+ phaseCounts, err := m.getPerGroupPodPhaseCounts(ctx, &inframonitoringtypes.PostablePods{
+ Start: req.Start,
+ End: req.End,
+ Filter: req.Filter,
+ GroupBy: req.GroupBy,
+ }, pageGroups)
+ if err != nil {
+ return nil, err
+ }
+
+ resp.Records = buildDaemonSetRecords(queryResp, pageGroups, req.GroupBy, metadataMap, phaseCounts)
+ resp.Warning = queryResp.Warning
+
+ return resp, nil
+}
diff --git a/pkg/modules/inframonitoring/inframonitoring.go b/pkg/modules/inframonitoring/inframonitoring.go
index 74e0151e8d..170711461a 100644
--- a/pkg/modules/inframonitoring/inframonitoring.go
+++ b/pkg/modules/inframonitoring/inframonitoring.go
@@ -18,6 +18,7 @@ type Handler interface {
ListDeployments(http.ResponseWriter, *http.Request)
ListStatefulSets(http.ResponseWriter, *http.Request)
ListJobs(http.ResponseWriter, *http.Request)
+ ListDaemonSets(http.ResponseWriter, *http.Request)
}
type Module interface {
@@ -30,4 +31,5 @@ type Module interface {
ListDeployments(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableDeployments) (*inframonitoringtypes.Deployments, error)
ListStatefulSets(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableStatefulSets) (*inframonitoringtypes.StatefulSets, error)
ListJobs(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableJobs) (*inframonitoringtypes.Jobs, error)
+ ListDaemonSets(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableDaemonSets) (*inframonitoringtypes.DaemonSets, error)
}
diff --git a/pkg/types/inframonitoringtypes/daemonsets.go b/pkg/types/inframonitoringtypes/daemonsets.go
new file mode 100644
index 0000000000..8748aa81f8
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/daemonsets.go
@@ -0,0 +1,105 @@
+package inframonitoringtypes
+
+import (
+ "encoding/json"
+ "slices"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+)
+
+type DaemonSets struct {
+ Type ResponseType `json:"type" required:"true"`
+ Records []DaemonSetRecord `json:"records" required:"true"`
+ Total int `json:"total" required:"true"`
+ RequiredMetricsCheck RequiredMetricsCheck `json:"requiredMetricsCheck" required:"true"`
+ EndTimeBeforeRetention bool `json:"endTimeBeforeRetention" required:"true"`
+ Warning *qbtypes.QueryWarnData `json:"warning,omitempty"`
+}
+
+type DaemonSetRecord struct {
+ DaemonSetName string `json:"daemonSetName" required:"true"`
+ DaemonSetCPU float64 `json:"daemonSetCPU" required:"true"`
+ DaemonSetCPURequest float64 `json:"daemonSetCPURequest" required:"true"`
+ DaemonSetCPULimit float64 `json:"daemonSetCPULimit" required:"true"`
+ DaemonSetMemory float64 `json:"daemonSetMemory" required:"true"`
+ DaemonSetMemoryRequest float64 `json:"daemonSetMemoryRequest" required:"true"`
+ DaemonSetMemoryLimit float64 `json:"daemonSetMemoryLimit" required:"true"`
+ DesiredNodes int `json:"desiredNodes" required:"true"`
+ CurrentNodes int `json:"currentNodes" required:"true"`
+ PodCountsByPhase PodCountsByPhase `json:"podCountsByPhase" required:"true"`
+ Meta map[string]string `json:"meta" required:"true"`
+}
+
+// PostableDaemonSets is the request body for the v2 daemonsets list API.
+type PostableDaemonSets struct {
+ Start int64 `json:"start" required:"true"`
+ End int64 `json:"end" required:"true"`
+ Filter *qbtypes.Filter `json:"filter"`
+ GroupBy []qbtypes.GroupByKey `json:"groupBy"`
+ OrderBy *qbtypes.OrderBy `json:"orderBy"`
+ Offset int `json:"offset"`
+ Limit int `json:"limit" required:"true"`
+}
+
+// Validate ensures PostableDaemonSets contains acceptable values.
+func (req *PostableDaemonSets) Validate() error {
+ if req == nil {
+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "request is nil")
+ }
+
+ if req.Start <= 0 {
+ return errors.NewInvalidInputf(
+ errors.CodeInvalidInput,
+ "invalid start time %d: start must be greater than 0",
+ req.Start,
+ )
+ }
+
+ if req.End <= 0 {
+ return errors.NewInvalidInputf(
+ errors.CodeInvalidInput,
+ "invalid end time %d: end must be greater than 0",
+ req.End,
+ )
+ }
+
+ if req.Start >= req.End {
+ return errors.NewInvalidInputf(
+ errors.CodeInvalidInput,
+ "invalid time range: start (%d) must be less than end (%d)",
+ req.Start,
+ req.End,
+ )
+ }
+
+ if req.Limit < 1 || req.Limit > 5000 {
+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "limit must be between 1 and 5000")
+ }
+
+ if req.Offset < 0 {
+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "offset cannot be negative")
+ }
+
+ if req.OrderBy != nil {
+ if !slices.Contains(DaemonSetsValidOrderByKeys, req.OrderBy.Key.Name) {
+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "invalid order by key: %s", req.OrderBy.Key.Name)
+ }
+ if req.OrderBy.Direction != qbtypes.OrderDirectionAsc && req.OrderBy.Direction != qbtypes.OrderDirectionDesc {
+ return errors.NewInvalidInputf(errors.CodeInvalidInput, "invalid order by direction: %s", req.OrderBy.Direction)
+ }
+ }
+
+ return nil
+}
+
+// UnmarshalJSON validates input immediately after decoding.
+func (req *PostableDaemonSets) UnmarshalJSON(data []byte) error {
+ type raw PostableDaemonSets
+ var decoded raw
+ if err := json.Unmarshal(data, &decoded); err != nil {
+ return err
+ }
+ *req = PostableDaemonSets(decoded)
+ return req.Validate()
+}
diff --git a/pkg/types/inframonitoringtypes/daemonsets_constants.go b/pkg/types/inframonitoringtypes/daemonsets_constants.go
new file mode 100644
index 0000000000..89c5333c4f
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/daemonsets_constants.go
@@ -0,0 +1,23 @@
+package inframonitoringtypes
+
+const (
+ DaemonSetsOrderByCPU = "cpu"
+ DaemonSetsOrderByCPURequest = "cpu_request"
+ DaemonSetsOrderByCPULimit = "cpu_limit"
+ DaemonSetsOrderByMemory = "memory"
+ DaemonSetsOrderByMemoryRequest = "memory_request"
+ DaemonSetsOrderByMemoryLimit = "memory_limit"
+ DaemonSetsOrderByDesiredNodes = "desired_nodes"
+ DaemonSetsOrderByCurrentNodes = "current_nodes"
+)
+
+var DaemonSetsValidOrderByKeys = []string{
+ DaemonSetsOrderByCPU,
+ DaemonSetsOrderByCPURequest,
+ DaemonSetsOrderByCPULimit,
+ DaemonSetsOrderByMemory,
+ DaemonSetsOrderByMemoryRequest,
+ DaemonSetsOrderByMemoryLimit,
+ DaemonSetsOrderByDesiredNodes,
+ DaemonSetsOrderByCurrentNodes,
+}
diff --git a/pkg/types/inframonitoringtypes/daemonsets_test.go b/pkg/types/inframonitoringtypes/daemonsets_test.go
new file mode 100644
index 0000000000..d206d8aa00
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/daemonsets_test.go
@@ -0,0 +1,273 @@
+package inframonitoringtypes
+
+import (
+ "testing"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+ "github.com/SigNoz/signoz/pkg/types/telemetrytypes"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/stretchr/testify/require"
+)
+
+func TestPostableDaemonSets_Validate(t *testing.T) {
+ tests := []struct {
+ name string
+ req *PostableDaemonSets
+ wantErr bool
+ }{
+ {
+ name: "valid request",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: false,
+ },
+ {
+ name: "nil request",
+ req: nil,
+ wantErr: true,
+ },
+ {
+ name: "start time zero",
+ req: &PostableDaemonSets{
+ Start: 0,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time negative",
+ req: &PostableDaemonSets{
+ Start: -1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "end time zero",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 0,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time greater than end time",
+ req: &PostableDaemonSets{
+ Start: 2000,
+ End: 1000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time equal to end time",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 1000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit zero",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 0,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit negative",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: -10,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit exceeds max",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 5001,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "offset negative",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: -5,
+ },
+ wantErr: true,
+ },
+ {
+ name: "orderBy nil is valid",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key cpu and direction asc",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: DaemonSetsOrderByCPU,
+ },
+ },
+ Direction: qbtypes.OrderDirectionAsc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key memory_limit and direction desc",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: DaemonSetsOrderByMemoryLimit,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key desired_nodes and direction desc",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: DaemonSetsOrderByDesiredNodes,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key current_nodes and direction asc",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: DaemonSetsOrderByCurrentNodes,
+ },
+ },
+ Direction: qbtypes.OrderDirectionAsc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with restarts key is rejected",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: "restarts",
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: true,
+ },
+ {
+ name: "orderBy with invalid key",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: "unknown",
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: true,
+ },
+ {
+ name: "orderBy with valid key but invalid direction",
+ req: &PostableDaemonSets{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: DaemonSetsOrderByCPU,
+ },
+ },
+ Direction: qbtypes.OrderDirection{String: valuer.NewString("invalid")},
+ },
+ },
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := tt.req.Validate()
+ if tt.wantErr {
+ require.Error(t, err)
+ require.True(t, errors.Ast(err, errors.TypeInvalidInput), "expected error to be of type InvalidInput")
+ } else {
+ require.NoError(t, err)
+ }
+ })
+ }
+}