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

Show metrics in events homepage #1232

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
2 changes: 1 addition & 1 deletion dashboards-observability/common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const TAB_CHART_ID_TXT_PFX = 'main-content-vis-';
export const TAB_EVENT_ID = 'main-content-events';
export const TAB_CHART_ID = 'main-content-vis';
export const HAS_SAVED_TIMESTAMP = 'hasSavedTimestamp';
export const FILTER_OPTIONS = ['Visualization', 'Query'];
export const FILTER_OPTIONS = ['Visualization', 'Query', 'Metric'];
export const SAVED_QUERY = 'savedQuery';
export const SAVED_VISUALIZATION = 'savedVisualization';
export const SAVED_OBJECT_ID = 'savedObjectId';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Saved query table component Renders saved query table 1`] = `
<SavePanel
curVisId="line"
handleNameChange={[MockFunction]}
handleOptionChange={[MockFunction]}
savePanelName="Count by depature"
Expand Down Expand Up @@ -32,7 +33,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
},
]
}
setMetricLabel={[MockFunction]}
setMetricMeasure="hours (h)"
setSubType="metric"
showOptionList={true}
spanValue={false}
>
<EuiTitle
size="xxs"
Expand Down Expand Up @@ -701,5 +706,84 @@ exports[`Saved query table component Renders saved query table 1`] = `
</div>
</div>
</EuiFormRow>
<EuiFormRow
describedByIds={Array []}
display="columnCompressedSwitch"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
labelType="label"
>
<div
className="euiFormRow euiFormRow--compressed euiFormRow--horizontal euiFormRow--hasSwitch"
id="random_html_id-row"
>
<div
className="euiFormRow__fieldWrapper"
>
<EuiToolTip
content="Only Time Series visualization and a query including stats/span can be saved as Metric"
delay="regular"
id="random_html_id"
onBlur={[Function]}
onFocus={[Function]}
position="top"
>
<span
className="euiToolTipAnchor"
onKeyUp={[Function]}
onMouseOut={[Function]}
onMouseOver={[Function]}
>
<EuiSwitch
checked={false}
compressed={true}
disabled={true}
label="Save as Metric"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
showLabel={true}
>
<div
className="euiSwitch euiSwitch--compressed"
>
<button
aria-checked={false}
aria-labelledby="random_html_id"
className="euiSwitch__button"
disabled={true}
id="random_html_id"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
role="switch"
type="button"
>
<span
className="euiSwitch__body"
>
<span
className="euiSwitch__thumb"
/>
<span
className="euiSwitch__track"
/>
</span>
</button>
<span
className="euiSwitch__label"
id="random_html_id"
onClick={[Function]}
>
Save as Metric
</span>
</div>
</EuiSwitch>
</span>
</EuiToolTip>
</div>
</div>
</EuiFormRow>
</SavePanel>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
EuiSpacer,
EuiFieldText,
EuiSwitch,
EuiIconTip,
EuiFlexItem,
EuiToolTip
} from '@elastic/eui';
import { useEffect } from 'react';
import { isEmpty, isEqual } from 'lodash';
Expand Down Expand Up @@ -130,17 +133,21 @@ export const SavePanel = ({
data-test-subj="eventExplorer__querySaveName"
/>
</EuiFormRow>
{showOptionList && (isEqual(curVisId, 'line')) && spanValue && (
{showOptionList && (
<>
<EuiFormRow display="columnCompressedSwitch">
<EuiToolTip
content="Only Time Series visualization and a query including stats/span can be saved as Metric" >
<EuiSwitch
showLabel={true}
label="Save as Metric"
checked={checked}
onChange={onToggleChange}
compressed
disabled = {!((isEqual(curVisId, 'line')) && spanValue)}
/>
</EuiFormRow>
</EuiToolTip>
</EuiFormRow>
{checked && (
<>
<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -194,6 +199,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -337,6 +347,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
},
Expand Down Expand Up @@ -384,6 +399,11 @@ exports[`Saved query table component Renders saved query table 1`] = `
"value": "Query",
"view": "Query",
},
Object {
"name": "Metric",
"value": "Metric",
"view": "Metric",
},
],
"type": "field_value_selection",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { useState, useRef } from 'react';
import { EuiLink, EuiInMemoryTable, EuiIcon } from '@elastic/eui';
import { FILTER_OPTIONS } from '../../../../common/constants/explorer';
import { isEmpty } from 'lodash';

interface savedQueryTableProps {
savedHistories: Array<any>;
Expand Down Expand Up @@ -86,6 +87,14 @@ export function SavedQueryTable({
const isSavedVisualization = h.hasOwnProperty('savedVisualization');
const savedObject = isSavedVisualization ? h.savedVisualization : h.savedQuery;
const curType = isSavedVisualization ? 'savedVisualization' : 'savedQuery';
var subType = '';
if (isSavedVisualization) {
if (savedObject?.sub_type === 'metric') {
subType = 'Metric'
} else {
subType = savedObject?.sub_type;
}
}
const record = {
objectId: h.objectId,
objectType: curType,
Expand All @@ -100,7 +109,7 @@ export function SavedQueryTable({
id: h.objectId,
data: record,
name: savedObject.name,
type: isSavedVisualization ? 'Visualization' : 'Query',
type: isSavedVisualization ? (!isEmpty(subType)) ? subType: 'Visualization' : 'Query',
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ internal class SavedVisualizationTests {
"KE1Ie34BbsTr-CsB4G6Y",
"{\"dataConfig\":\"{}\",\"layoutConfig\":\"{}\"}",
"metric",
"hours (h)",
SavedVisualization.SelectedLabels(
listOf(SavedVisualization.Token("avg"))
)
"hours (h)"
)

@Test
Expand All @@ -54,7 +51,7 @@ internal class SavedVisualizationTests {
@Test
fun `SavedVisualization should deserialize json object using parser`() {
val jsonString =
"{\"name\":\"test-saved-visualization\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"type\":\"bar\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\",\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\",\"labels\":[{\"label\":\"avg\"}]}"
"{\"name\":\"test-saved-visualization\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"type\":\"bar\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\",\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { SavedVisualization.parse(it) }
assertEquals(sampleSavedVisualization, recreatedObject)
}
Expand All @@ -70,7 +67,7 @@ internal class SavedVisualizationTests {
@Test
fun `SavedVisualization should safely ignore extra field in json object`() {
val jsonString =
"{\"name\":\"test-saved-visualization\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"type\":\"bar\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\",\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\",\"labels\":[{\"label\":\"avg\"}]}"
"{\"name\":\"test-saved-visualization\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"type\":\"bar\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\",\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { SavedVisualization.parse(it) }
assertEquals(sampleSavedVisualization, recreatedObject)
}
Expand Down