Skip to content

Commit 0d6a416

Browse files
twou12031travilyu
authored andcommitted
[feature] deepflow querier datasource, 'SHOW METRICS' add 'auto' option as default
**Phenomenon and reproduction steps** none **Root cause and solution** none **Impactions** none **Test method** - deepflow querier datasource - 'SHOW METRICS' default value is 'auto' - when select multi metrics, will display - when select single metircs, will hidden **Affected branch(es)** - main **Checklist** - [ ] Dependencies update required - [ ] Common bug (similar problem in other repo)
1 parent ae75f32 commit 0d6a416

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

deepflow-querier-datasource/src/QueryEditor.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
22
import { QueryEditorProps, VariableModel } from '@grafana/data'
33
import { DataSource } from './datasource'
44
import { MyDataSourceOptions, MyQuery } from './types'
5-
import { Button, Form, InlineField, Select, Input, Alert, getTheme } from '@grafana/ui'
5+
import { Button, Form, InlineField, Select, Input, Alert, getTheme, Icon, Tooltip } from '@grafana/ui'
66
import { QueryEditorFormRow } from './components/QueryEditorFormRow'
77
import _ from 'lodash'
88
import * as querierJs from 'deepflow-sdk-js'
@@ -1230,14 +1230,34 @@ export class QueryEditor extends PureComponent<Props> {
12301230
/>
12311231
</InlineField>
12321232
<InlineField className="custom-label" label="SHOW METRICS" labelWidth={14}>
1233-
<Select
1234-
options={showMetricsOpts}
1235-
value={this.state.showMetrics}
1236-
onChange={(val: any) => this.onFieldChange('showMetrics', val)}
1237-
placeholder="SHOW METRICS"
1238-
key={this.state.showMetrics ? 'showMetricsWithVal' : 'showMetricsWithoutVal'}
1239-
width="auto"
1240-
/>
1233+
<div>
1234+
<Select
1235+
options={showMetricsOpts}
1236+
value={this.state.showMetrics}
1237+
onChange={(val: any) => this.onFieldChange('showMetrics', val)}
1238+
placeholder="SHOW METRICS"
1239+
key={this.state.showMetrics ? 'showMetricsWithVal' : 'showMetricsWithoutVal'}
1240+
width="auto"
1241+
/>
1242+
<Tooltip
1243+
placement="top"
1244+
content={
1245+
<div>
1246+
<span>whether to display metrics&apos;s names in legends.</span>
1247+
<br />
1248+
<span>auto: when select multiple metrics to display; otherwise do not show.</span>
1249+
</div>
1250+
}
1251+
>
1252+
<Icon
1253+
style={{
1254+
cursor: 'pointer',
1255+
marginLeft: '4px'
1256+
}}
1257+
name="question-circle"
1258+
/>
1259+
</Tooltip>
1260+
</div>
12411261
</InlineField>
12421262
</>
12431263
) : null}

deepflow-querier-datasource/src/consts.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export type FormTypes = keyof typeof formItemConfigs
125125

126126
export type BasicDataWithId = BasicData & { uuid: string }
127127

128-
export type ShowMetricsVal = 1 | 0
128+
export type ShowMetricsVal = -1 | 1 | 0
129129
export type QueryDataType = {
130130
appType: string
131131
db: string
@@ -199,12 +199,16 @@ export const defaultFormData: Omit<QueryDataType, 'appType' | 'db' | 'sources'>
199199
offset: '',
200200
formatAs: 'timeSeries',
201201
alias: '',
202-
showMetrics: 0
202+
showMetrics: -1
203203
}
204204

205205
export const ID_PREFIX = 'id-'
206206

207207
export const showMetricsOpts: SelectOpts = [
208+
{
209+
label: 'auto',
210+
value: -1
211+
},
208212
{
209213
label: 'true',
210214
value: 1

deepflow-querier-datasource/src/datasource.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
284284
})
285285
.join(',')
286286

287+
let _showMetrics: boolean
288+
switch (queryData.showMetrics) {
289+
case 0:
290+
_showMetrics = false
291+
break
292+
case 1:
293+
_showMetrics = true
294+
break
295+
case -1:
296+
default:
297+
_showMetrics = returnMetrics.length > 1
298+
break
299+
}
287300
const frame = new MutableDataFrame({
288301
refId: target.refId,
289302
fields: [
@@ -302,7 +315,7 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
302315
}
303316
}
304317
return {
305-
name: [keyPrefix || '*', ...(queryData.showMetrics ? [key] : [])].join('-'),
318+
name: [keyPrefix || '*', ...(_showMetrics ? [key] : [])].join('-'),
306319
type: type
307320
}
308321
})
@@ -313,7 +326,7 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
313326
const e = _.cloneDeep(_e)
314327
_.forIn(e, (val, key) => {
315328
if (returnMetricNames.includes(key)) {
316-
const keyName = [keyPrefix || '*', ...(queryData.showMetrics ? [key] : [])].join('-')
329+
const keyName = [keyPrefix || '*', ...(_showMetrics ? [key] : [])].join('-')
317330
e[keyName] = val
318331
}
319332
})

0 commit comments

Comments
 (0)