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.

4.7 KB
Raw Blame
import type { Meta, StoryObj } from '@storybook/react-vite';
import {
	findSuggestion,
	openKeySuggestions,
	typeFilter,
} from 'components/QueryBuilderV2/QueryV2/QuerySearch/stories/__story_mockdata__/querySearch.play';
import { screen, userEvent } from 'storybook/test';

import { storyMocks } from '@/storybook/controls/defineStoryMocks';
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';

import { metricsMocks, saveUnit } from './MetricsExplorerPage.stories.mocks';
import MetricsExplorerPage from '../MetricsExplorerPage';

type MetricsArgs = PageStoryArgs<typeof metricsMocks>;

const pageStory = storyMocks(metricsMocks, { layout: 'app' });

/**
 * Metrics: the summary treemap, the explorer over `query_range`, the metric drawer
 * with its attributes and related assets, saved views, and the volume control
 * rules.
 *
 * Route: `/metrics-explorer/*`, the tab control picks which.
 */
const meta = {
	title: 'Pages/Metrics/Explorer',
	tags: ['play'],
	component: MetricsExplorerPage,
	...pageStory,
	parameters: { ...pageStory.parameters },
} satisfies Meta<MetricsArgs>;

export default meta;

type Story = StoryObj<MetricsArgs>;

/**
 * The Summary tab on a workspace ingesting a full catalogue of metrics: the
 * proportion view sizing each metric against the others, and the list view
 * below it paging ten metrics at a time with their type, unit and cardinality.
 */
export const Default: Story = {};

/**
 * The metric details drawer, opened from a row: the metric's metadata, the
 * cardinality highlights, the dashboards and alerts it feeds, and its attribute
 * keys with the values seen in the window.
 */
export const MetricDetails: Story = {
	args: { drawer: 'details' },
};

/**
 * The inspect modal, which plots the raw time series behind one gauge before any
 * time or space aggregation is applied.
 */
export const Inspect: Story = {
	args: { drawer: 'inspect' },
};

/**
 * The Volume Control tab: what the workspace ingests against what the reduction
 * rules retain, and the rule per metric that decides it.
 */
export const VolumeControl: Story = {
	args: { tab: 'volume-control' },
};

/**
 * The Explorer tab plotting one metric, with the query builder above the chart
 * and the saved views beside it.
 */
export const Explorer: Story = {
	args: { tab: 'explorer' },
};

/**
 * A fresh workspace: nothing ingested in the window, so the Summary tab drops
 * both views for its onboarding state and nothing is saved or reduced yet.
 */
export const NoMetrics: Story = {
	args: { metrics: 0, treemap: 0, rules: 0, savedViews: 0 },
};

/** The Summary tab mid-query, with the cancel action the toolbar offers. */
export const Loading: Story = {
	args: { dataState: 'loading' },
};

/**
 * The metric details drawer's highlights, all three held open: the exact sample
 * count behind the abbreviated one, what counts as an active time series, and
 * the timestamp the last data point arrived at.
 */
export const Tooltips: Story = {
	args: { tooltipsOpen: true, drawer: 'details' },
};

/**
 * The dashboards pill in the metric details drawer, open: every dashboard that
 * charts this metric, each a link out to it.
 */
export const MetricDetailsDashboardsMenu: Story = {
	args: { drawer: 'details' },
	play: async (): Promise<void> => {
		await userEvent.click(
			await screen.findByTestId(
				'metric-dashboards-popover',
				{},
				{ timeout: 10000 },
			),
		);
		await screen.findByRole('menu');
	},
};

/** The summary's metric search focused: the attributes metrics can be found by. */
export const FilterKeySuggestions: Story = {
	play: async ({ canvasElement }): Promise<void> => {
		await openKeySuggestions(canvasElement, 'k8s.cluster.name');
	},
};

/** The metric search on an attribute and an operator: the values it holds. */
export const FilterValueSuggestions: Story = {
	play: async ({ canvasElement }): Promise<void> => {
		await typeFilter(canvasElement, 'service.name = ');
		await findSuggestion(canvasElement, 'checkout');
	},
};

/**
 * "Set the selected unit as the metric unit?" answered Yes: the toast raised
 * once the metadata write lands. Set Unit save to `error` for the failure.
 */
export const UnitSavedToast: Story = {
	args: { tab: 'explorer', metricUnit: 'unset' },
	play: async ({ canvasElement, args }): Promise<void> => {
		await saveUnit(
			canvasElement,
			args.unitSave === 'success'
				? 'Unit saved successfully'
				: 'Failed to save unit',
		);
	},
};

/** The same save with the metadata write failing. */
export const UnitSaveErrorToast: Story = {
	args: { tab: 'explorer', metricUnit: 'unset', unitSave: 'error' },
	// The deliberate 500 is the state under test.
	parameters: { allowConsoleErrors: true },
	play: async ({ canvasElement }): Promise<void> => {
		await saveUnit(canvasElement, 'Failed to save unit');
	},
};