Skip to content

Commit

Permalink
Metrics api events (#1214)
Browse files Browse the repository at this point in the history
* Add schema to router in events

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* update Saved Visualization in backend to include metrics

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* add SelectedLabels class

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* Add Token class in saved visualization

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* update test

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* fix frontend API data

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* update default subtype state to viz

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* disabling labels on front end

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* remove console.log comments

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* remove logger comments

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>
  • Loading branch information
kavithacm authored Nov 1, 2022
1 parent 4d99688 commit e64628d
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Search bar', () => {
const popoverItems = jest.fn();
const isLiveTailOn = jest.fn();
const countDistribution = jest.fn();
const setMetricLabel = jest.fn();
const utils = render(
<Search
key="search-component"
Expand Down Expand Up @@ -61,6 +62,11 @@ describe('Search bar', () => {
popoverItems={popoverItems}
isLiveTailOn={isLiveTailOn}
countDistribution={countDistribution}
curVisId={'line'}
spanValue={false}
setSubType={'metric'}
setMetricMeasure={'hours (h)'}
setMetricLabel={setMetricLabel}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export const Search = (props: any) => {
searchError = null,
curVisId,
spanValue,
setSubType,
setMetricMeasure,
setMetricLabel,
} = props;

const appLogEvents = tabId.match(APP_ANALYTICS_TAB_ID_REGEX);
Expand Down Expand Up @@ -216,9 +219,13 @@ export const Search = (props: any) => {
showOptionList={
showSavePanelOptionsList &&
searchBarConfigs[selectedSubTabId]?.showSavePanelOptionsList

}
curVisId={curVisId}
spanValue={spanValue}
setSubType={setSubType}
setMetricMeasure={setMetricMeasure}
setMetricLabel={setMetricLabel}
/>
<EuiPopoverFooter>
<EuiFlexGroup justifyContent="flexEnd">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export const Explorer = ({
false
);
const [spanValue, setSpanValue] = useState(false);
const [subType, setSubType] = useState('visualization');
const [metricMeasure, setMetricMeasure] = useState('');
const [metricLabel, setMetricLabel] = useState([]);
const queryRef = useRef();
const appBasedRef = useRef('');
appBasedRef.current = appBaseQuery;
Expand Down Expand Up @@ -1107,6 +1110,9 @@ export const Explorer = ({
? JSON.stringify(userVizConfigs[curVisId])
: JSON.stringify({}),
description: vizDescription,
subType: subType,
unitsOfMeasure: metricMeasure,
// selectedLabels: metricLabel
})
.then((res: any) => {
setToast(
Expand Down Expand Up @@ -1141,6 +1147,9 @@ export const Explorer = ({
? JSON.stringify(userVizConfigs[curVisId])
: JSON.stringify({}),
description: vizDescription,
subType: subType,
unitsOfMeasure: metricMeasure,
// selectedLabels: metricLabel
})
.then((res: any) => {
batch(() => {
Expand Down Expand Up @@ -1342,6 +1351,9 @@ export const Explorer = ({
searchError={explorerVisualizations}
curVisId={curVisId}
spanValue={spanValue}
setSubType={setSubType}
setMetricMeasure={setMetricMeasure}
setMetricLabel={setMetricLabel}
/>
<EuiTabbedContent
className="mainContentTabs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Saved query table component', () => {
it('Renders saved query table', async () => {
const handleNameChange = jest.fn();
const handleOptionChange = jest.fn();
const setMetricLabel = jest.fn();
const savedObjects = new SavedObjects(httpClientMock);

const wrapper = mount(
Expand All @@ -28,7 +29,12 @@ describe('Saved query table component', () => {
savedObjects={savedObjects}
savePanelName={'Count by depature'}
showOptionList={true}
/>
curVisId={'line'}
spanValue={false}
setSubType={'metric'}
setMetricMeasure={'hours (h)'}
setMetricLabel={setMetricLabel}
/>
);

wrapper.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface ISavedPanelProps {
showOptionList: boolean;
curVisId: string;
spanValue: boolean;
setSubType: any;
setMetricMeasure: any;
setMetricLabel: any;
}

interface CustomPanelOptions {
Expand All @@ -45,6 +48,9 @@ export const SavePanel = ({
showOptionList,
curVisId,
spanValue,
setSubType,
setMetricMeasure,
setMetricLabel,
}: ISavedPanelProps) => {
const [options, setOptions] = useState([]);
const [checked, setChecked] = useState(false);
Expand All @@ -67,14 +73,21 @@ export const SavePanel = ({

const onToggleChange = (e: { target: { checked: React.SetStateAction<boolean> } }) => {
setChecked(e.target.checked);
if (e.target.checked) {
setSubType("metric")
} else {
setSubType("visualization")
}
};

const onMeasureChange = (selectedMeasures: React.SetStateAction<never[]>) => {
setMeasure(selectedMeasures);
setMetricMeasure(selectedMeasures[0].label);
};

const onLabelChange = (selectedLabels: React.SetStateAction<never[]>) => {
setLabel(selectedLabels);
setMetricLabel(selectedLabels);
};

return (
Expand Down Expand Up @@ -149,11 +162,11 @@ export const SavePanel = ({
data-test-subj="eventExplorer__metricMeasureSaveComboBox"
/>
</EuiFormRow>
<EuiSpacer size="s" />
{/* <EuiSpacer size="s" />
<EuiTitle size="xxs">
<h3>{'Labels'}</h3>
</EuiTitle>
<EuiFormRow>
</EuiTitle> */}
{/* <EuiFormRow>
<EuiComboBox
placeholder="Select labels"
onChange={onLabelChange}
Expand All @@ -166,7 +179,7 @@ export const SavePanel = ({
isClearable={true}
data-test-subj="eventExplorer__metricLabelSaveComboBox"
/>
</EuiFormRow>
</EuiFormRow> */}
</>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default class SavedObjects {
description = '',
applicationId = '',
userConfigs = '',
subType = '',
unitsOfMeasure = '',
selectedLabels,
}: any) {
const objRequest: any = {
object: {
Expand Down Expand Up @@ -91,6 +94,18 @@ export default class SavedObjects {
objRequest.object.user_configs = userConfigs;
}

if (!isEmpty(subType)) {
objRequest.object.sub_type = subType;
}

if (!isEmpty(unitsOfMeasure)) {
objRequest.object.units_of_measure = unitsOfMeasure;
}

if (!isEmpty(selectedLabels)) {
objRequest.object.selected_labels = selectedLabels;
}

return objRequest;
}

Expand Down Expand Up @@ -167,6 +182,9 @@ export default class SavedObjects {
timestamp: params.timestamp,
userConfigs: params.userConfigs,
description: params.description,
subType: params.subType,
unitsOfMeasure: params.unitsOfMeasure,
selectedLabels: params.selectedLabels
});

finalParams.object_id = params.objectId;
Expand Down Expand Up @@ -227,6 +245,9 @@ export default class SavedObjects {
applicationId: params.applicationId,
userConfigs: params.userConfigs,
description: params.description,
subType: params.subType,
unitsOfMeasure: params.unitsOfMeasure,
selectedLabels: params.selectedLabels
});

return await this.http.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ export const registerEventAnalyticsRouter = ({
description: schema.string(),
application_id: schema.maybe(schema.string()),
user_configs: schema.string(),
sub_type: schema.string(),
units_of_measure: schema.maybe(schema.string()),
selected_labels: schema.maybe(schema.object({
label: schema.arrayOf(schema.object({}, { unknowns: 'allow' })),
})),
}),
}),
},
Expand Down Expand Up @@ -226,6 +231,11 @@ export const registerEventAnalyticsRouter = ({
description: schema.string(),
application_id: schema.maybe(schema.string()),
user_configs: schema.string(),
sub_type: schema.string(),
units_of_measure: schema.maybe(schema.string()),
selected_labels: schema.maybe(schema.object({
labels: schema.arrayOf(schema.object({}, { unknowns: 'allow' })),
})),
}),
}),
},
Expand Down
2 changes: 1 addition & 1 deletion opensearch-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
buildscript {
ext {
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
opensearch_version = System.getProperty("opensearch.version", "2.2.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "2.4.0-SNAPSHOT")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
Expand Down
Loading

0 comments on commit e64628d

Please sign in to comment.