Skip to content

Commit

Permalink
fix: service overview use sum (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mizy committed Dec 29, 2022
1 parent 90f403a commit ff125d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/pages/ServiceDashboard/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ function ServiceDetail(props: IProps) {
const getPromise = (chart) => {
return new Promise((resolve, reject) => {
const item: IServiceMetricItem = chart.metric;
const metricType = item.aggregations[0] as AggregationType;
const aggregation = item.aggregations[0] as AggregationType;
asyncFetchMetricsData({
query: getQueryByMetricType(item, metricType, period),
query: getQueryByMetricType(item, aggregation, period),
start: startTime,
end: endTime,
space: serviceType === ServiceName.GRAPHD ? space : undefined,
clusterID: cluster?.id,
isRawMetric:item.isRawMetric
isRawMetric: item.isRawMetric,
aggregation
}).then(res => {
resolve(res);
}).catch(e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { Popover } from 'antd';
import Icon from '@/components/Icon';
import { IServiceMetricItem, IServicePanelConfig, MetricScene, ServiceName } from '@/utils/interface';
import { calcTimeRange, getDataByType, getMetricsUniqName, TIME_OPTION_TYPE } from '@/utils/dashboard';
import { AggregationType, calcTimeRange, getDataByType, getMetricsUniqName, TIME_OPTION_TYPE } from '@/utils/dashboard';
import Card from '@/components/Service/ServiceCard/Card';
import { IDispatch, IRootState } from '@/store';
import { shouldCheckCluster } from '@/utils';
Expand Down Expand Up @@ -60,16 +60,19 @@ function CustomServiceQueryPanel(props: IProps) {
}, [metricsFilterValues, metricsFilterValues, cluster, config, serviceMetric])

const getMetricsData = async () => {
const { period: metricPeriod, space, metric, aggregation } = config;
let { period: metricPeriod = 5, space, metric } = config;
const [start, end] = calcTimeRange(TIME_OPTION_TYPE.HOUR12);
const item = (serviceMetric[serviceType] as IServiceMetricItem[]).find((metricItem: IServiceMetricItem) => metricItem.metric === metric);
const aggregation = item?.aggregations[0] as AggregationType;
if (item) {
const data = await asyncGetMetricsData({
query: getQueryByMetricType(item, aggregation, metricPeriod?.toString()), // EXPLAIN: query like nebula_graphd_num_queries_rate_600
start,
end,
space,
clusterID: cluster?.id
clusterID: cluster?.id,
isRawMetric: item.isRawMetric,
aggregation
});
setData(data)
}
Expand Down
5 changes: 3 additions & 2 deletions src/store/models/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'lodash';
import serviceApi from '@/config/service';
import { IPanelConfig, ServiceMetricsPanelValue } from '@/utils/interface';
import { DEFAULT_SERVICE_PANEL_CONFIG } from '@/utils/service';
import { getProperStep } from '@/utils/dashboard';
import { AggregationType, getProperStep } from '@/utils/dashboard';
import { unique } from '@/utils';
import { getClusterPrefix } from '@/utils/promQL';
import { InitMetricsFilterValues } from '@/utils/metric';
Expand Down Expand Up @@ -89,6 +89,7 @@ export function SereviceModelWrapper(serviceApi) {
clusterID?: string;
noSuffix?: boolean;
isRawMetric?: boolean;
aggregation: AggregationType;
}) {
const {
start,
Expand All @@ -106,7 +107,7 @@ export function SereviceModelWrapper(serviceApi) {
let query = _query;
if (!noSuffix) {
if (clusterID) {
if (!payload.isRawMetric) {
if (!payload.isRawMetric && payload.aggregation === AggregationType.Sum) {
query = `sum_over_time(${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}[${step}s])`;
} else {
query = `${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}`;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export const filterServiceMetrics = (payload: {
_item => _item === key,
);
if (!metricTypeItem) {
if (key === 'sum') {// make sum the first
metricItem.aggregations.unshift(key);
return;
}
metricItem.aggregations.push(key);
}
}
Expand All @@ -161,7 +165,7 @@ export const filterServiceMetrics = (payload: {
isSpaceMetric: !!isSpaceMetric,
isRawMetric: !key, // if metrics don't have sum / avg / p99
prefixMetric: `${metricFieldType}_${componentType.replace('-', '_')}`,
aggregations: key ? [key] : METRIC_FUNCTIONS,
aggregations: key ? [key] : [],
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ export const LINE_COLORS = [
export const DEFAULT_SERVICE_PANEL_CONFIG = {
[ServiceName.GRAPHD]: [
{
period: 60,
period: 5,
metric: 'num_queries',
aggregation: AggregationType.Rate,
aggregation: AggregationType.Sum,
},
{
period: 60,
period: 5,
metric: 'num_slow_queries',
aggregation: AggregationType.Rate,
aggregation: AggregationType.Sum,
},
],
[ServiceName.STORAGED]: [
Expand All @@ -111,9 +111,9 @@ export const DEFAULT_SERVICE_PANEL_CONFIG = {
aggregation: AggregationType.Avg,
},
{
period: 60,
period: 5,
metric: 'num_heartbeats',
aggregation: AggregationType.Rate,
aggregation: AggregationType.Sum,
}
],
[ServiceName.MetadListener]: [],
Expand Down

0 comments on commit ff125d0

Please sign in to comment.