Skip to content

Commit

Permalink
fix: sum_over_time
Browse files Browse the repository at this point in the history
  • Loading branch information
mizy committed Dec 27, 2022
1 parent af68625 commit 8487131
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 83 deletions.
38 changes: 1 addition & 37 deletions src/components/Service/ServiceCardEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ function ServiceCardEdit(props: IProps) {
initialValues={editItem}
onFinish={handlePanelConfigUpdate}
>
<Form.Item label={intl.get('service.period')} name="period">
<DashboardSelect>
{TIME_INTERVAL_OPTIONS.map(value => (
<Option key={value} value={value}>
{value}
</Option>
))}
</DashboardSelect>
</Form.Item>
<MetricPopover list={curServiceMetricItems} />
<Form.Item label={intl.get('service.metric')} name="metric">
<DashboardSelect onChange={handleUpdateMetricType}>
Expand Down Expand Up @@ -108,34 +99,7 @@ function ServiceCardEdit(props: IProps) {
</Form.Item>
) : null;
}}
</Form.Item>
<Form.Item
noStyle={true}
shouldUpdate={(prevValues, currentValues) =>
prevValues.metric !== currentValues.metric
}
>
{({ getFieldValue }) => {
const metric = getFieldValue('metric');
const typeList = curServiceMetricItems.find(
item => item.metric === metric,
)?.aggregations;
return getFieldValue('metric') ? (
<Form.Item
label={intl.get('service.metricParams')}
name="aggregation"
>
<DashboardSelect>
{typeList?.map((params, index) => (
<Option key={index} value={params}>
{params}
</Option>
))}
</DashboardSelect>
</Form.Item>
) : null;
}}
</Form.Item>
</Form.Item>
<Form.Item label={intl.get('common.baseLine')} name="baseLine">
<InputNumber />
</Form.Item>
Expand Down
28 changes: 1 addition & 27 deletions src/components/ServiceMetricsFilterPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,7 @@ function ServiceMetricsFilterPanel(props: IProps) {
</DashboardSelect>
</Form.Item>
)
}
<Form.Item
className="metric-period"
label={intl.get('service.period')}
name="period"
>
<DashboardSelect onChange={handlePeriodChange}>
{TIME_INTERVAL_OPTIONS.map(value => (
<Option key={value} value={value}>
{value}
</Option>
))}
</DashboardSelect>
</Form.Item>
<Form.Item
className="metric-type"
label={intl.get('service.metricParams')}
name="metricType"
>
<DashboardSelect onChange={handleMetricTypeChange}>
{AGGREGATION_OPTIONS.map(type => (
<Option key={type} value={type}>
{type}
</Option>
))}
</DashboardSelect>
</Form.Item>
}
</MetricsFilterPanel>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions src/pages/ServiceDashboard/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function ServiceDetail(props: IProps) {
end: endTime,
space: serviceType === ServiceName.GRAPHD ? space : undefined,
clusterID: cluster?.id,
isRawMetric:item.isRawMetric
}).then(res => {
resolve(res);
}).catch(e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,7 @@ function CustomServiceQueryPanel(props: IProps) {
>
{config.metric}
</Popover>
<div>
{
!isHidePeriod && (
<>
<span>
{intl.get('service.period')}: <span>{config.period}</span>
</span>
<span>
{intl.get('service.metricParams')}: <span>{config.metricType}</span>
</span>
</>
)
}
<div>
<div
className={classnames('blue btn-icon-with-desc', {
'hide-period': isHidePeriod,
Expand Down
19 changes: 14 additions & 5 deletions src/store/models/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ export function SereviceModelWrapper(serviceApi) {
}) {
const { start, end, space, query: _query, clusterID } = payload;
const step = getProperStep(start, end);
const _start = start / 1000;
const _end = end / 1000;
let _start = start / 1000;
let _end = end / 1000;
_start = _start - _start % step;
_end = _end + (step - _end % step);
let query = `sum(${_query}{${getClusterPrefix()}="${clusterID}"})`;
query = `${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}`;
const { code, data } = (await serviceApi.execPromQLByRange({
Expand Down Expand Up @@ -86,6 +88,7 @@ export function SereviceModelWrapper(serviceApi) {
end: number;
clusterID?: string;
noSuffix?: boolean;
isRawMetric?: boolean;
}) {
const {
start,
Expand All @@ -96,12 +99,18 @@ export function SereviceModelWrapper(serviceApi) {
noSuffix = false,
} = payload;
const step = getProperStep(start, end);
const _start = start / 1000;
const _end = end / 1000;
let _start = start / 1000;
let _end = end / 1000;
_start = _start - _start % step;
_end = _end + (step - _end % step);
let query = _query;
if (!noSuffix) {
if (clusterID) {
query = `${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}`;
if (!payload.isRawMetric) {
query = `sum_over_time(${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}[${step}s])`;
} else {
query = `${_query}{${getClusterPrefix()}="${clusterID}", space="${space || ''}"}`;
}
} else {
query = `${_query}{space="${space || ''}"}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AggregationType } from './dashboard';
import { ServiceName } from './interface';

export const SERVICE_POLLING_INTERVAL = 10 * 1000;
export const SERVICE_QUERY_PERIOD = 10 * 60;
export const SERVICE_QUERY_PERIOD = 5;
export const SERVICE_DEFAULT_RANGE = 6 * 60 * 60 * 1000;

export enum INTERVAL_FREQUENCY_TYPE {
Expand Down

0 comments on commit 8487131

Please sign in to comment.