Skip to content

Commit

Permalink
[APM] Return service groups stats from all spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Oct 6, 2022
1 parent 8219489 commit 5efd87d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,38 +450,91 @@ describe('data telemetry collection tasks', () => {
const task = tasks.find((t) => t.name === 'service_groups');
const savedObjectsClient = savedObjectsClientMock.create();

savedObjectsClient.find.mockResolvedValue({
page: 1,
per_page: 500,
total: 2,
saved_objects: [
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['default'],
attributes: {
color: '#5094C4',
kuery: 'service.environment: production',
groupName: 'production',
},
references: [],
score: 1,
},
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['default'],
attributes: {
color: '#5094C4',
kuery: 'agent.name: go',
groupName: 'agent',
},
references: [],
score: 0,
it('returns service group stats', async () => {
savedObjectsClient.find.mockResolvedValueOnce({
page: 1,
per_page: 500,
total: 2,
saved_objects: [
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['default'],
attributes: {
color: '#5094C4',
kuery: 'service.environment: production',
groupName: 'production',
},
references: [],
score: 1,
},
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['space-1'],
attributes: {
color: '#5094C4',
kuery: 'agent.name: go',
groupName: 'agent',
},
references: [],
score: 0,
},
],
});

expect(await task?.executor({ savedObjectsClient } as any)).toEqual({
service_groups: {
kuery_fields: ['service.environment', 'agent.name'],
total: 2,
},
],
});
});
it('returns service group stats', async () => {

it('should return stats from all spaces', () => {
expect(savedObjectsClient.find).toHaveBeenCalledWith({
type: 'apm-service-group',
page: 1,
perPage: 500,
sortField: 'updated_at',
sortOrder: 'desc',
namespaces: ['*'],
});
});

it('returns unique fields', async () => {
savedObjectsClient.find.mockResolvedValueOnce({
page: 1,
per_page: 500,
total: 2,
saved_objects: [
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['default'],
attributes: {
color: '#5094C4',
kuery: 'service.environment: production',
groupName: 'production',
},
references: [],
score: 1,
},
{
type: 'apm-service-group',
id: '0b6157f0-44bd-11ed-bdb7-bffab551cd4d',
namespaces: ['default'],
attributes: {
color: '#5094C4',
kuery: 'service.environment: production and agent.name: go',
groupName: 'agent',
},
references: [],
score: 0,
},
],
});

expect(await task?.executor({ savedObjectsClient } as any)).toEqual({
service_groups: {
kuery_fields: ['service.environment', 'agent.name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { fromKueryExpression } from '@kbn/es-query';
import { flatten, merge, sortBy, sum, pickBy } from 'lodash';
import { flatten, merge, sortBy, sum, pickBy, uniq } from 'lodash';
import { createHash } from 'crypto';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
Expand Down Expand Up @@ -1138,6 +1138,7 @@ export const tasks: TelemetryTask[] = [
perPage: MAX_NUMBER_OF_SERVICE_GROUPS,
sortField: 'updated_at',
sortOrder: 'desc',
namespaces: ['*'],
});

const kueryNodes = response.saved_objects.map(
Expand All @@ -1148,7 +1149,7 @@ export const tasks: TelemetryTask[] = [

return {
service_groups: {
kuery_fields: kueryFields,
kuery_fields: uniq(kueryFields),
total: response.total ?? 0,
},
};
Expand Down

0 comments on commit 5efd87d

Please sign in to comment.