Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Revert to traceGroup from traceGroupFields (#37)
Browse files Browse the repository at this point in the history
* Revert "Add null check for service map, fix percentile filter (#35)"

This reverts commit 126c3db.

* Revert "Merge pull request #34 from wrijeff/main"

This reverts commit 66a9dcc, reversing
changes made to 1cfd7b0.

* Revert "Merge pull request #33 from wrijeff/main"

This reverts commit 1cfd7b0, reversing
changes made to e914162.

* pick: Merge pull request #34 from wrijeff/main

Fixed getTracesQuery, was returning 0 unexpectedly.

* Add null check for service map, fix percentile filter (#35)

* Add null check for service map query

* Loop through filters when switching percentile filters

* Add check before changing percentile filter

* Change to traceGroup

Co-authored-by: Jeff Wright <[email protected]>
  • Loading branch information
joshuali925 and wrijeff authored Apr 23, 2021
1 parent 126c3db commit c84ecb4
Show file tree
Hide file tree
Showing 15 changed files with 559 additions and 559 deletions.
4 changes: 2 additions & 2 deletions .cypress/integration/dashboard.spec.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ describe('Testing dashboard table', () => {

cy.get('h2.euiTitle').contains('Traces').should('exist');
cy.contains(' (7)').should('exist');
cy.contains('traceGroup: HTTP GET').should('exist');
cy.contains('traceGroup.name: HTTP GET').should('exist');

cy.get('.euiSideNavItemButton__label').contains('Dashboard').click();
cy.wait(delay);

cy.contains('traceGroup: HTTP GET').should('exist');
cy.contains('traceGroup.name: HTTP GET').should('exist');
});
});

Expand Down
1,024 changes: 512 additions & 512 deletions .cypress/utils/otel-v1-apm-span-000001.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions public/components/common/__tests__/helper_functions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ describe('Helper functions', () => {
);
expect(DSL).toEqual(
JSON.parse(
`{"field":"Latency percentile within trace group","operator":"","value":">= 95th","inverted":false,"disabled":false,"custom":{"query":{"bool":{"must":[],"filter":[],"should":[{"bool":{"must":[{"term":{"traceGroup":{"value":"order"}}},{"range":{"traceGroupFields.durationInNanos":{"gte":1000}}}]}}],"must_not":[],"minimum_should_match":1}}}}`
`{"field":"Latency percentile within trace group","operator":"","value":">= 95th","inverted":false,"disabled":false,"custom":{"query":{"bool":{"must":[],"filter":[],"should":[{"bool":{"must":[{"term":{"traceGroup.name":{"value":"order"}}},{"range":{"traceGroup.durationInNanos":{"gte":1000}}}]}}],"must_not":[],"minimum_should_match":1}}}}`
)
);
});

