SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(infrastructure-monitoring): add pod metrics tab (#12106)
Vinicius Lourençoedee102b5295
diff --git a/frontend/src/container/InfraMonitoringK8sV2/Base/K8sBaseDetails.tsx b/frontend/src/container/InfraMonitoringK8sV2/Base/K8sBaseDetails.tsxindex f0ed216525..4d3ce22432 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Base/K8sBaseDetails.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/Base/K8sBaseDetails.tsx@@ -86,6 +86,23 @@ export interface K8sDetailsFilters {end: number;}+export interface CustomTabRenderProps<T> {+ entity: T;+ timeRange: { startTime: number; endTime: number };+ selectedInterval: Time;+ handleTimeChange: (+ interval: Time | CustomTimeType,+ dateTimeRange?: [number, number],+ ) => void;+}++export interface CustomTab<T> {+ key: string;+ label: string;+ icon: React.ReactNode;+ render: (props: CustomTabRenderProps<T>) => React.ReactNode;+}+export interface K8sBaseDetailsProps<T> {category: InfraMonitoringEntity;eventCategory: string;@@ -122,20 +139,7 @@ export interface K8sBaseDetailsProps<T> {showTraces?: boolean;showEvents?: boolean;};- customTabs?: Array<{- key: string;- label: string;- icon: React.ReactNode;- render: (props: {- entity: T;- timeRange: { startTime: number; endTime: number };- selectedInterval: Time;- handleTimeChange: (- interval: Time | CustomTimeType,- dateTimeRange?: [number, number],- ) => void;- }) => React.ReactNode;- }>;+ customTabs?: Array<CustomTab<T>>;}// eslint-disable-next-line sonarjs/cognitive-complexity@@ -271,6 +275,33 @@ export default function K8sBaseDetails<T>({const [selectedView, setSelectedView] = useInfraMonitoringView();const effectiveView = hideDetailViewTabs ? VIEW_TYPES.METRICS : selectedView;+ const validTabs = useMemo(() => {+ const tabs: string[] = [];+ if (tabVisibility.showMetrics) {+ tabs.push(VIEW_TYPES.METRICS);+ }+ if (tabVisibility.showLogs) {+ tabs.push(VIEW_TYPES.LOGS);+ }+ if (tabVisibility.showTraces) {+ tabs.push(VIEW_TYPES.TRACES);+ }+ if (tabVisibility.showEvents) {+ tabs.push(VIEW_TYPES.EVENTS);+ }+ if (customTabs) {+ tabs.push(...customTabs.map((t) => t.key));+ }+ return tabs;+ }, [tabVisibility, customTabs]);++ useEffect(() => {+ if (!hideDetailViewTabs && !validTabs.includes(selectedView)) {+ const firstValid = validTabs[0] || VIEW_TYPES.METRICS;+ void setSelectedView(firstValid);+ }+ }, [hideDetailViewTabs, selectedView, validTabs, setSelectedView]);+const [, setLogFiltersParam] = useInfraMonitoringLogFilters();const [, setTracesFiltersParam] = useInfraMonitoringTracesFilters();const [, setEventsFiltersParam] = useInfraMonitoringEventsFilters();@@ -306,7 +337,10 @@ export default function K8sBaseDetails<T>({}}, [getMinMaxTime, selectedTime]);- const handleTabChange = (value: string): void => {+ const handleTabChange = (value: string | null): void => {+ if (!value) {+ return;+ }setSelectedView(value);setLogFiltersParam(null);setTracesFiltersParam(null);diff --git a/frontend/src/container/InfraMonitoringK8sV2/Base/__tests__/K8sBaseDetails.tabValidation.test.tsx b/frontend/src/container/InfraMonitoringK8sV2/Base/__tests__/K8sBaseDetails.tabValidation.test.tsxnew file mode 100644index 0000000000..61fcc48f66--- /dev/null+++ b/frontend/src/container/InfraMonitoringK8sV2/Base/__tests__/K8sBaseDetails.tabValidation.test.tsx@@ -0,0 +1,221 @@+import { Box } from '@signozhq/icons';+import { screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import { NuqsTestingAdapter } from 'nuqs/adapters/testing';+import { act, render, waitFor } from 'tests/test-utils';++import {+ InfraMonitoringEntity,+ INFRA_MONITORING_K8S_PARAMS_KEYS,+ VIEW_TYPES,+} from '../../constants';+import K8sBaseDetails from '../K8sBaseDetails';++jest.mock('container/TopNav/DateTimeSelectionV2/index.tsx', () => ({+ __esModule: true,+ default: (): JSX.Element => <div data-testid="mock-datetime" />,+}));++type TestEntity = {+ name: string;+ namespace: string;+ cluster: string;+};++const mockEntity: TestEntity = {+ name: 'test-pod',+ namespace: 'default',+ cluster: 'test-cluster',+};++function createBaseProps() {+ return {+ category: InfraMonitoringEntity.PODS,+ eventCategory: 'Pod',+ getSelectedItemExpression: (): string => 'k8s.pod.name = "test-pod"',+ fetchEntityData: jest+ .fn()+ .mockResolvedValue({ data: mockEntity, error: null }),+ getEntityName: (e: TestEntity): string => e.name,+ getInitialLogTracesExpression: (): string => 'k8s.pod.name = "test-pod"',+ getInitialEventsExpression: (): string => 'k8s.pod.name = "test-pod"',+ metadataConfig: [+ { label: 'Name', getValue: (e: TestEntity): string => e.name },+ ],+ entityWidgetInfo: [{ title: 'CPU', yAxisUnit: 'percent' }],+ getEntityQueryPayload: jest.fn().mockReturnValue([]),+ queryKeyPrefix: 'testPod',+ };+}++interface RenderOptions {+ view?: string;+ tabsConfig?: {+ showMetrics?: boolean;+ showLogs?: boolean;+ showTraces?: boolean;+ showEvents?: boolean;+ };+ customTabs?: Array<{+ key: string;+ label: string;+ icon: React.ReactNode;+ render: () => React.ReactNode;+ }>;+}++function renderK8sBaseDetails({+ view = VIEW_TYPES.METRICS,+ tabsConfig,+ customTabs,+}: RenderOptions = {}) {+ const searchParams: Record<string, string> = {+ [INFRA_MONITORING_K8S_PARAMS_KEYS.SELECTED_ITEM]: 'test-pod',+ [INFRA_MONITORING_K8S_PARAMS_KEYS.VIEW]: view,+ };++ return render(+ <NuqsTestingAdapter searchParams={searchParams}>+ <K8sBaseDetails<TestEntity>+ {...createBaseProps()}+ tabsConfig={tabsConfig}+ customTabs={customTabs}+ />+ </NuqsTestingAdapter>,+ );+}++function getSelectedTabText(): string | null {+ const selectedTab = document.querySelector('[aria-checked="true"]');+ return selectedTab?.textContent ?? null;+}++describe('K8sBaseDetails - Tab Validation', () => {+ it('should reset view to METRICS when selected view is invalid', async () => {+ act(() => {+ renderK8sBaseDetails({ view: 'invalid-tab' });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Metrics');+ });+ });++ it('should reset to first available tab when METRICS is disabled and view is invalid', async () => {+ act(() => {+ renderK8sBaseDetails({+ view: 'invalid-tab',+ tabsConfig: { showMetrics: false },+ });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Logs');+ });+ });++ it('should reset to custom tab when all standard tabs disabled and custom tab exists', async () => {+ const customTabKey = 'pod-metrics';++ act(() => {+ renderK8sBaseDetails({+ view: 'invalid-tab',+ tabsConfig: {+ showMetrics: false,+ showLogs: false,+ showTraces: false,+ showEvents: false,+ },+ customTabs: [+ {+ key: customTabKey,+ label: 'Pod Metrics',+ icon: <Box size={14} />,+ render: (): React.ReactNode => <div>Custom Tab</div>,+ },+ ],+ });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Pod Metrics');+ });+ });++ it('should NOT reset view when selected view is valid', async () => {+ act(() => {+ renderK8sBaseDetails({ view: VIEW_TYPES.LOGS });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Logs');+ });+ });++ it('should NOT reset view when custom tab is selected and exists', async () => {+ const customTabKey = 'pod-metrics';++ act(() => {+ renderK8sBaseDetails({+ view: customTabKey,+ customTabs: [+ {+ key: customTabKey,+ label: 'Pod Metrics',+ icon: <Box size={14} />,+ render: (): React.ReactNode => <div>Custom Tab</div>,+ },+ ],+ });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Pod Metrics');+ });+ });++ it('should keep the selected tab when the active tab is clicked again (untoggle guard)', async () => {+ const user = userEvent.setup();++ act(() => {+ renderK8sBaseDetails({ view: VIEW_TYPES.LOGS });+ });++ await waitFor(() => {+ expect(screen.getAllByText('test-pod').length).toBeGreaterThan(0);+ });++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Logs');+ });++ const selectedTab = document.querySelector('[aria-checked="true"]');+ expect(selectedTab).not.toBeNull();++ await user.click(selectedTab as Element);++ await waitFor(() => {+ expect(getSelectedTabText()).toContain('Logs');+ });+ });+});diff --git a/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/K8sDaemonSetsList.tsx b/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/K8sDaemonSetsList.tsxindex 83930318c5..faf8e7d5cd 100644--- a/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/K8sDaemonSetsList.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/K8sDaemonSetsList.tsx@@ -1,4 +1,4 @@-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';import { listDaemonSets } from 'api/generated/services/inframonitoring';import { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';@@ -10,6 +10,7 @@ import {} from 'api/generated/services/sigNoz.schemas';import { InfraMonitoringEvents } from 'constants/events';import APIError from 'types/api/error';+import K8sBaseDetails, { K8sDetailsFilters } from '../Base/K8sBaseDetails';import { K8sBaseList } from '../Base/K8sBaseList';import { K8sBaseFilters } from '../Base/types';@@ -18,6 +19,7 @@ import { SelectedItemParams } from '../hooks';import {daemonSetWidgetInfo,getDaemonSetMetricsQueryPayload,+ getDaemonSetPodMetricsQueryPayload,k8sDaemonSetDetailsMetadataConfig,k8sDaemonSetGetEntityName,k8sDaemonSetGetSelectedItemExpression,@@ -29,6 +31,8 @@ import {getK8sDaemonSetRowKey,k8sDaemonSetsColumnsConfig,} from './table.config';+import { createPodMetricsTab } from 'container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab';+function K8sDaemonSetsList({controlListPrefix,}: {@@ -112,6 +116,17 @@ function K8sDaemonSetsList({},[],);+ const customTabs = useMemo(+ () => [+ createPodMetricsTab<InframonitoringtypesDaemonSetRecordDTO>({+ getQueryPayload: getDaemonSetPodMetricsQueryPayload,+ category: InfraMonitoringEntity.DAEMONSETS,+ queryKey: 'daemonSetPodMetrics',+ }),+ ],+ [],+ );+return (<><K8sBaseList<InframonitoringtypesDaemonSetRecordDTO, SelectedItemParams>@@ -135,6 +150,7 @@ function K8sDaemonSetsList({entityWidgetInfo={daemonSetWidgetInfo}getEntityQueryPayload={getDaemonSetMetricsQueryPayload}queryKeyPrefix="daemonset"+ customTabs={customTabs}/></>);diff --git a/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/constants.tsindex 5b609bc16f..4e62f56046 100644--- a/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/DaemonSets/constants.ts@@ -7,7 +7,10 @@ import { DataSource, ReduceOperators } from 'types/common/queryBuilder';import { v4 } from 'uuid';import { K8sDetailsMetadataConfig } from '../Base/K8sBaseDetails';-import { INFRA_MONITORING_ATTR_KEYS } from '../constants';+import {+ getPodUtilizationByPodQueryPayloads,+ INFRA_MONITORING_ATTR_KEYS,+} from '../constants';import { SelectedItemParams } from '../hooks';import {buildEventsExpression,@@ -676,3 +679,29 @@ export const getDaemonSetMetricsQueryPayload = (},];};++export const getDaemonSetPodMetricsQueryPayload = (+ daemonSet: InframonitoringtypesDaemonSetRecordDTO,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] => {+ const k8sDaemonSetNameKey = dotMetricsEnabled+ ? 'k8s.daemonset.name'+ : 'k8s_daemonset_name';++ return getPodUtilizationByPodQueryPayloads(+ {+ workloadNameKey: k8sDaemonSetNameKey,+ workloadNameValue:+ daemonSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_DAEMONSET_NAME] ?? '',+ clusterName:+ daemonSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] ?? '',+ namespaceName:+ daemonSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_NAMESPACE_NAME] ?? '',+ },+ start,+ end,+ dotMetricsEnabled,+ );+};diff --git a/frontend/src/container/InfraMonitoringK8sV2/Deployments/K8sDeploymentsList.tsx b/frontend/src/container/InfraMonitoringK8sV2/Deployments/K8sDeploymentsList.tsxindex 2cb9a252a6..62c157b95c 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Deployments/K8sDeploymentsList.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/Deployments/K8sDeploymentsList.tsx@@ -1,4 +1,4 @@-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';import { listDeployments } from 'api/generated/services/inframonitoring';import { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';@@ -19,6 +19,7 @@ import { SelectedItemParams } from '../hooks';import {deploymentWidgetInfo,getDeploymentMetricsQueryPayload,+ getDeploymentPodMetricsQueryPayload,k8sDeploymentDetailsMetadataConfig,k8sDeploymentGetEntityName,k8sDeploymentGetSelectedItemExpression,@@ -30,6 +31,7 @@ import {getK8sDeploymentRowKey,k8sDeploymentsColumnsConfig,} from './table.config';+import { createPodMetricsTab } from 'container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab';function K8sDeploymentsList({controlListPrefix,@@ -118,6 +120,17 @@ function K8sDeploymentsList({[],);+ const customTabs = useMemo(+ () => [+ createPodMetricsTab<InframonitoringtypesDeploymentRecordDTO>({+ getQueryPayload: getDeploymentPodMetricsQueryPayload,+ category: InfraMonitoringEntity.DEPLOYMENTS,+ queryKey: 'deploymentPodMetrics',+ }),+ ],+ [],+ );+return (<><K8sBaseList<InframonitoringtypesDeploymentRecordDTO, SelectedItemParams>@@ -142,6 +155,7 @@ function K8sDeploymentsList({entityWidgetInfo={deploymentWidgetInfo}getEntityQueryPayload={getDeploymentMetricsQueryPayload}queryKeyPrefix="deployment"+ customTabs={customTabs}/></>);diff --git a/frontend/src/container/InfraMonitoringK8sV2/Deployments/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/Deployments/constants.tsindex c30411562c..795b8ecc6e 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Deployments/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/Deployments/constants.ts@@ -7,7 +7,10 @@ import { DataSource, ReduceOperators } from 'types/common/queryBuilder';import { v4 } from 'uuid';import { K8sDetailsMetadataConfig } from '../Base/K8sBaseDetails';-import { INFRA_MONITORING_ATTR_KEYS } from '../constants';+import {+ getPodUtilizationByPodQueryPayloads,+ INFRA_MONITORING_ATTR_KEYS,+} from '../constants';import { SelectedItemParams } from '../hooks';import {buildEventsExpression,@@ -675,3 +678,29 @@ export const getDeploymentMetricsQueryPayload = (},];};++export const getDeploymentPodMetricsQueryPayload = (+ deployment: InframonitoringtypesDeploymentRecordDTO,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] => {+ const k8sDeploymentNameKey = dotMetricsEnabled+ ? 'k8s.deployment.name'+ : 'k8s_deployment_name';++ return getPodUtilizationByPodQueryPayloads(+ {+ workloadNameKey: k8sDeploymentNameKey,+ workloadNameValue:+ deployment.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_DEPLOYMENT_NAME] ?? '',+ clusterName:+ deployment.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] ?? '',+ namespaceName:+ deployment.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_NAMESPACE_NAME] ?? '',+ },+ start,+ end,+ dotMetricsEnabled,+ );+};diff --git a/frontend/src/container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab.tsx b/frontend/src/container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab.tsxnew file mode 100644index 0000000000..6badd3c252--- /dev/null+++ b/frontend/src/container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab.tsx@@ -0,0 +1,47 @@+import { Container } from '@signozhq/icons';+import { GetQueryResultsProps } from 'lib/dashboard/getQueryResults';++import { CustomTab } from '../Base/K8sBaseDetails';+import {+ InfraMonitoringEntity,+ podUtilizationByPodWidgetInfo,+ VIEW_TYPES,+} from '../constants';++import EntityMetrics from './EntityMetrics';++interface CreatePodMetricsTabParams<T> {+ getQueryPayload: (+ entity: T,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+ ) => GetQueryResultsProps[];+ category: InfraMonitoringEntity;+ queryKey: string;+}++export function createPodMetricsTab<T>({+ getQueryPayload,+ category,+ queryKey,+}: CreatePodMetricsTabParams<T>): CustomTab<T> {+ return {+ key: VIEW_TYPES.POD_METRICS,+ label: 'Pod Metrics',+ icon: <Container size={14} />,+ render: ({ entity, timeRange, selectedInterval, handleTimeChange }) => (+ <EntityMetrics+ entity={entity}+ selectedInterval={selectedInterval}+ timeRange={timeRange}+ handleTimeChange={handleTimeChange}+ isModalTimeSelection+ entityWidgetInfo={podUtilizationByPodWidgetInfo}+ getEntityQueryPayload={getQueryPayload}+ category={category}+ queryKey={queryKey}+ />+ ),+ };+}diff --git a/frontend/src/container/InfraMonitoringK8sV2/Jobs/K8sJobsList.tsx b/frontend/src/container/InfraMonitoringK8sV2/Jobs/K8sJobsList.tsxindex 6b1d468de8..4668b93319 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Jobs/K8sJobsList.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/Jobs/K8sJobsList.tsx@@ -1,4 +1,4 @@-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';import { listJobs } from 'api/generated/services/inframonitoring';import { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';@@ -18,6 +18,7 @@ import { InfraMonitoringEntity } from '../constants';import { SelectedItemParams } from '../hooks';import {getJobMetricsQueryPayload,+ getJobPodMetricsQueryPayload,jobWidgetInfo,k8sJobDetailsMetadataConfig,k8sJobGetEntityName,@@ -30,6 +31,7 @@ import {getK8sJobRowKey,k8sJobsColumnsConfig,} from './table.config';+import { createPodMetricsTab } from 'container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab';function K8sJobsList({controlListPrefix,@@ -118,6 +120,17 @@ function K8sJobsList({[],);+ const customTabs = useMemo(+ () => [+ createPodMetricsTab<InframonitoringtypesJobRecordDTO>({+ getQueryPayload: getJobPodMetricsQueryPayload,+ category: InfraMonitoringEntity.JOBS,+ queryKey: 'jobPodMetrics',+ }),+ ],+ [],+ );+return (<><K8sBaseList<InframonitoringtypesJobRecordDTO, SelectedItemParams>@@ -142,6 +155,7 @@ function K8sJobsList({entityWidgetInfo={jobWidgetInfo}getEntityQueryPayload={getJobMetricsQueryPayload}queryKeyPrefix="job"+ customTabs={customTabs}/></>);diff --git a/frontend/src/container/InfraMonitoringK8sV2/Jobs/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/Jobs/constants.tsindex a81bc81595..f79235d44c 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Jobs/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/Jobs/constants.ts@@ -7,7 +7,10 @@ import { DataSource, ReduceOperators } from 'types/common/queryBuilder';import { v4 } from 'uuid';import { K8sDetailsMetadataConfig } from '../Base/K8sBaseDetails';-import { INFRA_MONITORING_ATTR_KEYS } from '../constants';+import {+ getPodUtilizationByPodQueryPayloads,+ INFRA_MONITORING_ATTR_KEYS,+} from '../constants';import { SelectedItemParams } from '../hooks';import {buildEventsExpression,@@ -429,3 +432,25 @@ export const getJobMetricsQueryPayload = (},];};++export const getJobPodMetricsQueryPayload = (+ job: InframonitoringtypesJobRecordDTO,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] => {+ const k8sJobNameKey = dotMetricsEnabled ? 'k8s.job.name' : 'k8s_job_name';++ return getPodUtilizationByPodQueryPayloads(+ {+ workloadNameKey: k8sJobNameKey,+ workloadNameValue: job.jobName ?? '',+ clusterName: job.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] ?? '',+ namespaceName:+ job.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_NAMESPACE_NAME] ?? '',+ },+ start,+ end,+ dotMetricsEnabled,+ );+};diff --git a/frontend/src/container/InfraMonitoringK8sV2/Namespaces/K8sNamespacesList.tsx b/frontend/src/container/InfraMonitoringK8sV2/Namespaces/K8sNamespacesList.tsxindex 05d8c5ba55..ff911eab2b 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Namespaces/K8sNamespacesList.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/Namespaces/K8sNamespacesList.tsx@@ -1,4 +1,4 @@-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';import { listNamespaces } from 'api/generated/services/inframonitoring';import { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';@@ -18,6 +18,7 @@ import { InfraMonitoringEntity } from '../constants';import { SelectedItemParams } from '../hooks';import {getNamespaceMetricsQueryPayload,+ getNamespacePodMetricsQueryPayload,k8sNamespaceDetailsCountsConfig,k8sNamespaceDetailsMetadataConfig,k8sNamespaceGetCountsFilterExpression,@@ -32,6 +33,7 @@ import {getK8sNamespaceRowKey,k8sNamespacesColumnsConfig,} from './table.config';+import { createPodMetricsTab } from 'container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab';function K8sNamespacesList({controlListPrefix,@@ -120,6 +122,17 @@ function K8sNamespacesList({[],);+ const customTabs = useMemo(+ () => [+ createPodMetricsTab<InframonitoringtypesNamespaceRecordDTO>({+ getQueryPayload: getNamespacePodMetricsQueryPayload,+ category: InfraMonitoringEntity.NAMESPACES,+ queryKey: 'namespacePodMetrics',+ }),+ ],+ [],+ );+return (<><K8sBaseList<InframonitoringtypesNamespaceRecordDTO, SelectedItemParams>@@ -146,6 +159,7 @@ function K8sNamespacesList({entityWidgetInfo={namespaceWidgetInfo}getEntityQueryPayload={getNamespaceMetricsQueryPayload}queryKeyPrefix="namespace"+ customTabs={customTabs}/></>);diff --git a/frontend/src/container/InfraMonitoringK8sV2/Namespaces/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/Namespaces/constants.tsindex 740c345f1c..a52a8a4ac1 100644--- a/frontend/src/container/InfraMonitoringK8sV2/Namespaces/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/Namespaces/constants.ts@@ -11,6 +11,7 @@ import {K8sDetailsMetadataConfig,} from '../Base/K8sBaseDetails';import {+ getPodUtilizationByPodQueryPayloads,INFRA_MONITORING_ATTR_KEYS,InfraMonitoringEntity,} from '../constants';@@ -1752,3 +1753,26 @@ export const getNamespaceMetricsQueryPayload = (},];};++export const getNamespacePodMetricsQueryPayload = (+ namespace: InframonitoringtypesNamespaceRecordDTO,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] => {+ const k8sNamespaceNameKey = dotMetricsEnabled+ ? 'k8s.namespace.name'+ : 'k8s_namespace_name';++ return getPodUtilizationByPodQueryPayloads(+ {+ workloadNameKey: k8sNamespaceNameKey,+ workloadNameValue: namespace.namespaceName ?? '',+ clusterName:+ namespace.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] ?? '',+ },+ start,+ end,+ dotMetricsEnabled,+ );+};diff --git a/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/K8sStatefulSetsList.tsx b/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/K8sStatefulSetsList.tsxindex faf6634a09..d8b2a0daa6 100644--- a/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/K8sStatefulSetsList.tsx+++ b/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/K8sStatefulSetsList.tsx@@ -1,4 +1,4 @@-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';import { listStatefulSets } from 'api/generated/services/inframonitoring';import { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';@@ -18,6 +18,7 @@ import { InfraMonitoringEntity } from '../constants';import { SelectedItemParams } from '../hooks';import {getStatefulSetMetricsQueryPayload,+ getStatefulSetPodMetricsQueryPayload,k8sStatefulSetDetailsMetadataConfig,k8sStatefulSetGetEntityName,k8sStatefulSetGetSelectedItemExpression,@@ -30,6 +31,7 @@ import {getK8sStatefulSetRowKey,k8sStatefulSetsColumnsConfig,} from './table.config';+import { createPodMetricsTab } from 'container/InfraMonitoringK8sV2/EntityDetailsUtils/createPodMetricsTab';function K8sStatefulSetsList({controlListPrefix,@@ -118,6 +120,17 @@ function K8sStatefulSetsList({[],);+ const customTabs = useMemo(+ () => [+ createPodMetricsTab<InframonitoringtypesStatefulSetRecordDTO>({+ getQueryPayload: getStatefulSetPodMetricsQueryPayload,+ category: InfraMonitoringEntity.STATEFULSETS,+ queryKey: 'statefulSetPodMetrics',+ }),+ ],+ [],+ );+return (<><K8sBaseList<InframonitoringtypesStatefulSetRecordDTO, SelectedItemParams>@@ -142,6 +155,7 @@ function K8sStatefulSetsList({entityWidgetInfo={statefulSetWidgetInfo}getEntityQueryPayload={getStatefulSetMetricsQueryPayload}queryKeyPrefix="statefulSet"+ customTabs={customTabs}/></>);diff --git a/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/constants.tsindex f0f68783ba..fda20ce99d 100644--- a/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/StatefulSets/constants.ts@@ -7,7 +7,10 @@ import { DataSource, ReduceOperators } from 'types/common/queryBuilder';import { v4 } from 'uuid';import { K8sDetailsMetadataConfig } from '../Base/K8sBaseDetails';-import { INFRA_MONITORING_ATTR_KEYS } from '../constants';+import {+ getPodUtilizationByPodQueryPayloads,+ INFRA_MONITORING_ATTR_KEYS,+} from '../constants';import { SelectedItemParams } from '../hooks';import {buildEventsExpression,@@ -859,3 +862,29 @@ export const getStatefulSetMetricsQueryPayload = (},];};++export const getStatefulSetPodMetricsQueryPayload = (+ statefulSet: InframonitoringtypesStatefulSetRecordDTO,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] => {+ const k8sStatefulSetNameKey = dotMetricsEnabled+ ? INFRA_MONITORING_ATTR_KEYS.K8S_STATEFULSET_NAME+ : 'k8s_statefulset_name';++ return getPodUtilizationByPodQueryPayloads(+ {+ workloadNameKey: k8sStatefulSetNameKey,+ workloadNameValue:+ statefulSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_STATEFULSET_NAME] ?? '',+ clusterName:+ statefulSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] ?? '',+ namespaceName:+ statefulSet.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_NAMESPACE_NAME] ?? '',+ },+ start,+ end,+ dotMetricsEnabled,+ );+};diff --git a/frontend/src/container/InfraMonitoringK8sV2/constants.ts b/frontend/src/container/InfraMonitoringK8sV2/constants.tsindex bb80171466..01c07db8b7 100644--- a/frontend/src/container/InfraMonitoringK8sV2/constants.ts+++ b/frontend/src/container/InfraMonitoringK8sV2/constants.ts@@ -2,8 +2,12 @@ import {FiltersType,IQuickFiltersConfig,} from 'components/QuickFilters/types';+import { PANEL_TYPES } from 'constants/queryBuilder';+import { GetQueryResultsProps } from 'lib/dashboard/getQueryResults';import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';-import { DataSource } from 'types/common/queryBuilder';+import { EQueryType } from 'types/common/dashboard';+import { DataSource, ReduceOperators } from 'types/common/queryBuilder';+import { v4 } from 'uuid';// TODO(backend): Find a way to generate this via openapiexport const INFRA_MONITORING_ATTR_KEYS = {@@ -130,6 +134,7 @@ export enum VIEWS {CONTAINERS = 'containers',PROCESSES = 'processes',EVENTS = 'events',+ POD_METRICS = 'pod_metrics',}export const VIEW_TYPES = {@@ -137,6 +142,7 @@ export const VIEW_TYPES = {LOGS: VIEWS.LOGS,TRACES: VIEWS.TRACES,EVENTS: VIEWS.EVENTS,+ POD_METRICS: VIEWS.POD_METRICS,};export const K8sCategories = {@@ -916,3 +922,261 @@ export const METRIC_NAMESPACE_BY_ENTITY: Record<InfraMonitoringEntity, string> =[InfraMonitoringEntity.JOBS]: 'k8s.',[InfraMonitoringEntity.VOLUMES]: 'k8s.volume.',};++export interface WorkloadFilterContext {+ workloadNameKey: string;+ workloadNameValue: string;+ clusterName: string;+ namespaceName?: string;+}++export const podUtilizationByPodWidgetInfo = [+ {+ title: 'CPU Limit Utilization By Pod Name',+ yAxisUnit: 'percentunit',+ },+ {+ title: 'CPU Request Utilization By Pod Name',+ yAxisUnit: 'percentunit',+ },+ {+ title: 'Memory Limit Utilization By Pod Name',+ yAxisUnit: 'percentunit',+ },+ {+ title: 'Memory Request Utilization By Pod Name',+ yAxisUnit: 'percentunit',+ },+ {+ title: 'FileSystem Usage Percentage By Pod Name',+ yAxisUnit: 'percentunit',+ },+];++export function getPodUtilizationByPodQueryPayloads(+ context: WorkloadFilterContext,+ start: number,+ end: number,+ dotMetricsEnabled: boolean,+): GetQueryResultsProps[] {+ const getKey = (dotKey: string, underscoreKey: string): string =>+ dotMetricsEnabled ? dotKey : underscoreKey;++ const k8sPodCpuLimitUtilKey = getKey(+ 'k8s.pod.cpu_limit_utilization',+ 'k8s_pod_cpu_limit_utilization',+ );+ const k8sPodCpuRequestUtilKey = getKey(+ 'k8s.pod.cpu_request_utilization',+ 'k8s_pod_cpu_request_utilization',+ );+ const k8sPodMemLimitUtilKey = getKey(+ 'k8s.pod.memory_limit_utilization',+ 'k8s_pod_memory_limit_utilization',+ );+ const k8sPodMemRequestUtilKey = getKey(+ 'k8s.pod.memory_request_utilization',+ 'k8s_pod_memory_request_utilization',+ );+ const k8sPodFsUsageKey = getKey(+ 'k8s.pod.filesystem.usage',+ 'k8s_pod_filesystem_usage',+ );+ const k8sPodFsCapacityKey = getKey(+ 'k8s.pod.filesystem.capacity',+ 'k8s_pod_filesystem_capacity',+ );+ const k8sPodNameKey = getKey('k8s.pod.name', 'k8s_pod_name');+ const k8sClusterNameKey = getKey('k8s.cluster.name', 'k8s_cluster_name');+ const k8sNamespaceNameKey = getKey('k8s.namespace.name', 'k8s_namespace_name');++ const baseFilters = [+ {+ id: 'workload',+ key: {+ dataType: DataTypes.String,+ id: `${context.workloadNameKey}--string--tag--false`,+ key: context.workloadNameKey,+ type: 'tag',+ },+ op: '=',+ value: context.workloadNameValue,+ },+ {+ id: 'cluster',+ key: {+ dataType: DataTypes.String,+ id: `${k8sClusterNameKey}--string--tag--false`,+ key: k8sClusterNameKey,+ type: 'tag',+ },+ op: '=',+ value: context.clusterName,+ },+ ...(context.namespaceName+ ? [+ {+ id: 'namespace',+ key: {+ dataType: DataTypes.String,+ id: `${k8sNamespaceNameKey}--string--tag--false`,+ key: k8sNamespaceNameKey,+ type: 'tag',+ },+ op: '=',+ value: context.namespaceName,+ },+ ]+ : []),+ ];++ const podNameGroupBy = [+ {+ dataType: DataTypes.String,+ id: `${k8sPodNameKey}--string--tag--false`,+ key: k8sPodNameKey,+ type: 'tag',+ },+ ];++ const buildSingleMetricQuery = (+ metricKey: string,+ metricId: string,+ ): GetQueryResultsProps => ({+ selectedTime: 'GLOBAL_TIME',+ graphType: PANEL_TYPES.TIME_SERIES,+ query: {+ builder: {+ queryData: [+ {+ aggregateAttribute: {+ dataType: DataTypes.Float64,+ id: metricId,+ key: metricKey,+ type: 'Gauge',+ },+ aggregateOperator: 'avg',+ dataSource: DataSource.METRICS,+ disabled: false,+ expression: 'A',+ filters: {+ items: [...baseFilters],+ op: 'AND',+ },+ functions: [],+ groupBy: podNameGroupBy,+ having: [],+ legend: `{{${k8sPodNameKey}}}`,+ limit: null,+ orderBy: [],+ queryName: 'A',+ reduceTo: ReduceOperators.AVG,+ spaceAggregation: 'sum',+ stepInterval: 60,+ timeAggregation: 'avg',+ },+ ],+ queryFormulas: [],+ queryTraceOperator: [],+ },+ clickhouse_sql: [{ disabled: false, legend: '', name: 'A', query: '' }],+ id: v4(),+ promql: [{ disabled: false, legend: '', name: 'A', query: '' }],+ queryType: EQueryType.QUERY_BUILDER,+ },+ variables: {},+ formatForWeb: false,+ start,+ end,+ });++ const filesystemUsagePercentQuery: GetQueryResultsProps = {+ selectedTime: 'GLOBAL_TIME',+ graphType: PANEL_TYPES.TIME_SERIES,+ query: {+ builder: {+ queryData: [+ {+ aggregateAttribute: {+ dataType: DataTypes.Float64,+ id: 'fs_usage',+ key: k8sPodFsUsageKey,+ type: 'Gauge',+ },+ aggregateOperator: 'avg',+ dataSource: DataSource.METRICS,+ disabled: true,+ expression: 'A',+ filters: {+ items: [...baseFilters],+ op: 'AND',+ },+ functions: [],+ groupBy: podNameGroupBy,+ having: [],+ legend: `{{${k8sPodNameKey}}}`,+ limit: null,+ orderBy: [],+ queryName: 'A',+ reduceTo: ReduceOperators.AVG,+ spaceAggregation: 'sum',+ stepInterval: 60,+ timeAggregation: 'avg',+ },+ {+ aggregateAttribute: {+ dataType: DataTypes.Float64,+ id: 'fs_capacity',+ key: k8sPodFsCapacityKey,+ type: 'Gauge',+ },+ aggregateOperator: 'avg',+ dataSource: DataSource.METRICS,+ disabled: true,+ expression: 'B',+ filters: {+ items: [...baseFilters],+ op: 'AND',+ },+ functions: [],+ groupBy: podNameGroupBy,+ having: [],+ legend: `{{${k8sPodNameKey}}}`,+ limit: null,+ orderBy: [],+ queryName: 'B',+ reduceTo: ReduceOperators.AVG,+ spaceAggregation: 'sum',+ stepInterval: 60,+ timeAggregation: 'avg',+ },+ ],+ queryFormulas: [+ {+ disabled: false,+ expression: 'A/B',+ legend: `{{${k8sPodNameKey}}}`,+ queryName: 'F1',+ },+ ],+ queryTraceOperator: [],+ },+ clickhouse_sql: [{ disabled: false, legend: '', name: 'A', query: '' }],+ id: v4(),+ promql: [{ disabled: false, legend: '', name: 'A', query: '' }],+ queryType: EQueryType.QUERY_BUILDER,+ },+ variables: {},+ formatForWeb: false,+ start,+ end,+ };++ return [+ buildSingleMetricQuery(k8sPodCpuLimitUtilKey, 'cpu_limit_util'),+ buildSingleMetricQuery(k8sPodCpuRequestUtilKey, 'cpu_request_util'),+ buildSingleMetricQuery(k8sPodMemLimitUtilKey, 'mem_limit_util'),+ buildSingleMetricQuery(k8sPodMemRequestUtilKey, 'mem_request_util'),+ filesystemUsagePercentQuery,+ ];+}