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

[8.x] [ObsUX] [APM] [OTel] Runtime metrics show dashboards with different ingest path (#211822) #213373

Merged
merged 1 commit into from
Mar 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ class Otel extends Serializable<OtelDocument> {
},
resource: {
attributes: {
'agent.name': 'otlp',
'agent.name': 'opentelemetry/nodejs',
'agent.version': '1.28.0',
'service.instance.id': '89117ac1-0dbf-4488-9e17-4c2c3b76943a',
'service.name': 'sendotlp-synth',
'metricset.interval': '10m',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.language': 'nodejs',
},
dropped_attributes_count: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export {
AGENT_NAMES,
} from './src/agent_names';

export { getIngestionPath } from './src/agent_ingestion_path';

export { getSdkNameAndLanguage } from './src/agent_sdk_name_and_language';

export type {
ElasticAgentName,
OpenTelemetryAgentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isAndroidAgentName,
isAWSLambdaAgentName,
isAzureFunctionsAgentName,
isElasticAgentName,
isIosAgentName,
isJavaAgentName,
isJRubyAgentName,
Expand Down Expand Up @@ -44,6 +45,17 @@ describe('Agents guards', () => {
expect(isOpenTelemetryAgentName('not-an-agent')).toBe(false);
});

it('isElasticAgentName should guard if the passed agent is an APM agent one.', () => {
expect(isElasticAgentName('nodejs')).toBe(true);
expect(isElasticAgentName('iOS/swift')).toBe(true);
expect(isElasticAgentName('java')).toBe(true);
expect(isElasticAgentName('rum-js')).toBe(true);
expect(isElasticAgentName('android/java')).toBe(true);
expect(isElasticAgentName('node-js')).toBe(false);
expect(isElasticAgentName('opentelemetry/nodejs/elastic')).toBe(false);
expect(isElasticAgentName('not-an-agent')).toBe(false);
});

it('isJavaAgentName should guard if the passed agent is an Java one.', () => {
expect(isJavaAgentName('java')).toBe(true);
expect(isJavaAgentName('otlp/java')).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import {
ANDROID_AGENT_NAMES,
ELASTIC_AGENT_NAMES,
IOS_AGENT_NAMES,
JAVA_AGENT_NAMES,
OPEN_TELEMETRY_AGENT_NAMES,
Expand All @@ -17,13 +18,16 @@ import {

import type {
AndroidAgentName,
ElasticAgentName,
IOSAgentName,
JavaAgentName,
OpenTelemetryAgentName,
RumAgentName,
ServerlessType,
} from './agent_names';

const ElasticAgentNamesSet = new Set(ELASTIC_AGENT_NAMES);

export function getAgentName(
agentName: string | null,
telemetryAgentName: string | null,
Expand Down Expand Up @@ -57,6 +61,9 @@ export function isOpenTelemetryAgentName(agentName: string): agentName is OpenTe
);
}

export const isElasticAgentName = (agentName: string): agentName is ElasticAgentName =>
ElasticAgentNamesSet.has(agentName as ElasticAgentName);

export function isJavaAgentName(agentName?: string): agentName is JavaAgentName {
return (
hasOpenTelemetryPrefix(agentName, 'java') ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const getIngestionPath = (hasOpenTelemetryFields: boolean) =>
hasOpenTelemetryFields ? 'otel_native' : 'classic_apm';
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getSdkNameAndLanguage } from './agent_sdk_name_and_language';

describe('getSdkNameAndLanguage', () => {
it.each([
{
agentName: 'java',
result: { sdkName: 'apm', language: 'java' },
},
{
agentName: 'iOS/swift',
result: { sdkName: 'apm', language: 'iOS/swift' },
},
{
agentName: 'android/java',
result: { sdkName: 'apm', language: 'android/java' },
},
{
agentName: 'opentelemetry/java/test/elastic',
result: { sdkName: 'edot', language: 'java' },
},
{
agentName: 'opentelemetry/java/elastic',
result: { sdkName: 'edot', language: 'java' },
},
{
agentName: 'otlp/nodejs',
result: { sdkName: 'otel_other', language: 'nodejs' },
},
{
agentName: 'otlp',
result: { sdkName: 'otel_other', language: undefined },
},
{
agentName: 'test/test/test/something-else/elastic',
result: { sdkName: undefined, language: undefined },
},
{
agentName: 'test/java/test/something-else/',
result: { sdkName: undefined, language: undefined },
},
{
agentName: 'elastic',
result: { sdkName: undefined, language: undefined },
},
{
agentName: 'my-awesome-agent/otel',
result: { sdkName: undefined, language: undefined },
},
])('for the agent name $agentName returns $result', ({ agentName, result }) => {
expect(getSdkNameAndLanguage(agentName)).toStrictEqual(result);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { isElasticAgentName, isOpenTelemetryAgentName } from './agent_guards';

interface SdkNameAndLanguage {
sdkName?: 'apm' | 'edot' | 'otel_other';
language?: string;
}

const LANGUAGE_INDEX = 1;

export const getSdkNameAndLanguage = (agentName: string): SdkNameAndLanguage => {
if (isElasticAgentName(agentName)) {
return { sdkName: 'apm', language: agentName };
}
const agentNameParts = agentName.split('/');

if (isOpenTelemetryAgentName(agentName)) {
if (agentNameParts[agentNameParts.length - 1] === 'elastic') {
return { sdkName: 'edot', language: agentNameParts[LANGUAGE_INDEX] };
}
return {
sdkName: 'otel_other',
language: agentNameParts[LANGUAGE_INDEX],
};
}

return { sdkName: undefined, language: undefined };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* 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 type { CoreStart } from '@kbn/core/public';
import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public';
import { render } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import React from 'react';
import type { ApmPluginContextValue } from '../../../context/apm_plugin/apm_plugin_context';
import {
MockApmPluginContextWrapper,
mockApmPluginContextValue,
} from '../../../context/apm_plugin/mock_apm_plugin_context';
import * as useApmServiceContext from '../../../context/apm_service/use_apm_service_context';
import type { ServiceEntitySummary } from '../../../context/apm_service/use_service_entity_summary_fetcher';
import * as useApmDataViewHook from '../../../hooks/use_adhoc_apm_data_view';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { fromQuery } from '../../shared/links/url_helpers';
import { Metrics } from '.';
import type { DataView } from '@kbn/data-views-plugin/common';

const KibanaReactContext = createKibanaReactContext({
settings: { client: { get: () => {} } },
} as unknown as Partial<CoreStart>);

function MetricsWithWrapper() {
jest
.spyOn(useApmDataViewHook, 'useAdHocApmDataView')
.mockReturnValue({ dataView: { id: 'id-1', name: 'apm-data-view' } as DataView });

const history = createMemoryHistory();
history.replace({
pathname: '/services/testServiceName/metrics',
search: fromQuery({
rangeFrom: 'now-15m',
rangeTo: 'now',
}),
});

return (
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper
history={history}
value={mockApmPluginContextValue as unknown as ApmPluginContextValue}
>
<Metrics />
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>
);
}

describe('Metrics', () => {
describe('render the correct metrics content for', () => {
describe('APM agent / server service', () => {
beforeEach(() => {
jest.spyOn(useApmServiceContext, 'useApmServiceContext').mockReturnValue({
agentName: 'java',
serviceName: 'testServiceName',
transactionTypeStatus: FETCH_STATUS.SUCCESS,
transactionTypes: [],
fallbackToTransactions: true,
serviceAgentStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummary: {
dataStreamTypes: ['metrics'],
} as unknown as ServiceEntitySummary,
});
});

it('shows java dashboard content', () => {
const result = render(<MetricsWithWrapper />);
// Check that the other content is not rendered as we don't have test id in the dashboard rendering component
const loadingBar = result.queryByRole('progressbar');
expect(loadingBar).toBeNull();
expect(result.queryByTestId('apmMetricsNoDashboardFound')).toBeNull();
expect(result.queryByTestId('apmAddApmCallout')).toBeNull();
});
});

describe('APM agent / EDOT sdk with dashboard', () => {
beforeEach(() => {
jest.spyOn(useApmServiceContext, 'useApmServiceContext').mockReturnValue({
agentName: 'opentelemetry/nodejs/elastic',
serviceName: 'testServiceName',
transactionTypeStatus: FETCH_STATUS.SUCCESS,
transactionTypes: [],
fallbackToTransactions: true,
serviceAgentStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummary: {
dataStreamTypes: ['metrics'],
} as unknown as ServiceEntitySummary,
});
});

it('shows nodejs dashboard content', () => {
const result = render(<MetricsWithWrapper />);
// Check that the other content is not rendered as we don't have test id in the dashboard rendering component
const loadingBar = result.queryByRole('progressbar');
expect(loadingBar).toBeNull();
expect(result.queryByTestId('apmMetricsNoDashboardFound')).toBeNull();
expect(result.queryByTestId('apmAddApmCallout')).toBeNull();
});
});

describe('APM agent / otel sdk with no dashboard', () => {
beforeEach(() => {
jest.spyOn(useApmServiceContext, 'useApmServiceContext').mockReturnValue({
agentName: 'opentelemetry/go',
serviceName: 'testServiceName',
transactionTypeStatus: FETCH_STATUS.SUCCESS,
transactionTypes: [],
fallbackToTransactions: true,
serviceAgentStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummary: {
dataStreamTypes: ['metrics'],
} as unknown as ServiceEntitySummary,
});
});

it('shows "no dashboard found" message', () => {
const result = render(<MetricsWithWrapper />);
const apmMetricsNoDashboardFound = result.getByTestId('apmMetricsNoDashboardFound');
expect(apmMetricsNoDashboardFound).toBeInTheDocument();
});
});

describe('Logs signals', () => {
beforeEach(() => {
jest.spyOn(useApmServiceContext, 'useApmServiceContext').mockReturnValue({
agentName: 'java',
serviceName: 'testServiceName',
transactionTypeStatus: FETCH_STATUS.SUCCESS,
transactionTypes: [],
fallbackToTransactions: true,
serviceAgentStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
serviceEntitySummary: {
dataStreamTypes: ['logs'],
} as unknown as ServiceEntitySummary,
});
});

it('shows service from logs metrics content', () => {
const result = render(<MetricsWithWrapper />);
const apmAddApmCallout = result.getByTestId('apmAddApmCallout');
expect(apmAddApmCallout).toBeInTheDocument();
});
});
});
});
Loading