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

[APM] Integrate Alert Search bar in alert tab #149610

Merged
merged 11 commits into from
Jan 27, 2023
19 changes: 16 additions & 3 deletions x-pack/plugins/apm/common/environment_filter_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { escapeKuery } from '@kbn/es-query';
import { SERVICE_ENVIRONMENT } from './es_fields/apm';
import { Environment } from './environment_rt';

Expand Down Expand Up @@ -43,18 +44,30 @@ export const ENVIRONMENT_NOT_DEFINED = {
label: getEnvironmentLabel(ENVIRONMENT_NOT_DEFINED_VALUE),
};

export function getEnvironmentEsField(environment: string) {
if (
function isEnvironmentDefined(environment: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpatticha Shouldn't this be called isEnvironmentUndefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! I fixed it and forgot to push 😢
image

thanks for catching this!, will fix it in a follow-up PR

return (
!environment ||
environment === ENVIRONMENT_NOT_DEFINED_VALUE ||
environment === ENVIRONMENT_ALL_VALUE
) {
);
}

export function getEnvironmentEsField(environment: string) {
if (isEnvironmentDefined(environment)) {
return {};
}

return { [SERVICE_ENVIRONMENT]: environment };
}

export function getEnvironmentKuery(environment: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use it like this:

const environmentValue = getEnvironmentEsField(environment)?.[SERVICE_ENVIRONMENT]

let query = `${SERVICE_NAME}:${serviceName}`;

 if (environmentKuery) {
    // HERE I need to use again `SERVICE_ENVIRONMENT`
      query += ` AND ${SERVICE_ENVIRONMENT}: ${environmentValue}`;
 }

so I thought it might be cleaner to have the function getEnvironmentKuery responsible for returning the kuery

if (isEnvironmentDefined(environment)) {
return null;
}

return `${[SERVICE_ENVIRONMENT]}: ${escapeKuery(environment)} `;
}

// returns the environment url param that should be used
// based on the requested environment. If the requested
// environment is different from the URL parameter, we'll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import url from 'url';
import { synthtrace } from '../../../../synthtrace';
import { opbeans } from '../../../fixtures/synthtrace/opbeans';

const start = '2021-10-10T00:00:00.000Z';
const end = '2021-10-10T00:15:00.000Z';

const serviceOverviewHref = url.format({
pathname: '/app/apm/services/opbeans-java/alerts',
query: { rangeFrom: start, rangeTo: end },
});

describe('Errors table', () => {
before(() => {
synthtrace.index(
opbeans({
from: new Date(start).getTime(),
to: new Date(end).getTime(),
})
);
});

after(() => {
synthtrace.clean();
});

beforeEach(() => {
cy.loginAsViewerUser();
});

it('Alerts table with the search bar is populated', () => {
cy.visitKibana(serviceOverviewHref);
cy.contains('opbeans-java');
cy.contains('All');
cy.contains('Active');
cy.contains('Recovered');
cy.getByTestSubj('globalQueryBar').should('exist');
});
});

This file was deleted.

This file was deleted.

Loading