The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/trails/MetricSelect/MetricSelectScene.tsx

724 lines
24 KiB

import { css } from '@emotion/css';
import { debounce, isEqual } from 'lodash';
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
import { SyntheticEvent, useReducer } from 'react';
import { AdHocVariableFilter, GrafanaTheme2, RawTimeRange, SelectableValue } from '@grafana/data';
import { config, isFetchError } from '@grafana/runtime';
import {
AdHocFiltersVariable,
PanelBuilders,
SceneComponentProps,
SceneCSSGridItem,
SceneCSSGridLayout,
SceneFlexItem,
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
SceneFlexLayout,
sceneGraph,
SceneObject,
SceneObjectBase,
SceneObjectRef,
SceneObjectState,
SceneObjectStateChangedEvent,
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
SceneObjectUrlSyncConfig,
SceneObjectUrlValues,
SceneObjectWithUrlSync,
SceneTimeRange,
SceneVariableSet,
VariableDependencyConfig,
} from '@grafana/scenes';
Explore metrics: Consolidate filters with the OTel experience (#98371) * sort otel resources to top of adhoc filters * add bool in datatrail * add function to find non promoted otel resources * add additional super filter variable * hide filters var and keep otel filters var hidden * add nonpromoted resources to state, update otel or var filters when super filter is updated * update comments * update plan * Allow deployment environment values from both metrics and target_info * Remove usage of dep env var in getting resources * update code comments for clarity * Remove dep env variable, autoselect dep env in otelmetricvar and allow updating of vals in otelmetricvar * Fix bug that conflicts with local storage useOtelExperience check * expose metadata to show data source is loaded to prevent otel race conditions * remove filtering check on target_info in the itel join query * update plan with extra issues * refactor update and reset functions for otel experience * use non promoted resources as the standardization check * sort the resources in filters var if using otel experience * add test for sorting resources with otelmetricsvar * update tests for otel experience in datatrail.test * update tests for otel utils * update otel api tests * update trail store tests to remove dep env var * run prettier * remove unused imports * add tests, distinguish on start and when the initial otel check is done, update comments * Fix bug when adding multiple otel resources * fix when adding filter from breakdown * add migration for dep env var * update migration function and write tests * prettier * Update dep env migration to handle bookmarks * fix trailstore tests for reintroducing the dep env var * refactor default env function, we only need the value * remove redundant check * move otel functions to utils and update and add tests * prettier * cleanup * fix migration for fromStart * update tests for migration * use join and use push * fix flow with state * Fix flow in update OTel function * update tests for flow fixes * fix toggle OTel bugs * report when dep env has been migrated and delete dep env filters to not migrate it again * Clear out dep env after migration * run prettier * improve non promoted attribute function * remove unused functions * prettier * default otel experience to off * report when otel experience is used * report when otel is turned on and off * report otel filters changed * prettier * keep default otel off, respect the local storage, but if loading with otel vars from url or bookmark we can turn it on * Add new badge * fix metric scene breakdown add filter bug around non promoted labels on a metric that are different than non promoted labels for all metrics * prettier * make i18n-extract * prettier for translations * change button name to "Filter" * Update public/app/features/trails/Breakdown/AddToFiltersGraphAction.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/migrations/otelDeploymentEnvironment.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/api.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/util.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Add more padding for pill where capital letter gets to close to the left border and looks off. * clear up comments --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
import { Alert, Badge, Field, Icon, IconButton, InlineSwitch, Input, Select, Tooltip, useStyles2 } from '@grafana/ui';
import { Trans, t } from 'app/core/internationalization';
import { MetricScene } from '../MetricScene';
import { StatusWrapper } from '../StatusWrapper';
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
import { Node, Parser } from '../groop/parser';
import { getMetricDescription } from '../helpers/MetricDatasourceHelper';
import { reportExploreMetrics } from '../interactions';
import { setOtelExperienceToggleState } from '../services/store';
import {
getVariablesWithMetricConstant,
MetricSelectedEvent,
RefreshMetricsEvent,
VAR_DATASOURCE,
VAR_DATASOURCE_EXPR,
VAR_FILTERS,
} from '../shared';
import { getFilters, getTrailFor, isSceneTimeRangeState } from '../utils';
import { SelectMetricAction } from './SelectMetricAction';
import { getMetricNames } from './api';
import { getPreviewPanelFor } from './previewPanel';
import { sortRelatedMetrics } from './relatedMetrics';
import { createJSRegExpFromSearchTerms, createPromRegExp, deriveSearchTermsFromInput } from './util';
interface MetricPanel {
name: string;
index: number;
itemRef?: SceneObjectRef<SceneCSSGridItem>;
isEmpty?: boolean;
isPanel?: boolean;
loaded?: boolean;
}
export interface MetricSelectSceneState extends SceneObjectState {
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
body: SceneFlexLayout | SceneCSSGridLayout;
rootGroup?: Node;
metricPrefix?: string;
metricNames?: string[];
metricNamesLoading?: boolean;
metricNamesError?: string;
metricNamesWarning?: string;
missingOtelTargets?: boolean;
}
const ROW_PREVIEW_HEIGHT = '175px';
const ROW_CARD_HEIGHT = '64px';
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
const METRIC_PREFIX_ALL = 'all';
const MAX_METRIC_NAMES = 20000;
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
const viewByTooltip =
'View by the metric prefix. A metric prefix is a single word at the beginning of the metric name, relevant to the domain the metric belongs to.';
export class MetricSelectScene extends SceneObjectBase<MetricSelectSceneState> implements SceneObjectWithUrlSync {
private previewCache: Record<string, MetricPanel> = {};
private ignoreNextUpdate = false;
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
private _debounceRefreshMetricNames = debounce(() => this._refreshMetricNames(), 1000);
constructor(state: Partial<MetricSelectSceneState>) {
super({
$variables: state.$variables,
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
metricPrefix: state.metricPrefix ?? METRIC_PREFIX_ALL,
body:
state.body ??
new SceneCSSGridLayout({
children: [],
templateColumns: 'repeat(auto-fill, minmax(450px, 1fr))',
autoRows: ROW_PREVIEW_HEIGHT,
isLazy: true,
}),
...state,
});
this.addActivationHandler(this._onActivate.bind(this));
}
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['metricPrefix'] });
protected _variableDependency = new VariableDependencyConfig(this, {
variableNames: [VAR_DATASOURCE, VAR_FILTERS],
onReferencedVariableValueChanged: () => {
// In all cases, we want to reload the metric names
this._debounceRefreshMetricNames();
},
});
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
getUrlState() {
return { metricPrefix: this.state.metricPrefix };
}
updateFromUrl(values: SceneObjectUrlValues) {
if (typeof values.metricPrefix === 'string') {
if (this.state.metricPrefix !== values.metricPrefix) {
this.setState({ metricPrefix: values.metricPrefix });
}
}
}
private _onActivate() {
if (this.state.body.state.children.length === 0) {
this.buildLayout();
} else {
// Temp hack when going back to select metric scene and variable updates
this.ignoreNextUpdate = true;
}
const trail = getTrailFor(this);
this._subs.add(
trail.subscribeToEvent(MetricSelectedEvent, (event) => {
const { steps, currentStep } = trail.state.history.state;
const prevStep = steps[currentStep].parentIndex;
const previousMetric = steps[prevStep].trailState.metric;
const isRelatedMetricSelector = previousMetric !== undefined;
if (event.payload !== undefined) {
const metricSearch = getMetricSearch(trail);
const searchTermCount = deriveSearchTermsFromInput(metricSearch).length;
reportExploreMetrics('metric_selected', {
from: isRelatedMetricSelector ? 'related_metrics' : 'metric_list',
searchTermCount,
});
}
})
);
this._subs.add(
trail.subscribeToEvent(SceneObjectStateChangedEvent, (evt) => {
if (evt.payload.changedObject instanceof SceneTimeRange) {
const { prevState, newState } = evt.payload;
if (isSceneTimeRangeState(prevState) && isSceneTimeRangeState(newState)) {
if (prevState.from === newState.from && prevState.to === newState.to) {
return;
}
}
}
})
);
this._subs.add(
trail.subscribeToState(({ metricSearch }, oldState) => {
const oldSearchTerms = deriveSearchTermsFromInput(oldState.metricSearch);
const newSearchTerms = deriveSearchTermsFromInput(metricSearch);
if (!isEqual(oldSearchTerms, newSearchTerms)) {
this._debounceRefreshMetricNames();
}
})
);
this.subscribeToState((newState, prevState) => {
if (newState.metricNames !== prevState.metricNames) {
this.onMetricNamesChanged();
}
});
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
this._subs.add(
trail.subscribeToState(({ otelTargets }, oldState) => {
// if the otel targets have changed, get the new list of metrics
if (
otelTargets?.instances !== oldState.otelTargets?.instances &&
otelTargets?.jobs !== oldState.otelTargets?.jobs
) {
this._debounceRefreshMetricNames();
}
})
);
this._subs.add(
trail.subscribeToState(() => {
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
// users will most likely not switch this off but for now,
// update metric names when changing useOtelExperience
this._debounceRefreshMetricNames();
})
);
this._subs.add(
trail.subscribeToState(() => {
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
// move showPreviews into the settings
// build layout when toggled
this.buildLayout();
})
);
if (config.featureToggles.enableScopesInMetricsExplore) {
this._subs.add(
trail.subscribeToEvent(RefreshMetricsEvent, () => {
this._debounceRefreshMetricNames();
})
);
}
this._debounceRefreshMetricNames();
}
private async _refreshMetricNames() {
const trail = getTrailFor(this);
const timeRange: RawTimeRange | undefined = trail.state.$timeRange?.state;
if (!timeRange) {
return;
}
const filters: AdHocVariableFilter[] = [];
const filtersVar = sceneGraph.lookupVariable(VAR_FILTERS, this);
const adhocFilters = filtersVar instanceof AdHocFiltersVariable ? (filtersVar?.state.filters ?? []) : [];
if (adhocFilters.length > 0) {
filters.push(...adhocFilters);
}
const metricSearchRegex = createPromRegExp(trail.state.metricSearch);
if (metricSearchRegex) {
filters.push({
key: '__name__',
operator: '=~',
value: metricSearchRegex,
});
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
}
const datasourceUid = sceneGraph.interpolate(trail, VAR_DATASOURCE_EXPR);
this.setState({ metricNamesLoading: true, metricNamesError: undefined, metricNamesWarning: undefined });
try {
const jobsList = trail.state.useOtelExperience ? (trail.state.otelTargets?.jobs ?? []) : [];
const instancesList = trail.state.useOtelExperience ? (trail.state.otelTargets?.instances ?? []) : [];
const response = await getMetricNames(
datasourceUid,
timeRange,
sceneGraph.getScopesBridge(this)?.getValue() ?? [],
filters,
jobsList,
instancesList,
MAX_METRIC_NAMES
);
const searchRegex = createJSRegExpFromSearchTerms(getMetricSearch(this));
let metricNames = searchRegex
? response.data.filter((metric) => !searchRegex || searchRegex.test(metric))
: response.data;
// use this to generate groups for metric prefix
const filteredMetricNames = metricNames;
// filter the remaining metrics with the metric prefix
const metricPrefix = this.state.metricPrefix;
if (metricPrefix && metricPrefix !== 'all') {
const prefixRegex = new RegExp(`(^${metricPrefix}.*)`, 'igy');
metricNames = metricNames.filter((metric) => !prefixRegex || prefixRegex.test(metric));
}
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
let metricNamesWarning = response.limitReached
? `This feature will only return up to ${MAX_METRIC_NAMES} metric names for performance reasons. ` +
`This limit is being exceeded for the current data source. ` +
`Add search terms or label filters to narrow down the number of metric names returned.`
: undefined;
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
// if there are no otel targets for otel resources, there will be no labels
if (trail.state.useOtelExperience && (jobsList.length === 0 || instancesList.length === 0)) {
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
metricNames = [];
metricNamesWarning = undefined;
}
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
let bodyLayout = this.state.body;
// generate groups based on the search metrics input
let rootGroupNode = await this.generateGroups(filteredMetricNames);
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
this.setState({
metricNames,
rootGroup: rootGroupNode,
body: bodyLayout,
metricNamesLoading: false,
metricNamesWarning,
metricNamesError: response.error,
missingOtelTargets: response.missingOtelTargets,
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
});
} catch (err: unknown) {
let error = 'Unknown error';
if (isFetchError(err)) {
if (err.cancelled) {
error = 'Request cancelled';
} else if (err.statusText) {
error = err.statusText;
}
}
this.setState({ metricNames: undefined, metricNamesLoading: false, metricNamesError: error });
}
}
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
private async generateGroups(metricNames: string[] = []) {
const groopParser = new Parser();
groopParser.config = {
...groopParser.config,
maxDepth: 2,
minGroupSize: 2,
miscGroupKey: 'misc',
};
const { root: rootGroupNode } = groopParser.parse(metricNames);
return rootGroupNode;
}
private onMetricNamesChanged() {
const metricNames = this.state.metricNames || [];
const nameSet = new Set(metricNames);
Object.values(this.previewCache).forEach((panel) => {
if (!nameSet.has(panel.name)) {
panel.isEmpty = true;
}
});
const trail = getTrailFor(this);
const sortedMetricNames =
trail.state.metric !== undefined ? sortRelatedMetrics(metricNames, trail.state.metric) : metricNames;
const metricsMap: Record<string, MetricPanel> = {};
const metricsLimit = 120;
// Clear absent metrics from cache
Object.keys(this.previewCache).forEach((metric) => {
if (!nameSet.has(metric)) {
delete this.previewCache[metric];
}
});
for (let index = 0; index < sortedMetricNames.length; index++) {
const metricName = sortedMetricNames[index];
if (Object.keys(metricsMap).length > metricsLimit) {
break;
}
const oldPanel = this.previewCache[metricName];
metricsMap[metricName] = oldPanel || { name: metricName, index, loaded: false };
}
try {
// If there is a current metric, do not present it
const currentMetric = sceneGraph.getAncestor(this, MetricScene).state.metric;
delete metricsMap[currentMetric];
} catch (err) {
// There is no current metric
}
this.previewCache = metricsMap;
this.buildLayout();
}
private sortedPreviewMetrics() {
return Object.values(this.previewCache).sort((a, b) => {
if (a.isEmpty && b.isEmpty) {
return a.index - b.index;
}
if (a.isEmpty) {
return 1;
}
if (b.isEmpty) {
return -1;
}
return a.index - b.index;
});
}
private async buildLayout() {
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
const trail = getTrailFor(this);
const showPreviews = trail.state.showPreviews;
// Temp hack when going back to select metric scene and variable updates
if (this.ignoreNextUpdate) {
this.ignoreNextUpdate = false;
return;
}
const children: SceneFlexItem[] = [];
const metricsList = this.sortedPreviewMetrics();
// Get the current filters to determine the count of them
// Which is required for `getPreviewPanelFor`
const filters = getFilters(this);
const currentFilterCount = filters?.length || 0;
for (let index = 0; index < metricsList.length; index++) {
const metric = metricsList[index];
const metadata = await trail.getMetricMetadata(metric.name);
const description = getMetricDescription(metadata);
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
if (showPreviews) {
if (metric.itemRef && metric.isPanel) {
children.push(metric.itemRef.resolve());
continue;
}
Explore metrics: Support native histograms (#98894) * identify native histograms by classic histograms * use trail to expose ds helper * identify native histograms for preview panel * refactor ds helper to initialize all native histograms * remove await * add info message for native histograms * hide button on show examples * show nh in metric scene by passing check for nh and storing in url for url loads, bookmarks and recent explorations * add badge for native histograms * click native histogram examples in info message to see them * add link for learn more * close banner on select when selecting native histogram in info banner * show message for newly selected data sources * capitalize Native Histogram badge * prettier * fix badge ui width * add padding for badge * add images, styling and tests for native histogram banner * move images to img folder * fix store tests * run i18n * fix betterer * fix betterer with translations * cannot translate interpolated metric in button text * Fix import * do not indent the > See examples section * trans component interferes with text with special chars * update sm text with 4px padding and 16px spacing between images * do not show banner after closing then changing data sources * prettier * Update public/app/features/trails/helpers/MetricDatasourceHelper.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/banners/NativeHistogramBanner.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/banners/NativeHistogramBanner.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * update comments * remove unnecessary code check * add rudderstack types * add close example functionality * prettier * add t() for betterer * prettier * fix betterer and trans issues * fix test --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
// refactor this into the query generator in future
const isNative = trail.isNativeHistogram(metric.name);
const panel = getPreviewPanelFor(metric.name, index, currentFilterCount, description, isNative, true);
metric.itemRef = panel.getRef();
metric.isPanel = true;
children.push(panel);
} else {
const panel = new SceneCSSGridItem({
$variables: new SceneVariableSet({
variables: getVariablesWithMetricConstant(metric.name),
}),
body: getCardPanelFor(metric.name, description),
});
metric.itemRef = panel.getRef();
metric.isPanel = false;
children.push(panel);
}
}
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
const rowTemplate = showPreviews ? ROW_PREVIEW_HEIGHT : ROW_CARD_HEIGHT;
this.state.body.setState({ children, autoRows: rowTemplate });
}
public updateMetricPanel = (metric: string, isLoaded?: boolean, isEmpty?: boolean) => {
const metricPanel = this.previewCache[metric];
if (metricPanel) {
metricPanel.isEmpty = isEmpty;
metricPanel.loaded = isLoaded;
this.previewCache[metric] = metricPanel;
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
if (this.state.metricPrefix === 'All') {
this.buildLayout();
}
}
};
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
public onSearchQueryChange = (evt: SyntheticEvent<HTMLInputElement>) => {
const metricSearch = evt.currentTarget.value;
const trail = getTrailFor(this);
// Update the variable
trail.setState({ metricSearch });
};
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
public onPrefixFilterChange = (val: SelectableValue) => {
this.setState({ metricPrefix: val.value });
this._refreshMetricNames();
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
};
public reportPrefixFilterInteraction = (isMenuOpen: boolean) => {
const trail = getTrailFor(this);
const { steps, currentStep } = trail.state.history.state;
const previousMetric = steps[currentStep]?.trailState.metric;
const isRelatedMetricSelector = previousMetric !== undefined;
reportExploreMetrics('prefix_filter_clicked', {
from: isRelatedMetricSelector ? 'related_metrics' : 'metric_list',
action: isMenuOpen ? 'open' : 'close',
});
};
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
public onToggleOtelExperience = () => {
const trail = getTrailFor(this);
const useOtelExperience = trail.state.useOtelExperience;
Explore metrics: Consolidate filters with the OTel experience (#98371) * sort otel resources to top of adhoc filters * add bool in datatrail * add function to find non promoted otel resources * add additional super filter variable * hide filters var and keep otel filters var hidden * add nonpromoted resources to state, update otel or var filters when super filter is updated * update comments * update plan * Allow deployment environment values from both metrics and target_info * Remove usage of dep env var in getting resources * update code comments for clarity * Remove dep env variable, autoselect dep env in otelmetricvar and allow updating of vals in otelmetricvar * Fix bug that conflicts with local storage useOtelExperience check * expose metadata to show data source is loaded to prevent otel race conditions * remove filtering check on target_info in the itel join query * update plan with extra issues * refactor update and reset functions for otel experience * use non promoted resources as the standardization check * sort the resources in filters var if using otel experience * add test for sorting resources with otelmetricsvar * update tests for otel experience in datatrail.test * update tests for otel utils * update otel api tests * update trail store tests to remove dep env var * run prettier * remove unused imports * add tests, distinguish on start and when the initial otel check is done, update comments * Fix bug when adding multiple otel resources * fix when adding filter from breakdown * add migration for dep env var * update migration function and write tests * prettier * Update dep env migration to handle bookmarks * fix trailstore tests for reintroducing the dep env var * refactor default env function, we only need the value * remove redundant check * move otel functions to utils and update and add tests * prettier * cleanup * fix migration for fromStart * update tests for migration * use join and use push * fix flow with state * Fix flow in update OTel function * update tests for flow fixes * fix toggle OTel bugs * report when dep env has been migrated and delete dep env filters to not migrate it again * Clear out dep env after migration * run prettier * improve non promoted attribute function * remove unused functions * prettier * default otel experience to off * report when otel experience is used * report when otel is turned on and off * report otel filters changed * prettier * keep default otel off, respect the local storage, but if loading with otel vars from url or bookmark we can turn it on * Add new badge * fix metric scene breakdown add filter bug around non promoted labels on a metric that are different than non promoted labels for all metrics * prettier * make i18n-extract * prettier for translations * change button name to "Filter" * Update public/app/features/trails/Breakdown/AddToFiltersGraphAction.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/migrations/otelDeploymentEnvironment.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/api.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/util.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Add more padding for pill where capital letter gets to close to the left border and looks off. * clear up comments --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
// set the startButtonClicked to null as we have gone past the owrkflow this is needed for
let startButtonClicked = false;
let resettingOtel = true;
if (useOtelExperience) {
reportExploreMetrics('otel_experience_toggled', { value: 'off' });
// if turning off OTel
resettingOtel = false;
trail.resetOtelExperience();
} else {
reportExploreMetrics('otel_experience_toggled', { value: 'on' });
}
setOtelExperienceToggleState(!useOtelExperience);
Explore metrics: Consolidate filters with the OTel experience (#98371) * sort otel resources to top of adhoc filters * add bool in datatrail * add function to find non promoted otel resources * add additional super filter variable * hide filters var and keep otel filters var hidden * add nonpromoted resources to state, update otel or var filters when super filter is updated * update comments * update plan * Allow deployment environment values from both metrics and target_info * Remove usage of dep env var in getting resources * update code comments for clarity * Remove dep env variable, autoselect dep env in otelmetricvar and allow updating of vals in otelmetricvar * Fix bug that conflicts with local storage useOtelExperience check * expose metadata to show data source is loaded to prevent otel race conditions * remove filtering check on target_info in the itel join query * update plan with extra issues * refactor update and reset functions for otel experience * use non promoted resources as the standardization check * sort the resources in filters var if using otel experience * add test for sorting resources with otelmetricsvar * update tests for otel experience in datatrail.test * update tests for otel utils * update otel api tests * update trail store tests to remove dep env var * run prettier * remove unused imports * add tests, distinguish on start and when the initial otel check is done, update comments * Fix bug when adding multiple otel resources * fix when adding filter from breakdown * add migration for dep env var * update migration function and write tests * prettier * Update dep env migration to handle bookmarks * fix trailstore tests for reintroducing the dep env var * refactor default env function, we only need the value * remove redundant check * move otel functions to utils and update and add tests * prettier * cleanup * fix migration for fromStart * update tests for migration * use join and use push * fix flow with state * Fix flow in update OTel function * update tests for flow fixes * fix toggle OTel bugs * report when dep env has been migrated and delete dep env filters to not migrate it again * Clear out dep env after migration * run prettier * improve non promoted attribute function * remove unused functions * prettier * default otel experience to off * report when otel experience is used * report when otel is turned on and off * report otel filters changed * prettier * keep default otel off, respect the local storage, but if loading with otel vars from url or bookmark we can turn it on * Add new badge * fix metric scene breakdown add filter bug around non promoted labels on a metric that are different than non promoted labels for all metrics * prettier * make i18n-extract * prettier for translations * change button name to "Filter" * Update public/app/features/trails/Breakdown/AddToFiltersGraphAction.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/migrations/otelDeploymentEnvironment.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/api.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/util.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Add more padding for pill where capital letter gets to close to the left border and looks off. * clear up comments --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
trail.setState({ useOtelExperience: !useOtelExperience, resettingOtel, startButtonClicked });
};
public static Component = ({ model }: SceneComponentProps<MetricSelectScene>) => {
const {
body,
metricNames,
metricNamesError,
metricNamesLoading,
metricNamesWarning,
rootGroup,
metricPrefix,
missingOtelTargets,
} = model.useState();
const { children } = body.useState();
const trail = getTrailFor(model);
const styles = useStyles2(getStyles);
const [warningDismissed, dismissWarning] = useReducer(() => true, false);
const { metricSearch, useOtelExperience, hasOtelResources, isStandardOtel, metric } = trail.useState();
const tooStrict = children.length === 0 && metricSearch;
const noMetrics = !metricNamesLoading && metricNames && metricNames.length === 0;
const isLoading = metricNamesLoading && children.length === 0;
const unableToRetrieveMetricNames = t(
'trails.metric-select-scene.unable-to-retrieve-metric-names',
'Unable to retrieve metric names'
);
const blockingMessage = isLoading
? undefined
: missingOtelTargets
? 'There are no metrics found. Please adjust your filters based on your OTel resource attributes.'
: (noMetrics && 'There are no results found. Try a different time range or a different data source.') ||
(tooStrict && 'There are no results found. Try adjusting your search or filters.') ||
undefined;
const metricNamesWarningIcon = metricNamesWarning ? (
<Tooltip
content={
<>
<h4>{unableToRetrieveMetricNames}</h4>
<p>{metricNamesWarning}</p>
</>
}
>
<Icon className={styles.warningIcon} name="exclamation-triangle" />
</Tooltip>
) : undefined;
return (
<div className={styles.container}>
<div className={styles.header}>
<Field
label={t('trails.metric-select-scene.label-search-metrics', 'Search metrics')}
className={styles.searchField}
>
<Input
placeholder={t('trails.metric-select-scene.placeholder-search-metrics', 'Search metrics')}
prefix={<Icon name={'search'} />}
value={metricSearch}
onChange={model.onSearchQueryChange}
suffix={metricNamesWarningIcon}
/>
</Field>
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
<Field
label={
<div className={styles.displayOptionTooltip}>
<Trans i18nKey="explore-metrics.viewBy">View by</Trans>
<IconButton name={'info-circle'} size="sm" variant={'secondary'} tooltip={viewByTooltip} />
</div>
}
className={styles.displayOption}
>
<Select
value={metricPrefix}
onChange={model.onPrefixFilterChange}
onOpenMenu={() => model.reportPrefixFilterInteraction(true)}
onCloseMenu={() => model.reportPrefixFilterInteraction(false)}
options={[
{
label: 'All metric names',
value: METRIC_PREFIX_ALL,
},
...Array.from(rootGroup?.groups.keys() ?? []).map((g) => ({ label: `${g}_`, value: g })),
]}
className="metrics-drilldown-metric-prefix-select"
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
/>
</Field>
{!metric && hasOtelResources && (
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
<Field
label={
Explore metrics: Consolidate filters with the OTel experience (#98371) * sort otel resources to top of adhoc filters * add bool in datatrail * add function to find non promoted otel resources * add additional super filter variable * hide filters var and keep otel filters var hidden * add nonpromoted resources to state, update otel or var filters when super filter is updated * update comments * update plan * Allow deployment environment values from both metrics and target_info * Remove usage of dep env var in getting resources * update code comments for clarity * Remove dep env variable, autoselect dep env in otelmetricvar and allow updating of vals in otelmetricvar * Fix bug that conflicts with local storage useOtelExperience check * expose metadata to show data source is loaded to prevent otel race conditions * remove filtering check on target_info in the itel join query * update plan with extra issues * refactor update and reset functions for otel experience * use non promoted resources as the standardization check * sort the resources in filters var if using otel experience * add test for sorting resources with otelmetricsvar * update tests for otel experience in datatrail.test * update tests for otel utils * update otel api tests * update trail store tests to remove dep env var * run prettier * remove unused imports * add tests, distinguish on start and when the initial otel check is done, update comments * Fix bug when adding multiple otel resources * fix when adding filter from breakdown * add migration for dep env var * update migration function and write tests * prettier * Update dep env migration to handle bookmarks * fix trailstore tests for reintroducing the dep env var * refactor default env function, we only need the value * remove redundant check * move otel functions to utils and update and add tests * prettier * cleanup * fix migration for fromStart * update tests for migration * use join and use push * fix flow with state * Fix flow in update OTel function * update tests for flow fixes * fix toggle OTel bugs * report when dep env has been migrated and delete dep env filters to not migrate it again * Clear out dep env after migration * run prettier * improve non promoted attribute function * remove unused functions * prettier * default otel experience to off * report when otel experience is used * report when otel is turned on and off * report otel filters changed * prettier * keep default otel off, respect the local storage, but if loading with otel vars from url or bookmark we can turn it on * Add new badge * fix metric scene breakdown add filter bug around non promoted labels on a metric that are different than non promoted labels for all metrics * prettier * make i18n-extract * prettier for translations * change button name to "Filter" * Update public/app/features/trails/Breakdown/AddToFiltersGraphAction.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/migrations/otelDeploymentEnvironment.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/api.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/util.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Add more padding for pill where capital letter gets to close to the left border and looks off. * clear up comments --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
<>
<div className={styles.displayOptionTooltip}>
<Trans i18nKey="trails.metric-select.filter-by">Filter by</Trans>
<IconButton
name={'info-circle'}
size="sm"
variant={'secondary'}
tooltip={
<Trans i18nKey="trails.metric-select.otel-switch">
This switch enables filtering by OTel resources for OTel native data sources.
</Trans>
}
/>
<div>
<Badge
text={<Trans i18nKey="trails.metric-select.new-badge">New</Trans>}
color={'blue'}
className={styles.badgeStyle}
></Badge>
</div>
</div>
</>
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
}
className={styles.displayOption}
>
<div
title={
!isStandardOtel ? 'This setting is disabled because this is not an OTel native data source.' : ''
}
>
<InlineSwitch
disabled={!isStandardOtel}
showLabel={true}
label={t('trails.metric-select-scene.label-otel-experience', 'OTel experience')}
Explore Metrics: Get OTel resources and filter metrics and labels (#91221) * add OTel filter in metric select scene * add resource query to get matching OTEL job&instance * filter metrics by OTEL resources * only add otel select if DS has OTEL matching job and instance * add folder for otel resources * upate metric select for new otel folder * move otel api call * get otel resources for labels for single series job/instance target_info * add otel resources to adhoc variable dropdown * update otel api to check for standardization and return labels * label types for api * check standardization, show otel variable, select depenv, update other variables * remove otel target list from metric select scene * load resources if dep_env label has already been selected * exclude previously used filters * do not check standardization if there are already otel filters * drop filters when switching data sources * add experience var for switching to otel experience * remove otel from variables and place near settings * add error for non-standard prom with otel resources * fix typescript errors, remove ts-ignores * add custom variable for deployment environment like app-olly * fix name of otel variable * add function for getting otel resources from variables * add otel join query const * update standard check to be simpler * allow for unstandard otel data sources but give warning * add otelJoinQuery to the base query and clean up variables when state changes * refactor otel functions to return filters for targets, use targets to filter metrics * update metric names on otel target filter change * when no otel targets for otel resource filter, show no metrics * move switch to settings, default to use experience, refactor otel checks * clean code * fix refactor to add hasOtelResources for showing the switch in settings * sort otel resources by blessed list * reset otel when data source is changed * move otel experience toggle back outside settings * move showPreviews into settings * do not re-add otel resources from blessed list to filters when already selected * add otel join query variable to histogram base query * only show settings for appropriate scenes * show info tooltip the same but show error on hover for disabling otel exp for unstandard DS * refactor tagKeys and tagValues for otel resources variable, fix promoted list ordering, fix dep env state bug * default dep env value * apply var filters only where they are using VAR_FILTER_EXPR in queryies * change copy for labels to attributes * do not group_left job label when already joining by job * update copy for label variable when using otel * remove isStandard check for now because of data staleness in Prometheus * default to showing heatmap for histograms * add trail history for selecting dep env and otel resources * add otel resource attributes tests for DataTrail * move otel functions to utils * write tests for otel api calls * write tests for otel utils functions * fix history * standard otel has target_info metric and deployment_environment resource attributes * fix tests * refactor otel functions for updating state and variables * clean code * fix tests * fix tests * mock checkDataSourceForOtelResources * fix tests * update query tests with otelJoinQuery and default to heatmap for _bucket metrics * fix tests for otel api * fix trail history test * fix trail store tests for missing otel variables * make i18n-extract * handle target_info with inconsistent job and instance labels * fix otel copy and <Trans> component * fix custom variable deployment environment bug when switchiing data sources from non otel to otel * fix linting error for trans component * format i18nKey correctly * clean up old comments * add frontend hardening for OTel job and instance metric list filtering * fix test for deployment environment custom variable to use changeValueTo * fix i18n * remove comments for fixed bug * edit skipped tests
8 months ago
value={useOtelExperience}
onChange={model.onToggleOtelExperience}
/>
</div>
</Field>
)}
</div>
{metricNamesError && (
<Alert title={unableToRetrieveMetricNames} severity="error">
<div>We are unable to connect to your data source. Double check your data source URL and credentials.</div>
<div>({metricNamesError})</div>
</Alert>
)}
{metricNamesWarning && !warningDismissed && (
<Alert
title={t(
'trails.metric-select-scene.title-unable-to-retrieve-all-metric-names',
'Unable to retrieve all metric names'
)}
severity="warning"
onSubmit={dismissWarning}
onRemove={dismissWarning}
>
<div>{metricNamesWarning}</div>
</Alert>
)}
<StatusWrapper {...{ isLoading, blockingMessage }}>
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
{body instanceof SceneFlexLayout && <body.Component model={body} />}
{body instanceof SceneCSSGridLayout && <body.Component model={body} />}
</StatusWrapper>
</div>
);
};
}
function getCardPanelFor(metric: string, description?: string) {
return PanelBuilders.text()
.setTitle(metric)
.setDescription(description)
.setHeaderActions([new SelectMetricAction({ metric, title: 'Select' })])
.setOption('content', '')
.build();
}
function getStyles(theme: GrafanaTheme2) {
return {
container: css({
display: 'flex',
flexDirection: 'column',
}),
headingWrapper: css({
marginBottom: theme.spacing(0.5),
}),
header: css({
flexGrow: 0,
display: 'flex',
gap: theme.spacing(2),
marginBottom: theme.spacing(2),
alignItems: 'flex-end',
}),
searchField: css({
flexGrow: 1,
marginBottom: 0,
}),
Explore Metrics: Implement grouping with metric prefixes (#89481) * add groop as a local dependency * update layout * nested layout with panels * fix the height of the rows * copy groop library into grafana/grafana * Don't create a new scene everytime metrics refreshed * Add display option dropdown * handle different layout options in buildLayout * add select component props * unify scene body creation * handle other display cases in refreshMetricNames * set a new body when display format is different * handle nestedScene population * show nested groups * handle panel display * add tabs view * populate tabs view * show selected tab group * show display options before metric search * populate prefix filter layout * only switch layout for nested-rows display option * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/groop/parser.ts Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Update public/app/features/trails/MetricSelect/MetricSelectScene.tsx Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> * Remove tab view * generate groups async * Remove unnecessary parts * Refactor * implement urlSync * update keys * introduce interaction * ui updates * chore: revert some auto formatting to clarify comments * chore: revert some auto formatting to clarify comments * rename * add tooltip * add styles * update unit tests * make i18n-extract * update unit test --------- Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
10 months ago
metricTabGroup: css({
marginBottom: theme.spacing(2),
}),
displayOption: css({
flexGrow: 0,
marginBottom: 0,
minWidth: '184px',
}),
displayOptionTooltip: css({
display: 'flex',
gap: theme.spacing(1),
}),
warningIcon: css({
color: theme.colors.warning.main,
}),
Explore metrics: Consolidate filters with the OTel experience (#98371) * sort otel resources to top of adhoc filters * add bool in datatrail * add function to find non promoted otel resources * add additional super filter variable * hide filters var and keep otel filters var hidden * add nonpromoted resources to state, update otel or var filters when super filter is updated * update comments * update plan * Allow deployment environment values from both metrics and target_info * Remove usage of dep env var in getting resources * update code comments for clarity * Remove dep env variable, autoselect dep env in otelmetricvar and allow updating of vals in otelmetricvar * Fix bug that conflicts with local storage useOtelExperience check * expose metadata to show data source is loaded to prevent otel race conditions * remove filtering check on target_info in the itel join query * update plan with extra issues * refactor update and reset functions for otel experience * use non promoted resources as the standardization check * sort the resources in filters var if using otel experience * add test for sorting resources with otelmetricsvar * update tests for otel experience in datatrail.test * update tests for otel utils * update otel api tests * update trail store tests to remove dep env var * run prettier * remove unused imports * add tests, distinguish on start and when the initial otel check is done, update comments * Fix bug when adding multiple otel resources * fix when adding filter from breakdown * add migration for dep env var * update migration function and write tests * prettier * Update dep env migration to handle bookmarks * fix trailstore tests for reintroducing the dep env var * refactor default env function, we only need the value * remove redundant check * move otel functions to utils and update and add tests * prettier * cleanup * fix migration for fromStart * update tests for migration * use join and use push * fix flow with state * Fix flow in update OTel function * update tests for flow fixes * fix toggle OTel bugs * report when dep env has been migrated and delete dep env filters to not migrate it again * Clear out dep env after migration * run prettier * improve non promoted attribute function * remove unused functions * prettier * default otel experience to off * report when otel experience is used * report when otel is turned on and off * report otel filters changed * prettier * keep default otel off, respect the local storage, but if loading with otel vars from url or bookmark we can turn it on * Add new badge * fix metric scene breakdown add filter bug around non promoted labels on a metric that are different than non promoted labels for all metrics * prettier * make i18n-extract * prettier for translations * change button name to "Filter" * Update public/app/features/trails/Breakdown/AddToFiltersGraphAction.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/migrations/otelDeploymentEnvironment.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/DataTrail.tsx Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/api.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Update public/app/features/trails/otel/util.ts Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> * Add more padding for pill where capital letter gets to close to the left border and looks off. * clear up comments --------- Co-authored-by: Nick Richmond <5732000+NWRichmond@users.noreply.github.com>
4 months ago
badgeStyle: css({
display: 'flex',
height: '1rem',
padding: '0rem 0.25rem 0 0.30rem',
alignItems: 'center',
borderRadius: theme.shape.radius.pill,
border: `1px solid ${theme.colors.info.text}`,
background: theme.colors.info.transparent,
marginTop: '4px',
marginLeft: '-3px',
}),
};
}
function getMetricSearch(scene: SceneObject) {
const trail = getTrailFor(scene);
return trail.state.metricSearch || '';
}