Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured metadata: Changes to ad-hoc variable doesn't run detected_fields #849

Merged
merged 8 commits into from
Oct 23, 2024
Merged
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
"dependencies": {
"@bsull/augurs": "^0.3.1",
"@emotion/css": "^11.10.6",
"@grafana/data": "^11.2.2",
"@grafana/data": "^11.3.0",
"@grafana/lezer-logql": "^0.2.6",
"@grafana/runtime": "^11.2.2",
"@grafana/runtime": "^11.3.0",
"@grafana/scenes": "5.14.7",
"@grafana/ui": "^11.2.2",
"@grafana/ui": "^11.3.0",
"@hello-pangea/dnd": "^16.6.0",
"@lezer/common": "^1.2.1",
"@lezer/lr": "^1.4.1",
Expand Down
1 change: 0 additions & 1 deletion src/Components/IndexScene/IndexScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class IndexScene extends SceneObjectBase<IndexSceneState> {
new SceneRefreshPicker({}),
];

//@ts-expect-error
if (getDrilldownSlug() === 'explore' && config.featureToggles.exploreLogsAggregatedMetrics) {
controls.push(
new ToolbarScene({
Expand Down
3 changes: 1 addition & 2 deletions src/Components/IndexScene/ToolbarScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ export interface ToolbarSceneState extends SceneObjectState {
export class ToolbarScene extends SceneObjectBase<ToolbarSceneState> {
constructor(state: Partial<ToolbarSceneState>) {
const userOverride = localStorage.getItem(AGGREGATED_METRICS_USER_OVERRIDE_LOCALSTORAGE_KEY);
// @ts-expect-error
const active = config.featureToggles.exploreLogsAggregatedMetrics && userOverride !== 'false';

super({
isOpen: false,
options: {
aggregatedMetrics: {
active,
active: active ?? false,
userOverride: userOverride === 'true' ?? false,
disabled: false,
},
Expand Down
29 changes: 29 additions & 0 deletions src/Components/ServiceScene/ServiceScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
getFieldsVariable,
getLabelsVariable,
getLevelsVariable,
getMetadataVariable,
getPatternsVariable,
} from '../../services/variableGetters';
import { logger } from '../../services/logger';
import { IndexScene } from '../IndexScene/IndexScene';
Expand Down Expand Up @@ -266,12 +268,23 @@ export class ServiceScene extends SceneObjectBase<ServiceSceneState> {
// Variable subscriptions
this.setSubscribeToLabelsVariable();
this._subs.add(this.subscribeToFieldsVariable());
this._subs.add(this.subscribeToMetadataVariable());
this._subs.add(this.subscribeToLevelsVariable());
this._subs.add(this.subscribeToDataSourceVariable());
this._subs.add(this.subscribeToPatternsVariable());

// Update query runner on manual time range change
this._subs.add(this.subscribeToTimeRange());
}

private subscribeToPatternsVariable() {
return getPatternsVariable(this).subscribeToState((newState, prevState) => {
if (newState.value !== prevState.value) {
this.state.$detectedFieldsData?.runQueries();
}
});
}

private subscribeToDataSourceVariable() {
return getDataSourceVariable(this).subscribeToState(() => {
this.redirectToStart();
Expand All @@ -296,6 +309,22 @@ export class ServiceScene extends SceneObjectBase<ServiceSceneState> {
});
}

private subscribeToMetadataVariable() {
return getMetadataVariable(this).subscribeToState((newState, prevState) => {
if (!areArraysEqual(newState.filters, prevState.filters)) {
this.state.$detectedFieldsData?.runQueries();
}
});
}

private subscribeToLevelsVariable() {
return getLevelsVariable(this).subscribeToState((newState, prevState) => {
if (!areArraysEqual(newState.filters, prevState.filters)) {
this.state.$detectedFieldsData?.runQueries();
}
});
}

private runQueries() {
const slug = getDrilldownSlug();
const parentSlug = getDrilldownValueSlug();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import { FavoriteServiceHeaderActionScene } from './FavoriteServiceHeaderActionS
import { pushUrlHandler } from '../../services/navigate';
import { NoServiceVolume } from './NoServiceVolume';

// @ts-expect-error
const aggregatedMetricsEnabled: boolean | undefined = config.featureToggles.exploreLogsAggregatedMetrics;
// Don't export AGGREGATED_SERVICE_NAME, we want to rename things so the rest of the application is agnostic to how we got the services
const AGGREGATED_SERVICE_NAME = '__aggregated_metric__';
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
],
"roles": [],
"dependencies": {
"grafanaDependency": ">=11.2.0",
"grafanaDependency": ">=11.3.0",
"plugins": []
},
"preload": true,
Expand Down
1 change: 0 additions & 1 deletion src/services/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class WrappedLokiDatasource extends RuntimeDataSource<DataQuery> {
ds: DataSourceWithBackend<LokiQuery>,
subscriber: Subscriber<DataQueryResponse>
) {
// @ts-expect-error
const shardingEnabled = config.featureToggles.exploreLogsShardSplitting;

// Query the datasource and return either observable or promise
Expand Down
5 changes: 5 additions & 0 deletions src/services/variableGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
VAR_PRIMARY_LABEL,
VAR_PRIMARY_LABEL_SEARCH,
VAR_METADATA_EXPR,
VAR_METADATA,
} from './variables';
import { AdHocVariableFilter } from '@grafana/data';
import { logger } from './logger';
Expand Down Expand Up @@ -72,6 +73,10 @@ export function getFieldsVariable(scene: SceneObject) {
return getAdHocFiltersVariable(VAR_FIELDS, scene);
}

export function getMetadataVariable(scene: SceneObject) {
return getAdHocFiltersVariable(VAR_METADATA, scene);
}

export function getLevelsVariable(scene: SceneObject) {
return getAdHocFiltersVariable(VAR_LEVELS, scene);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/exploreServices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ test.describe('explore services page', () => {
page.waitForResponse((resp) => resp.url().includes('ds/query')),
]);
});
test.afterEach(async ({ page }) => {
await explorePage.unroute();
explorePage.echoConsoleLogsOnRetry();
});

test('refreshing time range should request panel data once', async ({ page }) => {
await page.waitForFunction(() => !document.querySelector('[title="Cancel query"]'));
Expand Down
9 changes: 2 additions & 7 deletions tests/exploreServicesBreakDown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test.describe('explore services breakdown page', () => {
test('should filter logs panel on search for broadcast field', async ({ page }) => {
await explorePage.serviceBreakdownSearch.click();
await explorePage.serviceBreakdownSearch.fill('broadcast');
await expect(page.getByRole('table').locator('tr').first().getByText('broadcast')).toBeVisible();
await expect(page.getByRole('table').locator('tr').first().getByText('broadcast').first()).toBeVisible();
await expect(page).toHaveURL(/broadcast/);
});

Expand Down Expand Up @@ -394,7 +394,6 @@ test.describe('explore services breakdown page', () => {
const json = await response.json();
return route.fulfill({ response, json });
});

// Navigate to fields tab
await explorePage.goToFieldsTab();
// Make sure the panels have started to render
Expand All @@ -403,19 +402,15 @@ test.describe('explore services breakdown page', () => {
await explorePage.assertTabsNotLoading();
// Fields on top should be loaded
expect(requestCount).toEqual(6);

await explorePage.scrollToBottom();
// Panel on the bottom should be visible
await expect(page.getByTestId(/data-testid Panel header/).last()).toBeInViewport();

// Panel on the top should not
await expect(page.getByTestId(/data-testid Panel header/).first()).not.toBeInViewport();

// Wait for a bit for the requests to be made
await page.waitForTimeout(250);

// if this flakes we could just assert that it's greater then 3
expect(requestCount).toEqual(14);
expect(requestCount).toEqual(17);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why there is an extra row now, this shouldn't have anything to do with the functional change in this PR, I think it's a consequence of the updates to 11.3

});

test(`should select field ${fieldName}, update filters, open log panel`, async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ExplorePage {
}

async setDefaultViewportSize() {
await this.page.setViewportSize({ width: 1280, height: 720 });
await this.page.setViewportSize({ width: 1280, height: 680 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window height also changed a bit in 11.3, which had the consequence of adding more lazy loaded elements into the viewport, bumping down the height a tiny bit so we don't have to update a bunch of assertions.

}

async setExtraTallViewportSize() {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class ExplorePage {
}

async scrollToBottom() {
const main = this.page.locator('main#pageContent');
const main = this.page.locator('html');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scroll container appears to have changed in 11.3


// Scroll the page container to the bottom
await main.evaluate((main) => main.scrollTo(0, main.scrollHeight));
Expand Down
Loading
Loading