Skip to content

Commit c405f51

Browse files
committed
feat: 【仪表盘】高级设置里,增加“降采样”的开关配置 --Story=120717565
# Reviewed, transaction id: 24166
1 parent 26dd1d6 commit c405f51

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
lines changed

src/timeseries/src/components/addvance-setting.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
* IN THE SOFTWARE.
2525
*/
2626
import Select from 'antd/es/select';
27+
import Switch from 'antd/es/switch';
2728
import React from 'react';
2829
import { EditMode } from 'typings/metric';
2930

3031
import { getEnByName } from '../utils/utils';
3132
import AliasInput from './alias-input';
3233
import EditorForm from './editor-form';
33-
export type AddvanceSettingKey = 'format' | 'promqlAlias' | 'step' | 'type';
34+
export type AddvanceSettingKey = 'enableDownSampling' | 'format' | 'promqlAlias' | 'step' | 'type';
3435
export interface IAddvanceSettingProps {
3536
format: string;
3637
mode: EditMode;
@@ -42,6 +43,7 @@ export interface IAddvanceSettingProps {
4243
promqlAlias: string;
4344
step: string;
4445
type: string;
46+
enableDownSampling: boolean;
4547
}
4648

4749
interface IAddvanceState {
@@ -87,7 +89,7 @@ export default class AddvanceSetting extends React.PureComponent<IAddvanceSettin
8789

8890
render(): JSX.Element {
8991
const { showContent } = this.state;
90-
const { format, mode, onChange, promqlAlias, step, type } = this.props;
92+
const { format, mode, onChange, promqlAlias, step, type, enableDownSampling } = this.props;
9193
const getHeaderContent = () => (
9294
<div className='header-content'>
9395
{mode === 'code' && <span className='header-content-item'>Min Step: {step || 'auto'}</span>}
@@ -102,6 +104,9 @@ export default class AddvanceSetting extends React.PureComponent<IAddvanceSettin
102104
<span className='header-content-item'>
103105
{getEnByName('类型')}: {typeList.find(item => item.id === type)?.name || 'Range'}
104106
</span>
107+
<span className='header-content-item'>
108+
{getEnByName('降采样')}: {enableDownSampling ? getEnByName('开启') : getEnByName('关闭')}
109+
</span>
105110
</div>
106111
);
107112
const uiForm = () => (
@@ -136,6 +141,17 @@ export default class AddvanceSetting extends React.PureComponent<IAddvanceSettin
136141
))}
137142
</Select>
138143
</EditorForm>
144+
<EditorForm title={getEnByName('降采样')}>
145+
<div className='down-sample-wrapper'>
146+
<Switch
147+
checked={enableDownSampling}
148+
checkedChildren={getEnByName('开启')}
149+
size='small'
150+
unCheckedChildren={getEnByName('关闭')}
151+
onChange={v => onChange('enableDownSampling', v)}
152+
/>
153+
</div>
154+
</EditorForm>
139155
</EditorForm>
140156
</>
141157
);
@@ -202,6 +218,17 @@ export default class AddvanceSetting extends React.PureComponent<IAddvanceSettin
202218
))}
203219
</Select>
204220
</EditorForm>
221+
<EditorForm title={getEnByName('降采样')}>
222+
<div className='down-sample-wrapper'>
223+
<Switch
224+
checked={enableDownSampling}
225+
checkedChildren={getEnByName('开启')}
226+
size='small'
227+
unCheckedChildren={getEnByName('关闭')}
228+
onChange={v => onChange('enableDownSampling', v)}
229+
/>
230+
</div>
231+
</EditorForm>
205232
</EditorForm>
206233
) : (
207234
uiForm()

src/timeseries/src/components/query-editor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ interface IQueryEditorState {
9393
// onlyPromql: boolean;
9494
step: string;
9595
type: string;
96+
enableDownSampling: boolean;
9697
}
9798
export default class MonitorQueryEditor extends React.PureComponent<IQueryEditorProps, IQueryEditorState> {
9899
constructor(props, context) {
@@ -116,6 +117,7 @@ export default class MonitorQueryEditor extends React.PureComponent<IQueryEditor
116117
promqlAlias = '',
117118
source = '',
118119
step = '',
120+
enableDownSampling = true,
119121
} = query;
120122
let expressions: IExpresionItem[] = expressionList;
121123
// 兼容旧版本
@@ -147,6 +149,7 @@ export default class MonitorQueryEditor extends React.PureComponent<IQueryEditor
147149
searchState: SearcState.deafult,
148150
source,
149151
step,
152+
enableDownSampling,
150153
type: query.type ?? 'range',
151154
};
152155
this.initState(query);
@@ -942,7 +945,7 @@ export default class MonitorQueryEditor extends React.PureComponent<IQueryEditor
942945
return letter;
943946
}
944947
handleGetQueryData(metricList: MetricDetail[]) {
945-
const { cluster, expressionList, host, module, promqlAlias } = this.state;
948+
const { cluster, expressionList, host, module, promqlAlias, enableDownSampling } = this.state;
946949
// const curExpression = typeof expression === 'undefined' ? this.state.expression : expression;
947950
// const curDisplay = typeof display === 'undefined' ? this.state.display : display;
948951
return {
@@ -957,6 +960,7 @@ export default class MonitorQueryEditor extends React.PureComponent<IQueryEditor
957960
host,
958961
module,
959962
promqlAlias,
963+
enableDownSampling,
960964
query_configs: metricList
961965
.filter(item => item.metricMetaId)
962966
.map(item => {
@@ -1413,6 +1417,7 @@ export default class MonitorQueryEditor extends React.PureComponent<IQueryEditor
14131417
) : undefined}
14141418
{
14151419
<AddvanceSetting
1420+
enableDownSampling={this.state.enableDownSampling}
14161421
format={this.state.format}
14171422
mode={mode}
14181423
promqlAlias={promqlAlias}

src/timeseries/src/datasource/datasource.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
857857
this.request({
858858
data: {
859859
display: config.display,
860-
down_sample_range,
860+
down_sample_range: item.enableDownSampling !== false ? down_sample_range : undefined,
861861
end_time: options.range.to.unix(),
862862
expression: config.refId || '',
863863
format: item.format,
@@ -892,7 +892,7 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
892892
if (item.mode === 'code' || item.only_promql) {
893893
const params = {
894894
data: {
895-
down_sample_range,
895+
down_sample_range: item.enableDownSampling !== false ? down_sample_range : undefined,
896896
end_time: options.range.to.unix(),
897897
format: item.format,
898898
promql: this.buildPromqlVariables(item.source!, {
@@ -924,13 +924,13 @@ export default class DashboardDatasource extends DataSourceApi<QueryData, QueryO
924924
}),
925925
);
926926
} else {
927-
const { cluster, expressionList, host, module } = item;
927+
const { cluster, expressionList, host, module, enableDownSampling } = item;
928928
expressionList?.forEach(exp => {
929929
if (exp.expression && exp.active) {
930930
const p = {
931931
data: {
932932
display: exp.active,
933-
down_sample_range,
933+
down_sample_range: enableDownSampling !== false ? down_sample_range : undefined,
934934
end_time: options.range.to.unix(),
935935
expression: exp.expression,
936936
format: item.format,

src/timeseries/src/lang/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@
7272
"指标选择": "Metric selection",
7373
"- 空 -": "- empty -",
7474
"复制成功": "Copy Success",
75-
"已选": "Selected"
75+
"已选": "Selected",
76+
"开启": "on",
77+
"关闭": "off",
78+
"降采样": "Down Sampling"
7679
}

src/timeseries/src/sass/grafana-antd.light.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// @import '~antd/es/style/themes/default.less';
32
// @import '~antd/dist/antd.less'; // 引入官方提供的 less 样式入口文件
43
// @import './custom-antd-theme.less'; // 用于覆盖上面定义的变量
@@ -16,4 +15,5 @@
1615
@import '~antd/es/spin/style/index.less';
1716
@import '~antd/es/cascader/style/index.less';
1817
@import '~antd/es/input-number/style/index.less';
19-
@import '~antd/es/button/style/index.less';
18+
@import '~antd/es/button/style/index.less';
19+
@import '~antd/es/switch/style/index.less';

src/timeseries/src/sass/query.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@
626626
}
627627
}
628628
}
629+
.down-sample-wrapper {
630+
display: flex;
631+
align-items: center;
632+
padding: 0px 8px;
633+
border: 1px solid #dcdee5;
634+
}
629635
}
630636

631637
.key-del {

src/timeseries/src/typings/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface QueryData extends DataQuery {
6868
source?: string;
6969
step?: string;
7070
type?: string;
71+
enableDownSampling?: boolean;
7172
}
7273

7374
export const DIM_NULL_ID = '';

0 commit comments

Comments
 (0)