Skip to content

Commit

Permalink
[8.17] [Inventory][ECO] APM url generated with invalid environment (e…
Browse files Browse the repository at this point in the history
…lastic#200987) (elastic#201089)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Inventory][ECO] APM url generated with invalid environment
(elastic#200987)](elastic#200987)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cauê
Marcondes","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-21T09:15:04Z","message":"[Inventory][ECO]
APM url generated with invalid environment (elastic#200987)\n\ncloses
https://github.com/elastic/kibana/issues/200913\r\n\r\nThe service
environment can be `null`, when that's the case we should\r\nnot pass it
to the service locator, we must instead pass `undefined`.\r\n\r\n<img
width=\"1238\" alt=\"Screenshot 2024-11-20 at 16 26
18\"\r\nsrc=\"https://github.com/user-attachments/assets/ced1f3c2-b7e2-4acf-8d87-4e4caa01095c\">","sha":"dde84ef67cd14c585c359011e51ed0a05a82bfa4","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","v8.17.0"],"title":"[Inventory][ECO]
APM url generated with invalid
environment","number":200987,"url":"https://github.com/elastic/kibana/pull/200987","mergeCommit":{"message":"[Inventory][ECO]
APM url generated with invalid environment (elastic#200987)\n\ncloses
https://github.com/elastic/kibana/issues/200913\r\n\r\nThe service
environment can be `null`, when that's the case we should\r\nnot pass it
to the service locator, we must instead pass `undefined`.\r\n\r\n<img
width=\"1238\" alt=\"Screenshot 2024-11-20 at 16 26
18\"\r\nsrc=\"https://github.com/user-attachments/assets/ced1f3c2-b7e2-4acf-8d87-4e4caa01095c\">","sha":"dde84ef67cd14c585c359011e51ed0a05a82bfa4"}},"sourceBranch":"main","suggestedTargetBranches":["8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200987","number":200987,"mergeCommit":{"message":"[Inventory][ECO]
APM url generated with invalid environment (elastic#200987)\n\ncloses
https://github.com/elastic/kibana/issues/200913\r\n\r\nThe service
environment can be `null`, when that's the case we should\r\nnot pass it
to the service locator, we must instead pass `undefined`.\r\n\r\n<img
width=\"1238\" alt=\"Screenshot 2024-11-20 at 16 26
18\"\r\nsrc=\"https://github.com/user-attachments/assets/ced1f3c2-b7e2-4acf-8d87-4e4caa01095c\">","sha":"dde84ef67cd14c585c359011e51ed0a05a82bfa4"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Nov 21, 2024
1 parent 78f7d73 commit b1934ec
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface BuiltinEntityMap {
container: InventoryEntity & { cloud?: { provider?: string[] } };
service: InventoryEntity & {
agent?: { name: AgentName[] };
service?: { environment?: string };
service?: { environment?: string | string[] | null };
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { apm, entities, log, timerange } from '@kbn/apm-synthtrace-client';
import { generateLongIdWithSeed } from '@kbn/apm-synthtrace-client/src/lib/utils/generate_id';

const SYNTH_NODE_TRACES_LOGS_ENTITY_ID = generateLongIdWithSeed('service');
const SERVICE_LOGS_ONLY_ENTITY_ID = generateLongIdWithSeed('service-logs-only');
const HOST_SERVER_1_LOGS_ENTITY_ID = generateLongIdWithSeed('host');
const CONTAINER_ID_METRICS_ENTITY_ID = generateLongIdWithSeed('container');

const SYNTH_NODE_TRACE_LOGS = 'synth-node-trace-logs';
const SERVICE_LOGS_ONLY = 'service-logs-only';
const HOST_NAME = 'server1';
const CONTAINER_ID = 'foo';

Expand All @@ -27,6 +29,13 @@ export function generateEntities({ from, to }: { from: number; to: number }) {
entityId: SYNTH_NODE_TRACES_LOGS_ENTITY_ID,
});

const serviceLogsOnly = entities.serviceEntity({
serviceName: SERVICE_LOGS_ONLY,
agentName: ['host'],
dataStreamType: ['logs'],
entityId: SERVICE_LOGS_ONLY_ENTITY_ID,
});

const hostServer1Logs = entities.hostEntity({
hostName: HOST_NAME,
agentName: ['nodejs'],
Expand All @@ -49,6 +58,7 @@ export function generateEntities({ from, to }: { from: number; to: number }) {
.generator((timestamp) => {
return [
serviceSynthNodeTracesLogs.timestamp(timestamp),
serviceLogsOnly.timestamp(timestamp),
hostServer1Logs.timestamp(timestamp),
containerMetrics.timestamp(timestamp),
];
Expand Down Expand Up @@ -90,23 +100,43 @@ export function generateLogs({ from, to }: { from: number; to: number }) {
.interval('1m')
.rate(1)
.generator((timestamp) => {
return Array(3)
.fill(0)
.map(() => {
const index = Math.floor(Math.random() * 3);
const logMessage = MESSAGE_LOG_LEVELS[index];
return [
...Array(3)
.fill(0)
.map(() => {
const index = Math.floor(Math.random() * 3);
const logMessage = MESSAGE_LOG_LEVELS[index];

return log
.create({ isLogsDb: false })
.service(SYNTH_NODE_TRACE_LOGS)
.message(logMessage.message)
.logLevel(logMessage.level)
.setGeoLocation([1])
.setHostIp('223.72.43.22')
.defaults({
'agent.name': 'nodejs',
})
.timestamp(timestamp);
}),
...Array(3)
.fill(0)
.map(() => {
const index = Math.floor(Math.random() * 3);
const logMessage = MESSAGE_LOG_LEVELS[index];

return log
.create({ isLogsDb: false })
.service(SYNTH_NODE_TRACE_LOGS)
.message(logMessage.message)
.logLevel(logMessage.level)
.setGeoLocation([1])
.setHostIp('223.72.43.22')
.defaults({
'agent.name': 'nodejs',
})
.timestamp(timestamp);
});
return log
.create({ isLogsDb: false })
.service(SERVICE_LOGS_ONLY)
.message(logMessage.message)
.logLevel(logMessage.level)
.setGeoLocation([1])
.setHostIp('223.72.43.22')
.defaults({
'agent.name': 'nodejs',
})
.timestamp(timestamp);
}),
];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ describe('Home page', () => {
cy.url().should('include', '/app/apm/services/synth-node-trace-logs/overview');
});

it('Navigates to apm when clicking on a logs only service', () => {
cy.intercept('GET', '/internal/entities/managed/enablement', {
fixture: 'eem_enabled.json',
}).as('getEEMStatus');
cy.visitKibana('/app/inventory');
cy.wait('@getEEMStatus');
cy.contains('service').click();
cy.contains('service-logs-only').click();
cy.url().should('include', '/app/apm/services/service-logs-only/overview');
cy.contains('Detect and resolve issues faster with deep visibility into your application');
});

it('Navigates to hosts when clicking on a host type entity', () => {
cy.intercept('GET', '/internal/entities/managed/enablement', {
fixture: 'eem_enabled.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export const useDetailViewRedirect = () => {
if (isBuiltinEntityOfType('service', entity)) {
return serviceOverviewLocator?.getRedirectUrl({
serviceName: identityFieldsValue[identityFields[0]],
environment: entity.service?.environment,
environment: entity.service?.environment
? castArray(entity.service?.environment)[0]
: undefined,
});
}

Expand Down

0 comments on commit b1934ec

Please sign in to comment.