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

feat: supporting aggregation queries in visualization #2506

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dashboard } from '@hypertrace/hyperdash';
import { recordObservable, runFakeRxjs } from '@hypertrace/test-utils';
import { MockService } from 'ng-mocks';
import { EMPTY, of } from 'rxjs';
import { CartesianSeriesVisualizationType } from '../../shared/components/cartesian/chart';
import { CartesianSeriesVisualizationType, ScaleType } from '../../shared/components/cartesian/chart';
import { ExploreVisualizationRequest } from '../../shared/components/explore-query-editor/explore-visualization-builder';
import { LegendPosition } from '../../shared/components/legend/legend.component';
import { ExplorerVisualizationCartesianDataSourceModel } from '../../shared/dashboard/data/graphql/explorer-visualization/explorer-visualization-cartesian-data-source.model';
Expand Down Expand Up @@ -45,6 +45,11 @@ describe('Explorer dashboard builder', () => {
'selection-handler': {
type: 'cartesian-explorer-selection-handler',
'show-context-menu': false
},
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band,
'show-tick-labels': false
}
},
onReady: expect.any(Function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@
type: 'cartesian-explorer-selection-handler',
'show-context-menu': false
},
...(!isEmpty(request.groupBy) && isEmpty(request.interval)
? {
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band
}
}
: {})
...this.buildXAxis(request)
},
onReady: dashboard => {
dashboard.createAndSetRootDataFromModelClass(ExplorerVisualizationCartesianDataSourceModel);
Expand Down Expand Up @@ -168,6 +161,29 @@
};
}

private buildXAxis(request: ExploreVisualizationRequest): object {
if (isEmpty(request.interval)) {
if (isEmpty(request.groupBy)) {
return {
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band,
'show-tick-labels': false
}
};
} else {
return {

Check warning on line 175 in projects/observability/src/pages/explorer/explorer-dashboard-builder.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/pages/explorer/explorer-dashboard-builder.ts#L174-L175

Added lines #L174 - L175 were not covered by tests
'x-axis': {
type: 'cartesian-axis',
'scale-type': ScaleType.Band
}
};
}
}

return {};
}

private getRendererForType(type: AttributeMetadataType): string {
switch (type) {
case AttributeMetadataType.Long:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
</div>
<div class="filters-row">
<ht-explore-query-order-by-editor
*ngIf="!currentVisualization.interval"
*ngIf="!currentVisualization.interval && currentVisualization.groupBy"
class="order-by"
[orderByExpression]="currentVisualization.orderBy"
[context]="currentVisualization.context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
return aggregatableSpecs.map(spec => this.buildGroupedTimeseriesData(spec, groupByExpressions, result)).flat();
}

return [];
return aggregatableSpecs.map(spec => this.buildMetricAggregationSeriesData(spec, result));

Check warning on line 126 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts#L126

Added line #L126 was not covered by tests
}

private buildSeries(request: ExploreRequestState, result: SeriesData, color: string): Observable<ExplorerSeries> {
Expand Down Expand Up @@ -174,6 +174,15 @@
};
}

public buildMetricAggregationSeriesData(spec: AggregatableSpec, result: ExploreResult): SeriesData {
const metricAggregationData = result.getMetricAggregationSeriesData(spec.name, spec.aggregation);

Check warning on line 178 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts#L177-L178

Added lines #L177 - L178 were not covered by tests

return {

Check warning on line 180 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts#L180

Added line #L180 was not covered by tests
data: metricAggregationData?.value ? [['', metricAggregationData.value]] : [],
spec: spec
};
}

public buildGroupedTimeseriesData(
spec: AggregatableSpec,
groupByExpressions: AttributeExpression[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
);
}

public getMetricAggregationSeriesData(metricKey: string, aggregation: MetricAggregationType): MetricAggregationData {
return this.extractMetricAggregationForSpec(this.specBuilder.exploreSpecificationForKey(metricKey, aggregation));

Check warning on line 43 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts#L42-L43

Added lines #L42 - L43 were not covered by tests
}

public getGroupedTimeSeriesData(
groupExpressions: AttributeExpression[],
metricKey: string,
Expand All @@ -64,10 +68,24 @@
return this.resultsContainingSpec(spec).map(result => this.resultToGroupData(result, groupBySpecs, spec));
}

private extractMetricAggregationForSpec(spec: ExploreSpecification): MetricAggregationData {

Check warning on line 71 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts#L71

Added line #L71 was not covered by tests
return this.resultToMetricAggregationDataData(this.resultsContainingSpec(spec)?.[0], spec);
}

private extractTimeseriesForSpec(spec: ExploreSpecification): MetricTimeseriesInterval[] {
return this.resultsToTimeseriesIntervals(this.resultsContainingSpec(spec), spec);
}

private resultToMetricAggregationDataData(
result: GraphQlExploreResult | undefined,
spec: ExploreSpecification

Check warning on line 81 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts#L81

Added line #L81 was not covered by tests
): MetricAggregationData {
return {

Check warning on line 83 in projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/dashboard/data/graphql/explore/explore-result.ts#L83

Added line #L83 was not covered by tests
key: spec.name,
value: result?.[spec.resultAlias()].value as number
};
}

private resultToGroupData(
result: GraphQlExploreResult,
groupBySpecs: ExploreSpecification[],
Expand Down Expand Up @@ -143,3 +161,8 @@
keys: string[];
value: number;
}

interface MetricAggregationData {
key: string;
value: number | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ export class CartesianAxisModel {
})
public minUpperLimit?: number;

@ModelProperty({
key: 'show-tick-labels',
required: false,
displayName: 'Show Tick Labels',
type: BOOLEAN_PROPERTY.type
})
public showTickLabels?: boolean;

public getAxisOption(): Partial<Axis> {
return {
scale: this.scale,
gridLines: this.showGridLines,
max: this.minUpperLimit
max: this.minUpperLimit,
tickLabels: this.showTickLabels
};
}
}
Loading