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 volumes list api (#11137)

Nikhil Mantria913e67acf39
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index 9246e4babe..7488d8f519 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -3013,6 +3013,32 @@ components:
- end
- limit
type: object
+ InframonitoringtypesPostableVolumes:
+ 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
InframonitoringtypesRequiredMetricsCheck:
properties:
missingMetrics:
@@ -3028,6 +3054,67 @@ components:
- list
- grouped_list
type: string
+ InframonitoringtypesVolumeRecord:
+ properties:
+ meta:
+ additionalProperties:
+ type: string
+ nullable: true
+ type: object
+ persistentVolumeClaimName:
+ type: string
+ volumeAvailable:
+ format: double
+ type: number
+ volumeCapacity:
+ format: double
+ type: number
+ volumeInodes:
+ format: double
+ type: number
+ volumeInodesFree:
+ format: double
+ type: number
+ volumeInodesUsed:
+ format: double
+ type: number
+ volumeUsage:
+ format: double
+ type: number
+ required:
+ - persistentVolumeClaimName
+ - volumeAvailable
+ - volumeCapacity
+ - volumeUsage
+ - volumeInodes
+ - volumeInodesFree
+ - volumeInodesUsed
+ - meta
+ type: object
+ InframonitoringtypesVolumes:
+ properties:
+ endTimeBeforeRetention:
+ type: boolean
+ records:
+ items:
+ $ref: '#/components/schemas/InframonitoringtypesVolumeRecord'
+ 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
LlmpricingruletypesGettablePricingRules:
properties:
items:
@@ -12169,6 +12256,77 @@ paths:
summary: List Pods for Infra Monitoring
tags:
- inframonitoring
+ /api/v2/infra_monitoring/pvcs:
+ post:
+ deprecated: false
+ description: 'Returns a paginated list of Kubernetes persistent volume claims
+ (PVCs) with key volume metrics: available bytes, capacity bytes, usage (capacity
+ - available), inodes, free inodes, and used inodes. Each row also includes
+ metadata attributes (k8s.persistentvolumeclaim.name, k8s.pod.uid, k8s.pod.name,
+ k8s.namespace.name, k8s.node.name, k8s.statefulset.name, k8s.cluster.name).
+ Supports filtering via a filter expression, custom groupBy to aggregate volumes
+ by any attribute, ordering by any of the six metrics (available, capacity,
+ usage, inodes, inodes_free, inodes_used), and pagination via offset/limit.
+ The response type is ''list'' for the default k8s.persistentvolumeclaim.name
+ grouping or ''grouped_list'' for custom groupBy keys; in both modes every
+ row aggregates volumes in the group. Also reports missing required metrics
+ and whether the requested time range falls before the data retention boundary.
+ Numeric metric fields (volumeAvailable, volumeCapacity, volumeUsage, volumeInodes,
+ volumeInodesFree, volumeInodesUsed) return -1 as a sentinel when no data is
+ available for that field.'
+ operationId: ListVolumes
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/InframonitoringtypesPostableVolumes'
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ properties:
+ data:
+ $ref: '#/components/schemas/InframonitoringtypesVolumes'
+ 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 Volumes for Infra Monitoring
+ tags:
+ - inframonitoring
/api/v2/livez:
get:
deprecated: false
diff --git a/frontend/src/api/generated/services/inframonitoring/index.ts b/frontend/src/api/generated/services/inframonitoring/index.ts
index 78cc373132..2a4fc5b851 100644
--- a/frontend/src/api/generated/services/inframonitoring/index.ts
+++ b/frontend/src/api/generated/services/inframonitoring/index.ts
@@ -17,11 +17,13 @@ import type {
InframonitoringtypesPostableNamespacesDTO,
InframonitoringtypesPostableNodesDTO,
InframonitoringtypesPostablePodsDTO,
+ InframonitoringtypesPostableVolumesDTO,
ListClusters200,
ListHosts200,
ListNamespaces200,
ListNodes200,
ListPods200,
+ ListVolumes200,
RenderErrorResponseDTO,
} from '../sigNoz.schemas';
@@ -448,3 +450,87 @@ export const useListPods = <
return useMutation(mutationOptions);
};
+/**
+ * Returns a paginated list of Kubernetes persistent volume claims (PVCs) with key volume metrics: available bytes, capacity bytes, usage (capacity - available), inodes, free inodes, and used inodes. Each row also includes metadata attributes (k8s.persistentvolumeclaim.name, k8s.pod.uid, k8s.pod.name, k8s.namespace.name, k8s.node.name, k8s.statefulset.name, k8s.cluster.name). Supports filtering via a filter expression, custom groupBy to aggregate volumes by any attribute, ordering by any of the six metrics (available, capacity, usage, inodes, inodes_free, inodes_used), and pagination via offset/limit. The response type is 'list' for the default k8s.persistentvolumeclaim.name grouping or 'grouped_list' for custom groupBy keys; in both modes every row aggregates volumes in the group. Also reports missing required metrics and whether the requested time range falls before the data retention boundary. Numeric metric fields (volumeAvailable, volumeCapacity, volumeUsage, volumeInodes, volumeInodesFree, volumeInodesUsed) return -1 as a sentinel when no data is available for that field.
+ * @summary List Volumes for Infra Monitoring
+ */
+export const listVolumes = (
+ inframonitoringtypesPostableVolumesDTO: BodyType<InframonitoringtypesPostableVolumesDTO>,
+ signal?: AbortSignal,
+) => {
+ return GeneratedAPIInstance<ListVolumes200>({
+ url: `/api/v2/infra_monitoring/pvcs`,
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ data: inframonitoringtypesPostableVolumesDTO,
+ signal,
+ });
+};
+
+export const getListVolumesMutationOptions = <
+ TError = ErrorType<RenderErrorResponseDTO>,
+ TContext = unknown,
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof listVolumes>>,
+ TError,
+ { data: BodyType<InframonitoringtypesPostableVolumesDTO> },
+ TContext
+ >;
+}): UseMutationOptions<
+ Awaited<ReturnType<typeof listVolumes>>,
+ TError,
+ { data: BodyType<InframonitoringtypesPostableVolumesDTO> },
+ TContext
+> => {
+ const mutationKey = ['listVolumes'];
+ 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 listVolumes>>,
+ { data: BodyType<InframonitoringtypesPostableVolumesDTO> }
+ > = (props) => {
+ const { data } = props ?? {};
+
+ return listVolumes(data);
+ };
+
+ return { mutationFn, ...mutationOptions };
+};
+
+export type ListVolumesMutationResult = NonNullable<
+ Awaited<ReturnType<typeof listVolumes>>
+>;
+export type ListVolumesMutationBody =
+ BodyType<InframonitoringtypesPostableVolumesDTO>;
+export type ListVolumesMutationError = ErrorType<RenderErrorResponseDTO>;
+
+/**
+ * @summary List Volumes for Infra Monitoring
+ */
+export const useListVolumes = <
+ TError = ErrorType<RenderErrorResponseDTO>,
+ TContext = unknown,
+>(options?: {
+ mutation?: UseMutationOptions<
+ Awaited<ReturnType<typeof listVolumes>>,
+ TError,
+ { data: BodyType<InframonitoringtypesPostableVolumesDTO> },
+ TContext
+ >;
+}): UseMutationResult<
+ Awaited<ReturnType<typeof listVolumes>>,
+ TError,
+ { data: BodyType<InframonitoringtypesPostableVolumesDTO> },
+ TContext
+> => {
+ const mutationOptions = getListVolumesMutationOptions(options);
+
+ return useMutation(mutationOptions);
+};
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index 3a90a971a4..41d5c00562 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -5085,6 +5085,34 @@ export interface InframonitoringtypesPostablePodsDTO {
start: number;
}
+export interface InframonitoringtypesPostableVolumesDTO {
+ /**
+ * @type integer
+ * @format int64
+ */
+ end: number;
+ filter?: Querybuildertypesv5FilterDTO;
+ /**
+ * @type array
+ * @nullable true
+ */
+ groupBy?: Querybuildertypesv5GroupByKeyDTO[] | null;
+ /**
+ * @type integer
+ */
+ limit: number;
+ /**
+ * @type integer
+ */
+ offset?: number;
+ orderBy?: Querybuildertypesv5OrderByDTO;
+ /**
+ * @type integer
+ * @format int64
+ */
+ start: number;
+}
+
export interface InframonitoringtypesRequiredMetricsCheckDTO {
/**
* @type array
@@ -5097,6 +5125,74 @@ export enum InframonitoringtypesResponseTypeDTO {
list = 'list',
grouped_list = 'grouped_list',
}
+/**
+ * @nullable
+ */
+export type InframonitoringtypesVolumeRecordDTOMeta = {
+ [key: string]: string;
+} | null;
+
+export interface InframonitoringtypesVolumeRecordDTO {
+ /**
+ * @type object
+ * @nullable true
+ */
+ meta: InframonitoringtypesVolumeRecordDTOMeta;
+ /**
+ * @type string
+ */
+ persistentVolumeClaimName: string;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeAvailable: number;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeCapacity: number;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeInodes: number;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeInodesFree: number;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeInodesUsed: number;
+ /**
+ * @type number
+ * @format double
+ */
+ volumeUsage: number;
+}
+
+export interface InframonitoringtypesVolumesDTO {
+ /**
+ * @type boolean
+ */
+ endTimeBeforeRetention: boolean;
+ /**
+ * @type array
+ * @nullable true
+ */
+ records: InframonitoringtypesVolumeRecordDTO[] | null;
+ requiredMetricsCheck: InframonitoringtypesRequiredMetricsCheckDTO;
+ /**
+ * @type integer
+ */
+ total: number;
+ type: InframonitoringtypesResponseTypeDTO;
+ warning?: Querybuildertypesv5QueryWarnDataDTO;
+}
+
export interface LlmpricingruletypesGettablePricingRulesDTO {
/**
* @type array
@@ -9445,6 +9541,14 @@ export type ListPods200 = {
status: string;
};
+export type ListVolumes200 = {
+ data: InframonitoringtypesVolumesDTO;
+ /**
+ * @type string
+ */
+ status: string;
+};
+
export type Livez200 = {
data: FactoryResponseDTO;
/**
diff --git a/pkg/apiserver/signozapiserver/inframonitoring.go b/pkg/apiserver/signozapiserver/inframonitoring.go
index ed3a444165..17383fd414 100644
--- a/pkg/apiserver/signozapiserver/inframonitoring.go
+++ b/pkg/apiserver/signozapiserver/inframonitoring.go
@@ -105,5 +105,24 @@ func (provider *provider) addInfraMonitoringRoutes(router *mux.Router) error {
return err
}
+ if err := router.Handle("/api/v2/infra_monitoring/pvcs", handler.New(
+ provider.authzMiddleware.ViewAccess(provider.infraMonitoringHandler.ListVolumes),
+ handler.OpenAPIDef{
+ ID: "ListVolumes",
+ Tags: []string{"inframonitoring"},
+ Summary: "List Volumes for Infra Monitoring",
+ Description: "Returns a paginated list of Kubernetes persistent volume claims (PVCs) with key volume metrics: available bytes, capacity bytes, usage (capacity - available), inodes, free inodes, and used inodes. Each row also includes metadata attributes (k8s.persistentvolumeclaim.name, k8s.pod.uid, k8s.pod.name, k8s.namespace.name, k8s.node.name, k8s.statefulset.name, k8s.cluster.name). Supports filtering via a filter expression, custom groupBy to aggregate volumes by any attribute, ordering by any of the six metrics (available, capacity, usage, inodes, inodes_free, inodes_used), and pagination via offset/limit. The response type is 'list' for the default k8s.persistentvolumeclaim.name grouping or 'grouped_list' for custom groupBy keys; in both modes every row aggregates volumes in the group. Also reports missing required metrics and whether the requested time range falls before the data retention boundary. Numeric metric fields (volumeAvailable, volumeCapacity, volumeUsage, volumeInodes, volumeInodesFree, volumeInodesUsed) return -1 as a sentinel when no data is available for that field.",
+ Request: new(inframonitoringtypes.PostableVolumes),
+ RequestContentType: "application/json",
+ Response: new(inframonitoringtypes.Volumes),
+ 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/handler.go b/pkg/modules/inframonitoring/implinframonitoring/handler.go
index c7ea90d150..1eb098909a 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/handler.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/handler.go
@@ -141,3 +141,27 @@ func (h *handler) ListClusters(rw http.ResponseWriter, req *http.Request) {
render.Success(rw, http.StatusOK, result)
}
+
+func (h *handler) ListVolumes(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.PostableVolumes
+ if err := binding.JSON.BindBody(req.Body, &parsedReq); err != nil {
+ render.Error(rw, err)
+ return
+ }
+
+ result, err := h.module.ListVolumes(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 c15469a13a..a50226abab 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/module.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/module.go
@@ -528,3 +528,86 @@ func (m *module) ListClusters(ctx context.Context, orgID valuer.UUID, req *infra
return resp, nil
}
+
+func (m *module) ListVolumes(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableVolumes) (*inframonitoringtypes.Volumes, error) {
+ if err := req.Validate(); err != nil {
+ return nil, err
+ }
+
+ resp := &inframonitoringtypes.Volumes{}
+
+ if req.OrderBy == nil {
+ req.OrderBy = &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: inframonitoringtypes.VolumesOrderByUsage,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ }
+ }
+
+ if len(req.GroupBy) == 0 {
+ req.GroupBy = []qbtypes.GroupByKey{pvcNameGroupByKey}
+ resp.Type = inframonitoringtypes.ResponseTypeList
+ } else {
+ resp.Type = inframonitoringtypes.ResponseTypeGroupedList
+ }
+
+ // Bake the volume base filter into req.Filter so all downstream helpers pick it up.
+ if req.Filter == nil {
+ req.Filter = &qbtypes.Filter{}
+ }
+ req.Filter.Expression = mergeFilterExpressions(volumesBaseFilterExpr, req.Filter.Expression)
+
+ missingMetrics, minFirstReportedUnixMilli, err := m.getMetricsExistenceAndEarliestTime(ctx, volumesTableMetricNamesList)
+ if err != nil {
+ return nil, err
+ }
+ if len(missingMetrics) > 0 {
+ resp.RequiredMetricsCheck = inframonitoringtypes.RequiredMetricsCheck{MissingMetrics: missingMetrics}
+ resp.Records = []inframonitoringtypes.VolumeRecord{}
+ resp.Total = 0
+ return resp, nil
+ }
+ if req.End < int64(minFirstReportedUnixMilli) {
+ resp.EndTimeBeforeRetention = true
+ resp.Records = []inframonitoringtypes.VolumeRecord{}
+ resp.Total = 0
+ return resp, nil
+ }
+ resp.RequiredMetricsCheck = inframonitoringtypes.RequiredMetricsCheck{MissingMetrics: []string{}}
+
+ metadataMap, err := m.getVolumesTableMetadata(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp.Total = len(metadataMap)
+
+ pageGroups, err := m.getTopVolumeGroups(ctx, orgID, req, metadataMap)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(pageGroups) == 0 {
+ resp.Records = []inframonitoringtypes.VolumeRecord{}
+ return resp, nil
+ }
+
+ filterExpr := ""
+ if req.Filter != nil {
+ filterExpr = req.Filter.Expression
+ }
+
+ fullQueryReq := buildFullQueryRequest(req.Start, req.End, filterExpr, req.GroupBy, pageGroups, m.newVolumesTableListQuery())
+ queryResp, err := m.querier.QueryRange(ctx, orgID, fullQueryReq)
+ if err != nil {
+ return nil, err
+ }
+
+ resp.Records = buildVolumeRecords(queryResp, pageGroups, req.GroupBy, metadataMap)
+ resp.Warning = queryResp.Warning
+
+ return resp, nil
+}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/volumes.go b/pkg/modules/inframonitoring/implinframonitoring/volumes.go
new file mode 100644
index 0000000000..6ecdabeeb5
--- /dev/null
+++ b/pkg/modules/inframonitoring/implinframonitoring/volumes.go
@@ -0,0 +1,128 @@
+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"
+)
+
+// buildVolumeRecords assembles the page records. VolumeUsage is taken from the
+// formula query F1 = B - A (matches v1 record.VolumeUsage = capacity - available).
+// No per-row sub-counts (unlike pods/nodes/clusters).
+func buildVolumeRecords(
+ resp *qbtypes.QueryRangeResponse,
+ pageGroups []map[string]string,
+ groupBy []qbtypes.GroupByKey,
+ metadataMap map[string]map[string]string,
+) []inframonitoringtypes.VolumeRecord {
+ metricsMap := parseFullQueryResponse(resp, groupBy)
+
+ records := make([]inframonitoringtypes.VolumeRecord, 0, len(pageGroups))
+ for _, labels := range pageGroups {
+ compositeKey := compositeKeyFromLabels(labels, groupBy)
+ pvcName := labels[persistentVolumeClaimNameAttrKey]
+
+ record := inframonitoringtypes.VolumeRecord{ // initialize with default values
+ PersistentVolumeClaimName: pvcName,
+ VolumeAvailable: -1,
+ VolumeCapacity: -1,
+ VolumeUsage: -1,
+ VolumeInodes: -1,
+ VolumeInodesFree: -1,
+ VolumeInodesUsed: -1,
+ Meta: map[string]string{},
+ }
+
+ if metrics, ok := metricsMap[compositeKey]; ok {
+ if v, exists := metrics["A"]; exists {
+ record.VolumeAvailable = v
+ }
+ if v, exists := metrics["B"]; exists {
+ record.VolumeCapacity = v
+ }
+ if v, exists := metrics["F1"]; exists {
+ record.VolumeUsage = v
+ }
+ if v, exists := metrics["C"]; exists {
+ record.VolumeInodes = v
+ }
+ if v, exists := metrics["D"]; exists {
+ record.VolumeInodesFree = v
+ }
+ if v, exists := metrics["E"]; exists {
+ record.VolumeInodesUsed = v
+ }
+ }
+
+ if attrs, ok := metadataMap[compositeKey]; ok {
+ for k, v := range attrs {
+ record.Meta[k] = v
+ }
+ }
+
+ records = append(records, record)
+ }
+ return records
+}
+
+func (m *module) getTopVolumeGroups(
+ ctx context.Context,
+ orgID valuer.UUID,
+ req *inframonitoringtypes.PostableVolumes,
+ metadataMap map[string]map[string]string,
+) ([]map[string]string, error) {
+ orderByKey := req.OrderBy.Key.Name
+ queryNamesForOrderBy := orderByToVolumesQueryNames[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.newVolumesTableListQuery().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) getVolumesTableMetadata(ctx context.Context, req *inframonitoringtypes.PostableVolumes) (map[string]map[string]string, error) {
+ var nonGroupByAttrs []string
+ for _, key := range volumeAttrKeysForMetadata {
+ if !isKeyInGroupByAttrs(req.GroupBy, key) {
+ nonGroupByAttrs = append(nonGroupByAttrs, key)
+ }
+ }
+ return m.getMetadata(ctx, volumesTableMetricNamesList, req.GroupBy, nonGroupByAttrs, req.Filter, req.Start, req.End)
+}
diff --git a/pkg/modules/inframonitoring/implinframonitoring/volumes_constants.go b/pkg/modules/inframonitoring/implinframonitoring/volumes_constants.go
new file mode 100644
index 0000000000..cfa3f128c3
--- /dev/null
+++ b/pkg/modules/inframonitoring/implinframonitoring/volumes_constants.go
@@ -0,0 +1,192 @@
+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 (
+ persistentVolumeClaimNameAttrKey = "k8s.persistentvolumeclaim.name"
+ volumesBaseFilterExpr = "k8s.persistentvolumeclaim.name != ''"
+)
+
+var pvcNameGroupByKey = qbtypes.GroupByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: persistentVolumeClaimNameAttrKey,
+ FieldContext: telemetrytypes.FieldContextResource,
+ FieldDataType: telemetrytypes.FieldDataTypeString,
+ },
+}
+
+// volumesTableMetricNamesList drives the existence/retention check.
+var volumesTableMetricNamesList = []string{
+ "k8s.volume.available",
+ "k8s.volume.capacity",
+ "k8s.volume.inodes",
+ "k8s.volume.inodes.free",
+ "k8s.volume.inodes.used",
+}
+
+// Carried forward from v1 volumeAttrsToEnrich
+// (pkg/query-service/app/inframetrics/pvcs.go:23-31).
+var volumeAttrKeysForMetadata = []string{
+ "k8s.persistentvolumeclaim.name",
+ "k8s.pod.uid",
+ "k8s.pod.name",
+ "k8s.namespace.name",
+ "k8s.node.name",
+ "k8s.statefulset.name",
+ "k8s.cluster.name",
+}
+
+// orderByToVolumesQueryNames maps the orderBy column to the query/formula names
+// from newVolumesTableListQuery used for ranking volume groups. For "usage",
+// the formula F1 = B - A is the ranking column, with A and B carried as deps
+// (mirrors the hosts pattern in orderByToHostsQueryNames).
+var orderByToVolumesQueryNames = map[string][]string{
+ inframonitoringtypes.VolumesOrderByAvailable: {"A"},
+ inframonitoringtypes.VolumesOrderByCapacity: {"B"},
+ inframonitoringtypes.VolumesOrderByUsage: {"A", "B", "F1"},
+ inframonitoringtypes.VolumesOrderByInodes: {"C"},
+ inframonitoringtypes.VolumesOrderByInodesFree: {"D"},
+ inframonitoringtypes.VolumesOrderByInodesUsed: {"E"},
+}
+
+// newVolumesTableListQuery builds the composite QB v5 request for the volumes list.
+// Five builder queries (A..E) cover the v1 volume metrics; formula F1 = B - A
+// derives usage = capacity - available (mirrors v1's F1 in PvcsTableListQuery).
+// Every builder query carries a base filter `k8s.persistentvolumeclaim.name != ”`.
+// Reason: the kubeletstats receiver emits `k8s.volume.*` metrics for every volume
+// mount on a pod (emptyDir, configMap, secret, projected, hostPath, ...), but
+// only PVC-backed volumes carry the `k8s.persistentvolumeclaim.name` resource
+// attribute (see https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/82f2e8798b42a13f07d733d073147b6eb279e0e1/receiver/kubeletstatsreceiver/internal/kubelet/volume.go#L25).
+// Without this filter, non-PVC volumes pollute the result and collapse into a single empty-string
+// group under the default groupBy. v1's PvcsTableListQuery applied the same filter.
+func (m *module) newVolumesTableListQuery() *qbtypes.QueryRangeRequest {
+ queries := []qbtypes.QueryEnvelope{
+ // Query A: k8s.volume.available
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "A",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.volume.available",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{
+ Expression: volumesBaseFilterExpr,
+ },
+ GroupBy: []qbtypes.GroupByKey{pvcNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query B: k8s.volume.capacity
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "B",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.volume.capacity",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{
+ Expression: volumesBaseFilterExpr,
+ },
+ GroupBy: []qbtypes.GroupByKey{pvcNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Formula F1: Volume Usage (capacity - available)
+ {
+ Type: qbtypes.QueryTypeFormula,
+ Spec: qbtypes.QueryBuilderFormula{
+ Name: "F1",
+ Expression: "B - A",
+ Legend: "Volume Usage",
+ Disabled: false,
+ },
+ },
+ // Query C: k8s.volume.inodes
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "C",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.volume.inodes",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{
+ Expression: volumesBaseFilterExpr,
+ },
+ GroupBy: []qbtypes.GroupByKey{pvcNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query D: k8s.volume.inodes.free
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "D",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.volume.inodes.free",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{
+ Expression: volumesBaseFilterExpr,
+ },
+ GroupBy: []qbtypes.GroupByKey{pvcNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ // Query E: k8s.volume.inodes.used
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "E",
+ Signal: telemetrytypes.SignalMetrics,
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "k8s.volume.inodes.used",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationSum,
+ ReduceTo: qbtypes.ReduceToLast,
+ },
+ },
+ Filter: &qbtypes.Filter{
+ Expression: volumesBaseFilterExpr,
+ },
+ GroupBy: []qbtypes.GroupByKey{pvcNameGroupByKey},
+ Disabled: false,
+ },
+ },
+ }
+
+ return &qbtypes.QueryRangeRequest{
+ RequestType: qbtypes.RequestTypeScalar,
+ CompositeQuery: qbtypes.CompositeQuery{
+ Queries: queries,
+ },
+ }
+}
diff --git a/pkg/modules/inframonitoring/inframonitoring.go b/pkg/modules/inframonitoring/inframonitoring.go
index b2f5fa0023..c20f0f395d 100644
--- a/pkg/modules/inframonitoring/inframonitoring.go
+++ b/pkg/modules/inframonitoring/inframonitoring.go
@@ -14,6 +14,7 @@ type Handler interface {
ListNodes(http.ResponseWriter, *http.Request)
ListNamespaces(http.ResponseWriter, *http.Request)
ListClusters(http.ResponseWriter, *http.Request)
+ ListVolumes(http.ResponseWriter, *http.Request)
}
type Module interface {
@@ -22,4 +23,5 @@ type Module interface {
ListNodes(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableNodes) (*inframonitoringtypes.Nodes, error)
ListNamespaces(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableNamespaces) (*inframonitoringtypes.Namespaces, error)
ListClusters(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableClusters) (*inframonitoringtypes.Clusters, error)
+ ListVolumes(ctx context.Context, orgID valuer.UUID, req *inframonitoringtypes.PostableVolumes) (*inframonitoringtypes.Volumes, error)
}
diff --git a/pkg/types/inframonitoringtypes/volumes.go b/pkg/types/inframonitoringtypes/volumes.go
new file mode 100644
index 0000000000..a99bdc3ef3
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/volumes.go
@@ -0,0 +1,102 @@
+package inframonitoringtypes
+
+import (
+ "encoding/json"
+ "slices"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+)
+
+type Volumes struct {
+ Type ResponseType `json:"type" required:"true"`
+ Records []VolumeRecord `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 VolumeRecord struct {
+ PersistentVolumeClaimName string `json:"persistentVolumeClaimName" required:"true"`
+ VolumeAvailable float64 `json:"volumeAvailable" required:"true"`
+ VolumeCapacity float64 `json:"volumeCapacity" required:"true"`
+ VolumeUsage float64 `json:"volumeUsage" required:"true"`
+ VolumeInodes float64 `json:"volumeInodes" required:"true"`
+ VolumeInodesFree float64 `json:"volumeInodesFree" required:"true"`
+ VolumeInodesUsed float64 `json:"volumeInodesUsed" required:"true"`
+ Meta map[string]string `json:"meta" required:"true"`
+}
+
+// PostableVolumes is the request body for the v2 volumes (PVCs) list API.
+type PostableVolumes 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 PostableVolumes contains acceptable values.
+func (req *PostableVolumes) 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(VolumesValidOrderByKeys, 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 *PostableVolumes) UnmarshalJSON(data []byte) error {
+ type raw PostableVolumes
+ var decoded raw
+ if err := json.Unmarshal(data, &decoded); err != nil {
+ return err
+ }
+ *req = PostableVolumes(decoded)
+ return req.Validate()
+}
diff --git a/pkg/types/inframonitoringtypes/volumes_constants.go b/pkg/types/inframonitoringtypes/volumes_constants.go
new file mode 100644
index 0000000000..f2e465b5c9
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/volumes_constants.go
@@ -0,0 +1,19 @@
+package inframonitoringtypes
+
+const (
+ VolumesOrderByAvailable = "available"
+ VolumesOrderByCapacity = "capacity"
+ VolumesOrderByUsage = "usage"
+ VolumesOrderByInodes = "inodes"
+ VolumesOrderByInodesFree = "inodes_free"
+ VolumesOrderByInodesUsed = "inodes_used"
+)
+
+var VolumesValidOrderByKeys = []string{
+ VolumesOrderByAvailable,
+ VolumesOrderByCapacity,
+ VolumesOrderByUsage,
+ VolumesOrderByInodes,
+ VolumesOrderByInodesFree,
+ VolumesOrderByInodesUsed,
+}
diff --git a/pkg/types/inframonitoringtypes/volumes_test.go b/pkg/types/inframonitoringtypes/volumes_test.go
new file mode 100644
index 0000000000..e38c4eec66
--- /dev/null
+++ b/pkg/types/inframonitoringtypes/volumes_test.go
@@ -0,0 +1,237 @@
+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 TestPostableVolumes_Validate(t *testing.T) {
+ tests := []struct {
+ name string
+ req *PostableVolumes
+ wantErr bool
+ }{
+ {
+ name: "valid request",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: false,
+ },
+ {
+ name: "nil request",
+ req: nil,
+ wantErr: true,
+ },
+ {
+ name: "start time zero",
+ req: &PostableVolumes{
+ Start: 0,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time negative",
+ req: &PostableVolumes{
+ Start: -1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "end time zero",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 0,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time greater than end time",
+ req: &PostableVolumes{
+ Start: 2000,
+ End: 1000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "start time equal to end time",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 1000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit zero",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 0,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit negative",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: -10,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "limit exceeds max",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 5001,
+ Offset: 0,
+ },
+ wantErr: true,
+ },
+ {
+ name: "offset negative",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: -5,
+ },
+ wantErr: true,
+ },
+ {
+ name: "orderBy nil is valid",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key usage and direction desc",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: VolumesOrderByUsage,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key available and direction asc",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: VolumesOrderByAvailable,
+ },
+ },
+ Direction: qbtypes.OrderDirectionAsc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with valid key inodes_free",
+ req: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: VolumesOrderByInodesFree,
+ },
+ },
+ Direction: qbtypes.OrderDirectionDesc,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "orderBy with invalid key",
+ req: &PostableVolumes{
+ 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: &PostableVolumes{
+ Start: 1000,
+ End: 2000,
+ Limit: 100,
+ Offset: 0,
+ OrderBy: &qbtypes.OrderBy{
+ Key: qbtypes.OrderByKey{
+ TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{
+ Name: VolumesOrderByCapacity,
+ },
+ },
+ 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)
+ }
+ })
+ }
+}