Skip to content

Commit

Permalink
[Logs onboarding] Using logsSynthtrace in api integration tests (#171510
Browse files Browse the repository at this point in the history
)

This is a follow up PR coming from
#170124 (comment).

### Changes
- Removed `createLogDoc` in favor of `LogsSynthtraceEsClient`.
- Added `agent.id` as `LogDoc` known property.
  • Loading branch information
yngrdyn authored Nov 20, 2023
1 parent 6e46756 commit 75dc0c1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 143 deletions.
1 change: 1 addition & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type LogDocument = Fields &
'log.level'?: string;
'host.name'?: string;
'trace.id'?: string;
'agent.id'?: string;
'agent.name'?: string;
'orchestrator.cluster.name'?: string;
'orchestrator.cluster.id'?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createObservabilityOnboardingUsers } from '@kbn/observability-onboardin
import { FtrConfigProviderContext } from '@kbn/test';
import supertest from 'supertest';
import { format, UrlObject } from 'url';
import { createLogger, LogLevel, LogsSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { ObservabilityOnboardingFtrConfigName } from '../configs';
import {
FtrProviderContext,
Expand Down Expand Up @@ -64,6 +65,9 @@ export interface CreateTest {
services: InheritedServices & {
observabilityOnboardingFtrConfig: () => ObservabilityOnboardingFtrConfig;
registry: ({ getService }: FtrProviderContext) => ReturnType<typeof RegistryProvider>;
logSynthtraceEsClient: (
context: InheritedFtrProviderContext
) => Promise<LogsSynthtraceEsClient>;
observabilityOnboardingApiClient: (
context: InheritedFtrProviderContext
) => ObservabilityOnboardingApiClient;
Expand Down Expand Up @@ -97,6 +101,12 @@ export function createTestConfig(
...services,
observabilityOnboardingFtrConfig: () => config,
registry: RegistryProvider,
logSynthtraceEsClient: (context: InheritedFtrProviderContext) =>
new LogsSynthtraceEsClient({
client: context.getService('es'),
logger: createLogger(LogLevel.info),
refreshAfterIndex: true,
}),
observabilityOnboardingApiClient: async (_: InheritedFtrProviderContext) => {
const { username, password } = servers.kibana;
const esUrl = format(esServer);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* 2.0.
*/

import { log, timerange } from '@kbn/apm-synthtrace-client';
import expect from '@kbn/expect';
import { ObservabilityOnboardingApiClientKey } from '../../../common/config';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
import { ObservabilityOnboardingApiError } from '../../../common/observability_onboarding_api_supertest';
import { expectToReject } from '../../../common/utils/expect_to_reject';
import { createLogDoc } from './es_utils';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const observabilityOnboardingApiClient = getService('observabilityOnboardingApiClient');
const es = getService('es');
const synthtrace = getService('logSynthtraceEsClient');

async function callApi({
onboardingId,
Expand Down Expand Up @@ -141,24 +141,24 @@ export default function ApiTest({ getService }: FtrProviderContext) {
describe('with a different agentId', () => {
describe('and onboarding type is logFiles', () => {
before(async () => {
await es.indices.createDataStream({
name: `logs-${datasetName}-${namespace}`,
});

const doc = createLogDoc({
time: new Date('06/28/2023').getTime(),
logFilepath: '/my-service.log',
serviceName: 'my-service',
namespace,
datasetName,
message: 'This is a log message',
agentId: 'another-agent-id',
});

await es.bulk({
body: [{ create: { _index: `logs-${datasetName}-${namespace}` } }, doc],
refresh: 'wait_for',
});
await synthtrace.index([
timerange('2023-11-20T10:00:00.000Z', '2023-11-20T10:01:00.000Z')
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset(datasetName)
.namespace(namespace)
.service('my-service')
.defaults({
'agent.id': 'another-agent-id',
'log.file.path': '/my-service.log',
})
),
]);
});

it('should return log-ingest as incomplete', async () => {
Expand All @@ -173,9 +173,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

after(async () => {
await es.indices.deleteDataStream({
name: `logs-${datasetName}-${namespace}`,
});
await synthtrace.clean();
});
});

Expand Down Expand Up @@ -211,23 +209,23 @@ export default function ApiTest({ getService }: FtrProviderContext) {
},
});

await es.indices.createDataStream({
name: `logs-system.syslog-${namespace}`,
});

const doc = createLogDoc({
time: new Date('06/28/2023').getTime(),
logFilepath: '/var/log/system.log',
namespace,
datasetName: 'system.syslog',
message: 'This is a system log message',
agentId: 'another-agent-id',
});

await es.bulk({
body: [{ create: { _index: `logs-system.syslog-${namespace}` } }, doc],
refresh: 'wait_for',
});
await synthtrace.index([
timerange('2023-11-20T10:00:00.000Z', '2023-11-20T10:01:00.000Z')
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a system log message')
.timestamp(timestamp)
.dataset('system.syslog')
.namespace(namespace)
.defaults({
'agent.id': 'another-agent-id',
'log.file.path': '/var/log/system.log',
})
),
]);
});

it('should return log-ingest as incomplete', async () => {
Expand All @@ -242,34 +240,32 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

after(async () => {
await es.indices.deleteDataStream({
name: `logs-system.syslog-${namespace}`,
});
await synthtrace.clean();
});
});
});

describe('with the expected agentId', () => {
describe('and onboarding type is logFiles', () => {
before(async () => {
await es.indices.createDataStream({
name: `logs-${datasetName}-${namespace}`,
});

const doc = createLogDoc({
time: new Date('06/28/2023').getTime(),
logFilepath: '/my-service.log',
serviceName: 'my-service',
namespace,
datasetName,
message: 'This is a log message',
agentId,
});

await es.bulk({
body: [{ create: { _index: `logs-${datasetName}-${namespace}` } }, doc],
refresh: 'wait_for',
});
await synthtrace.index([
timerange('2023-11-20T10:00:00.000Z', '2023-11-20T10:01:00.000Z')
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset(datasetName)
.namespace(namespace)
.service('my-service')
.defaults({
'agent.id': agentId,
'log.file.path': '/my-service.log',
})
),
]);
});

it('should return log-ingest as complete', async () => {
Expand All @@ -284,9 +280,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

after(async () => {
await es.indices.deleteDataStream({
name: `logs-${datasetName}-${namespace}`,
});
await synthtrace.clean();
});
});

Expand Down Expand Up @@ -322,23 +316,23 @@ export default function ApiTest({ getService }: FtrProviderContext) {
},
});

await es.indices.createDataStream({
name: `logs-system.syslog-${namespace}`,
});

const doc = createLogDoc({
time: new Date('06/28/2023').getTime(),
logFilepath: '/var/log/system.log',
namespace,
datasetName: 'system.syslog',
message: 'This is a system log message',
agentId,
});

await es.bulk({
body: [{ create: { _index: `logs-system.syslog-${namespace}` } }, doc],
refresh: 'wait_for',
});
await synthtrace.index([
timerange('2023-11-20T10:00:00.000Z', '2023-11-20T10:01:00.000Z')
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a system log message')
.timestamp(timestamp)
.dataset('system.syslog')
.namespace(namespace)
.defaults({
'agent.id': agentId,
'log.file.path': '/var/log/system.log',
})
),
]);
});

it('should return log-ingest as complete', async () => {
Expand All @@ -353,9 +347,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

after(async () => {
await es.indices.deleteDataStream({
name: `logs-system.syslog-${namespace}`,
});
await synthtrace.clean();
});
});
});
Expand Down

0 comments on commit 75dc0c1

Please sign in to comment.