it('converts filters to DSL', () => {
const getTestFilters = (field = 'traceGroup', operator = 'exists') => [
const getTestFilters = (field = 'traceGroup.name', operator = 'exists') => [
[
{
field,
Expand All @@ -139,12 +139,12 @@ describe('Helper functions', () => {
];
const existsDSL = filtersToDsl(...getTestFilters());
expect(JSON.stringify(existsDSL)).toEqual(
"{\"query\":{\"bool\":{\"must\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}},{\"query_string\":{\"query\":\"order\"}},{\"exists\":{\"field\":\"traceGroup\"}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"custom\":{\"timeFilter\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}}],\"serviceNames\":[],\"serviceNamesExclude\":[],\"traceGroup\":[],\"traceGroupExclude\":[],\"percentiles\":{\"query\":{\"bool\":{\"should\":[]}}}}}"
"{\"query\":{\"bool\":{\"must\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}},{\"query_string\":{\"query\":\"order\"}},{\"exists\":{\"field\":\"traceGroup.name\"}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"custom\":{\"timeFilter\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}}],\"serviceNames\":[],\"serviceNamesExclude\":[],\"traceGroup\":[],\"traceGroupExclude\":[],\"percentiles\":{\"query\":{\"bool\":{\"should\":[]}}}}}"
);

const isDSL = filtersToDsl(...getTestFilters('traceGroup', 'is'));
const isDSL = filtersToDsl(...getTestFilters('traceGroup.name', 'is'));
expect(JSON.stringify(isDSL)).toEqual(
"{\"query\":{\"bool\":{\"must\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}},{\"query_string\":{\"query\":\"order\"}},{\"term\":{\"traceGroup\":{\"from\":\"100\",\"to\":\"∞\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"custom\":{\"timeFilter\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}}],\"serviceNames\":[],\"serviceNamesExclude\":[],\"traceGroup\":[],\"traceGroupExclude\":[],\"percentiles\":{\"query\":{\"bool\":{\"should\":[]}}}}}"
"{\"query\":{\"bool\":{\"must\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}},{\"query_string\":{\"query\":\"order\"}},{\"term\":{\"traceGroup.name\":{\"from\":\"100\",\"to\":\"∞\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"custom\":{\"timeFilter\":[{\"range\":{\"startTime\":{\"gte\":\"now-5m\",\"lte\":\"now\"}}}],\"serviceNames\":[],\"serviceNamesExclude\":[],\"traceGroup\":[],\"traceGroupExclude\":[],\"percentiles\":{\"query\":{\"bool\":{\"should\":[]}}}}}"
);
const isBetweenDSL = filtersToDsl(...getTestFilters('durationInNanos', 'is between'));
expect(JSON.stringify(isBetweenDSL)).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Filter popover component renders filter popover 1`] = `
filterFieldOptions={
Array [
Object {
"label": "traceGroup",
"label": "traceGroup.name",
},
Object {
"label": "serviceName",
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`Filter popover component renders filter popover 1`] = `
options={
Array [
Object {
"label": "traceGroup",
"label": "traceGroup.name",
},
Object {
"label": "serviceName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Filter popover component', () => {
wrapper
.find('input')
.at(0)
.simulate('change', [{ label: 'traceGroup' }]);
.simulate('change', [{ label: 'traceGroup.name' }]);
wrapper
.find('input')
.at(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Filter helper functions', () => {
it('returns fields by page', () => {
const fields = getFilterFields('dashboard');
expect(fields).toEqual([
'traceGroup',
'traceGroup.name',
'serviceName',
'error',
'status.message',
Expand All @@ -41,15 +41,15 @@ describe('Filter helper functions', () => {
const dashboardFields = getValidFilterFields('dashboard');
const servicesFields = getValidFilterFields('services');
expect(dashboardFields).toEqual([
'traceGroup',
'traceGroup.name',
'serviceName',
'error',
'status.message',
'latency',
'Latency percentile within trace group',
]);
expect(servicesFields).toEqual([
'traceGroup',
'traceGroup.name',
'serviceName',
'error',
'status.message',
Expand Down
6 changes: 3 additions & 3 deletions public/components/common/filters/filter_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import React from 'react';

const getFields = (page: 'dashboard' | 'traces' | 'services') =>
({
dashboard: ['traceGroup', 'serviceName', 'error', 'status.message', 'latency'],
traces: ['traceId', 'traceGroup', 'serviceName', 'error', 'status.message', 'latency'],
services: ['traceGroup', 'serviceName', 'error', 'status.message', 'latency'],
dashboard: ['traceGroup.name', 'serviceName', 'error', 'status.message', 'latency'],
traces: ['traceId', 'traceGroup.name', 'serviceName', 'error', 'status.message', 'latency'],
services: ['traceGroup.name', 'serviceName', 'error', 'status.message', 'latency'],
}[page]);
// filters will take effect and can be manually added
export const getFilterFields = (page: 'dashboard' | 'traces' | 'services') => getFields(page);
Expand Down
14 changes: 7 additions & 7 deletions public/components/common/helper_functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ export const getPercentileFilter = (
must: [
{
term: {
'traceGroup': {
'traceGroup.name': {
value: map.traceGroupName,
},
},
},
{
range: {
'traceGroupFields.durationInNanos': map.durationFilter,
'traceGroup.durationInNanos': map.durationFilter,
},
},
],
Expand Down Expand Up @@ -344,8 +344,8 @@ export const filtersToDsl = (

let filterQuery = {};
let field = filter.field;
if (field === 'latency') field = 'traceGroupFields.durationInNanos';
else if (field === 'error') field = 'traceGroupFields.statusCode';
if (field === 'latency') field = 'traceGroup.durationInNanos';
else if (field === 'error') field = 'traceGroup.statusCode';
let value;

switch (filter.operator) {
Expand All @@ -362,9 +362,9 @@ export const filtersToDsl = (
case 'is not':
value = filter.value;
// latency and error are not actual fields, need to convert first
if (field === 'traceGroupFields.durationInNanos') {
if (field === 'traceGroup.durationInNanos') {
value = milliToNanoSec(value);
} else if (field === 'traceGroupFields.statusCode') {
} else if (field === 'traceGroup.statusCode') {
value = value[0].label === 'true' ? '2' : '0';
}

Expand All @@ -380,7 +380,7 @@ export const filtersToDsl = (
const range: { gte?: string; lte?: string } = {};
if (!filter.value.from.includes('\u221E')) range.gte = filter.value.from;
if (!filter.value.to.includes('\u221E')) range.lte = filter.value.to;
if (field === 'traceGroupFields.durationInNanos') {
if (field === 'traceGroup.durationInNanos') {
if (range.lte) range.lte = milliToNanoSec(parseInt(range.lte || '')).toString();
if (range.gte) range.gte = milliToNanoSec(parseInt(range.gte || '')).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`Dashboard table component renders dashboard table 1`] = `
Array [
Object {
"disabled": false,
"field": "traceGroup",
"field": "traceGroup.name",
"inverted": false,
"operator": "exists",
"value": "exists",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Dashboard table component', () => {
items={tableItems}
filters={[
{
field: 'traceGroup',
field: 'traceGroup.name',
operator: 'exists',
value: 'exists',
inverted: false,
Expand Down
4 changes: 2 additions & 2 deletions public/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ export function Dashboard(props: DashboardProps) {
const newFilter = JSON.parse(JSON.stringify(props.filters[i]));
newFilter.custom.query.bool.should.forEach((should) =>
should.bool.must.forEach((must) => {
const range = must?.range?.['traceGroupFields.durationInNanos'];
const range = must?.range?.['traceGroup.durationInNanos'];
if (range) {
const duration = range.lt || range.lte || range.gt || range.gte;
if (duration || duration === 0) {
must.range['traceGroupFields.durationInNanos'] = {
must.range['traceGroup.durationInNanos'] = {
[condition]: duration,
};
}
Expand Down
6 changes: 3 additions & 3 deletions public/components/dashboard/dashboard_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function DashboardTable(props: {
data-test-subj="dashboard-table-trace-group-name-button"
onClick={() =>
props.addFilter({
field: 'traceGroup',
field: 'traceGroup.name',
operator: 'is',
value: item,
inverted: false,
Expand Down Expand Up @@ -179,7 +179,7 @@ export function DashboardTable(props: {
currPercentileFilter,
addFilter: (condition?: 'lte' | 'gte') => {
const traceGroupFilter = {
field: 'traceGroup',
field: 'traceGroup.name',
operator: 'is',
value: row.dashboard_trace_group_name,
inverted: false,
Expand Down Expand Up @@ -331,7 +331,7 @@ export function DashboardTable(props: {
onClick={() => {
props.setRedirect(true);
props.addFilter({
field: 'traceGroup',
field: 'traceGroup.name',
operator: 'is',
value: row.dashboard_trace_group_name,
inverted: false,
Expand Down
18 changes: 9 additions & 9 deletions public/requests/queries/dashboard_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getDashboardQuery = () => {
aggs: {
trace_group_name: {
terms: {
field: 'traceGroup',
field: 'traceGroup.name',
size: 10000,
},
aggs: {
Expand All @@ -48,12 +48,12 @@ export const getDashboardQuery = () => {
aggs: {
duration: {
max: {
field: 'traceGroupFields.durationInNanos',
field: 'traceGroup.durationInNanos',
},
},
last_updated: {
max: {
field: 'traceGroupFields.endTime',
field: 'traceGroup.endTime',
},
},
},
Expand Down Expand Up @@ -85,12 +85,12 @@ export const getDashboardQuery = () => {
aggs: {
duration: {
max: {
field: 'traceGroupFields.durationInNanos',
field: 'traceGroup.durationInNanos',
},
},
last_updated: {
max: {
field: 'traceGroupFields.endTime',
field: 'traceGroup.endTime',
},
},
},
Expand All @@ -117,7 +117,7 @@ export const getDashboardQuery = () => {
error_count: {
filter: {
term: {
'traceGroupFields.statusCode': '2',
'traceGroup.statusCode': '2',
},
},
aggs: {
Expand Down Expand Up @@ -166,12 +166,12 @@ export const getDashboardTraceGroupPercentiles = () => {
aggs: {
trace_group: {
terms: {
field: 'traceGroup',
field: 'traceGroup.name',
},
aggs: {
latency_variance_nanos: {
percentiles: {
field: 'traceGroupFields.durationInNanos',
field: 'traceGroup.durationInNanos',
percents: [0, 95, 100],
},
},
Expand Down Expand Up @@ -202,7 +202,7 @@ export const getErrorRatePltQuery = (fixedInterval) => {
error_count: {
filter: {
term: {
'traceGroupFields.statusCode': '2',
'traceGroup.statusCode': '2',
},
},
aggs: {
Expand Down
4 changes: 2 additions & 2 deletions public/requests/queries/services_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ export const getServiceEdgesQuery = (source: 'destination' | 'target') => {
export const getServiceMetricsQuery = (DSL, serviceNames: string[], map: ServiceObject) => {
const traceGroupFilter = new Set(
DSL?.query?.bool.must
.filter((must) => must.term?.['traceGroup'])
.map((must) => must.term['traceGroup']) || []
.filter((must) => must.term?.['traceGroup.name'])
.map((must) => must.term['traceGroup.name']) || []
);

const targetResource =
Expand Down
12 changes: 6 additions & 6 deletions public/requests/queries/traces_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export const getTracesQuery = (traceId = null, sort?: PropertySort) => {
max: {
script: {
source: `
if (doc.containsKey('traceGroupFields.durationInNanos') && !doc['traceGroupFields.durationInNanos'].empty) {
return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0
if (doc.containsKey('traceGroup.durationInNanos') && !doc['traceGroup.durationInNanos'].empty) {
return Math.round(doc['traceGroup.durationInNanos'].value / 10000) / 100.0
}
return 0
Expand All @@ -94,20 +94,20 @@ export const getTracesQuery = (traceId = null, sort?: PropertySort) => {
},
trace_group: {
terms: {
field: 'traceGroup',
field: 'traceGroup.name',
size: 1,
},
},
error_count: {
filter: {
term: {
'traceGroupFields.statusCode': '2',
'traceGroup.statusCode': '2',
},
},
},
last_updated: {
max: {
field: 'traceGroupFields.endTime',
field: 'traceGroup.endTime',
},
},
},
Expand Down Expand Up @@ -258,7 +258,7 @@ export const getValidTraceIdsQuery = (DSL) => {
},
};
if (DSL.custom?.timeFilter.length > 0) query.query.bool.must.push(...DSL.custom.timeFilter);
if (DSL.custom?.traceGroupFields.length > 0) {
if (DSL.custom?.traceGroup.length > 0) {
query.query.bool.filter.push({
terms: {
traceGroup: DSL.custom.traceGroup,
Expand Down

0 comments on commit c84ecb4

Please sign in to comment.