Skip to content

Commit

Permalink
[APM] Show JVM tab for Java Otel agent (#102346)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Jun 17, 2021
1 parent 9569fe0 commit d57ffce
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 54 deletions.
7 changes: 7 additions & 0 deletions x-pack/plugins/apm/common/agent_name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ describe('agent name helpers', () => {
expect(isJavaAgentName('java')).toEqual(true);
});
});

describe('when the agent name is opentelemetry/java', () => {
it('returns true', () => {
expect(isJavaAgentName('opentelemetry/java')).toEqual(true);
});
});

describe('when the agent name is not java', () => {
it('returns true', () => {
expect(isJavaAgentName('not java')).toEqual(false);
Expand Down
26 changes: 20 additions & 6 deletions x-pack/plugins/apm/common/agent_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,34 @@ export const AGENT_NAMES: AgentName[] = [
...OPEN_TELEMETRY_AGENT_NAMES,
];

export const JAVA_AGENT_NAMES: AgentName[] = ['java', 'opentelemetry/java'];

export function isJavaAgentName(
agentName?: string
): agentName is 'java' | 'opentelemetry/java' {
return JAVA_AGENT_NAMES.includes(agentName! as AgentName);
}

export const RUM_AGENT_NAMES: AgentName[] = [
'js-base',
'rum-js',
'opentelemetry/webjs',
];

export function isJavaAgentName(
agentName: string | undefined
): agentName is 'java' {
return agentName === 'java';
}

export function isRumAgentName(
agentName?: string
): agentName is 'js-base' | 'rum-js' | 'opentelemetry/webjs' {
return RUM_AGENT_NAMES.includes(agentName! as AgentName);
}

export function normalizeAgentName(agentName: string | undefined) {
if (isRumAgentName(agentName)) {
return 'rum-js';
}

if (isJavaAgentName(agentName)) {
return 'java';
}

return agentName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@ const examples = {
dotnet: 'dotnet',
erlang: 'erlang',
go: 'go',
java: 'java',
'js-base': 'rum',
nodejs: 'nodejs',
ocaml: 'ocaml',
'opentelemetry/cpp': 'opentelemetry',
'opentelemetry/dotnet': 'dotnet',
'opentelemetry/erlang': 'erlang',
'opentelemetry/go': 'go',
'opentelemetry/java': 'java',
'opentelemetry/nodejs': 'nodejs',
'opentelemetry/php': 'php',
'opentelemetry/python': 'python',
'opentelemetry/ruby': 'ruby',
'opentelemetry/webjs': 'rum',
otlp: 'opentelemetry',
php: 'php',
python: 'python',
ruby: 'ruby',
'rum-js': 'rum',
rust: 'rust',
'something else': undefined,

// Java agents
java: 'java',
'opentelemetry/java': 'java',

// RUM agents
'js-base': 'rum',
'opentelemetry/webjs': 'rum',
'rum-js': 'rum',
};

describe('getAgentIconKey', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import {
isRumAgentName,
isJavaAgentName,
OPEN_TELEMETRY_AGENT_NAMES,
RUM_AGENT_NAMES,
} from '../../../../common/agent_name';
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
import defaultIcon from '../span_icon/icons/default.svg';
Expand Down Expand Up @@ -60,10 +61,15 @@ export function getAgentIconKey(agentName: string) {
const lowercasedAgentName = agentName.toLowerCase();

// RUM agent names
if (RUM_AGENT_NAMES.includes(lowercasedAgentName as AgentName)) {
if (isRumAgentName(lowercasedAgentName)) {
return 'rum';
}

// Java agent names
if (isJavaAgentName(lowercasedAgentName)) {
return 'java';
}

// Remove "opentelemetry/" prefix
const agentNameWithoutPrefix = lowercasedAgentName.replace(
/^opentelemetry\//,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../../../../../common/elasticsearch_fieldnames';
import { getBucketSize } from '../../../../helpers/get_bucket_size';
import { getVizColorForIndex } from '../../../../../../common/viz_colors';
import { JAVA_AGENT_NAMES } from '../../../../../../common/agent_name';

export async function fetchAndTransformGcMetrics({
environment,
Expand Down Expand Up @@ -65,7 +66,7 @@ export async function fetchAndTransformGcMetrics({
filter: [
...projection.body.query.bool.filter,
{ exists: { field: fieldName } },
{ term: { [AGENT_NAME]: 'java' } },
{ terms: { [AGENT_NAME]: JAVA_AGENT_NAMES } },
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { Setup, SetupTimeRange } from '../../../../helpers/setup_request';
import { fetchAndTransformMetrics } from '../../../fetch_and_transform_metrics';
import { ChartBase } from '../../../types';
import { JAVA_AGENT_NAMES } from '../../../../../../common/agent_name';

const series = {
heapMemoryUsed: {
Expand Down Expand Up @@ -78,7 +79,7 @@ export function getHeapMemoryChart({
},
heapMemoryUsed: { avg: { field: METRIC_JAVA_HEAP_MEMORY_USED } },
},
additionalFilters: [{ term: { [AGENT_NAME]: 'java' } }],
additionalFilters: [{ terms: { [AGENT_NAME]: JAVA_AGENT_NAMES } }],
operationName: 'get_heap_memory_charts',
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { Setup, SetupTimeRange } from '../../../../helpers/setup_request';
import { ChartBase } from '../../../types';
import { fetchAndTransformMetrics } from '../../../fetch_and_transform_metrics';
import { JAVA_AGENT_NAMES } from '../../../../../../common/agent_name';

const series = {
nonHeapMemoryUsed: {
Expand Down Expand Up @@ -77,7 +78,7 @@ export async function getNonHeapMemoryChart({
avg: { field: METRIC_JAVA_NON_HEAP_MEMORY_USED },
},
},
additionalFilters: [{ term: { [AGENT_NAME]: 'java' } }],
additionalFilters: [{ terms: { [AGENT_NAME]: JAVA_AGENT_NAMES } }],
operationName: 'get_non_heap_memory_charts',
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Setup, SetupTimeRange } from '../../../../helpers/setup_request';
import { ChartBase } from '../../../types';
import { fetchAndTransformMetrics } from '../../../fetch_and_transform_metrics';
import { JAVA_AGENT_NAMES } from '../../../../../../common/agent_name';

const series = {
threadCount: {
Expand Down Expand Up @@ -64,7 +65,7 @@ export async function getThreadCountChart({
threadCount: { avg: { field: METRIC_JAVA_THREAD_COUNT } },
threadCountMax: { max: { field: METRIC_JAVA_THREAD_COUNT } },
},
additionalFilters: [{ term: { [AGENT_NAME]: 'java' } }],
additionalFilters: [{ terms: { [AGENT_NAME]: JAVA_AGENT_NAMES } }],
operationName: 'get_thread_count_charts',
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ interface Filter {
term?: {
[key: string]: string;
};
terms?: {
[key: string]: string[];
};
}

export async function fetchAndTransformMetrics<T extends MetricAggs>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getJavaMetricsCharts } from './by_agent/java';
import { getDefaultMetricsCharts } from './by_agent/default';
import { GenericMetricsChart } from './transform_metrics_chart';
import { isJavaAgentName } from '../../../common/agent_name';

export interface MetricsChartsByAgentAPIResponse {
charts: GenericMetricsChart[];
Expand All @@ -29,24 +30,20 @@ export async function getMetricsChartDataByAgent({
serviceNodeName?: string;
agentName: string;
}): Promise<MetricsChartsByAgentAPIResponse> {
switch (agentName) {
case 'java': {
return getJavaMetricsCharts({
environment,
kuery,
setup,
serviceName,
serviceNodeName,
});
}

default: {
return getDefaultMetricsCharts({
environment,
kuery,
setup,
serviceName,
});
}
if (isJavaAgentName(agentName)) {
return getJavaMetricsCharts({
environment,
kuery,
setup,
serviceName,
serviceNodeName,
});
}

return getDefaultMetricsCharts({
environment,
kuery,
setup,
serviceName,
});
}

0 comments on commit d57ffce

Please sign in to comment.