Skip to content

Commit

Permalink
adding processor event in the query, and refactoring theme
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 25, 2020
1 parent 9a92fae commit 8baaa5e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
7 changes: 5 additions & 2 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
fetchLandingPageData,
hasData,
} from './services/rest/observability_dashboard';
import { getTheme } from './utils/get_theme';

export type ApmPluginSetup = void;
export type ApmPluginStart = void;
Expand Down Expand Up @@ -78,11 +79,13 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);

if (plugins.observability) {
const isDarkMode = core.uiSettings.get('theme:darkMode');
const theme = getTheme({
isDarkMode: core.uiSettings.get('theme:darkMode'),
});
plugins.observability.dashboard.register({
appName: 'apm',
fetchData: async (params) => {
return fetchLandingPageData(params, { isDarkMode });
return fetchLandingPageData(params, { theme });
},
hasData,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import { fetchLandingPageData, hasData } from './observability_dashboard';
import * as createCallApmApi from './createCallApmApi';
import { getTheme } from '../../utils/get_theme';

const theme = getTheme({ isDarkMode: false });

describe('Observability dashboard data', () => {
const callApmApiMock = jest.spyOn(createCallApmApi, 'callApmApi');
Expand Down Expand Up @@ -43,7 +46,7 @@ describe('Observability dashboard data', () => {
endTime: '2',
bucketSize: '3',
},
{ isDarkMode: false }
{ theme }
);
expect(response).toEqual({
title: 'APM',
Expand Down Expand Up @@ -85,7 +88,7 @@ describe('Observability dashboard data', () => {
endTime: '2',
bucketSize: '3',
},
{ isDarkMode: false }
{ theme }
);
expect(response).toEqual({
title: 'APM',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@

import { i18n } from '@kbn/i18n';
import { sum } from 'lodash';
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';
import darkTheme from '@elastic/eui/dist/eui_theme_dark.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FetchDataParams } from '../../../../observability/public/data_handler';
import { ApmFetchDataResponse } from '../../../../observability/public/typings/fetch_data_response';
import { callApmApi } from './createCallApmApi';
import { Theme } from '../../utils/get_theme';

interface Options {
isDarkMode: boolean;
theme: Theme;
}

export const fetchLandingPageData = async (
{ startTime, endTime, bucketSize }: FetchDataParams,
{ isDarkMode }: Options
{ theme }: Options
): Promise<ApmFetchDataResponse> => {
const theme = isDarkMode ? darkTheme : lightTheme;

const data = await callApmApi({
pathname: '/api/apm/observability_dashboard',
params: { query: { start: startTime, end: endTime, bucketSize } },
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/apm/public/utils/get_theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';
import darkTheme from '@elastic/eui/dist/eui_theme_dark.json';

export type Theme = ReturnType<typeof getTheme>;

export function getTheme({ isDarkMode }: { isDarkMode: boolean }) {
return isDarkMode ? darkTheme : lightTheme;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ProcessorEvent } from '../../../common/processor_event';
import { rangeFilter } from '../../../common/utils/range_filter';
import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames';
import {
SERVICE_NAME,
PROCESSOR_EVENT,
} from '../../../common/elasticsearch_fieldnames';
import { Setup, SetupTimeRange } from '../helpers/setup_request';

export async function getServiceCount({
Expand All @@ -23,7 +27,22 @@ export async function getServiceCount({
],
body: {
size: 0,
query: { bool: { filter: [{ range: rangeFilter(start, end) }] } },
query: {
bool: {
filter: [
{ range: rangeFilter(start, end) },
{
terms: {
[PROCESSOR_EVENT]: [
ProcessorEvent.error,
ProcessorEvent.transaction,
ProcessorEvent.metric,
],
},
},
],
},
},
aggs: { serviceCount: { cardinality: { field: SERVICE_NAME } } },
},
};
Expand Down

0 comments on commit 8baaa5e

Please sign in to comment.