Skip to content

Commit

Permalink
remove avg_actions_run_duration_by_connector_type_per_day
Browse files Browse the repository at this point in the history
  • Loading branch information
ersin-erdal committed Sep 20, 2022
1 parent de4a052 commit b9c8252
Showing 8 changed files with 49 additions and 205 deletions.
70 changes: 23 additions & 47 deletions x-pack/plugins/actions/server/usage/actions_telemetry.test.ts
Original file line number Diff line number Diff line change
@@ -721,54 +721,34 @@ Object {
},
},
},
avg_run_duration_by_connector_type: {
connector_types: {
buckets: [
{
key: '.slack',
duration: {
average: {
value: 10,
},
},
},
{
key: '.email',
duration: {
average: {
value: 11,
},
},
},
],
},
},
count_connector_types_by_action_run_outcome_per_day: {
connector_types: {
buckets: [
{
key: '.slack',
outcome: {
count: {
buckets: [
{ key: 'success', doc_count: 12 },
{ key: 'failure', doc_count: 1 },
],
actionSavedObjects: {
connector_types: {
buckets: [
{
key: '.slack',
outcome: {
count: {
buckets: [
{ key: 'success', doc_count: 12 },
{ key: 'failure', doc_count: 1 },
],
},
},
},
},
{
key: '.email',
outcome: {
count: {
buckets: [
{ key: 'success', doc_count: 13 },
{ key: 'failure', doc_count: 2 },
],
{
key: '.email',
outcome: {
count: {
buckets: [
{ key: 'success', doc_count: 13 },
{ key: 'failure', doc_count: 2 },
],
},
},
},
},
],
],
},
},
},
},
@@ -804,10 +784,6 @@ Object {
__slack: 7,
},
countTotal: 120,
avgRunDurationByConnectorType: {
__email: 11,
__slack: 10,
},
countRunOutcomeByConnectorType: {
__email: {
failure: 2,
66 changes: 20 additions & 46 deletions x-pack/plugins/actions/server/usage/actions_telemetry.ts
Original file line number Diff line number Diff line change
@@ -9,10 +9,8 @@ import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { ElasticsearchClient, Logger } from '@kbn/core/server';
import { AggregationsTermsAggregateBase } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
AvgActionRunDurationByConnectorTypeBucket,
AvgActionRunOutcomeByConnectorTypeBucket,
parseActionRunOutcomeByConnectorTypesBucket,
parseDurationsByConnectorTypesBucket,
} from './lib/parse_connector_type_bucket';
import { AlertHistoryEsIndexConnectorId } from '../../common';
import { ActionResult, PreConfiguredAction } from '../types';
@@ -422,7 +420,6 @@ export async function getExecutionsPerDayCount(
countFailedByType: Record<string, number>;
avgExecutionTime: number;
avgExecutionTimeByType: Record<string, number>;
avgRunDurationByConnectorType: Record<string, number>;
countRunOutcomeByConnectorType: Record<string, number>;
}> {
const scriptedMetric = {
@@ -545,46 +542,27 @@ export async function getExecutionsPerDayCount(
},
},
},
avg_run_duration_by_connector_type: {
nested: {
path: 'kibana.saved_objects',
},
aggs: {
connector_types: {
terms: {
field: 'kibana.saved_objects.type_id',
},
aggs: {
duration: {
reverse_nested: {},
aggs: {
average: {
avg: {
field: 'event.duration',
},
},
},
},
},
},
},
},
count_connector_types_by_action_run_outcome_per_day: {
nested: {
path: 'kibana.saved_objects',
},
aggs: {
connector_types: {
terms: {
field: 'kibana.saved_objects.type_id',
},
actionSavedObjects: {
filter: { term: { 'kibana.saved_objects.type': 'action' } },
aggs: {
outcome: {
reverse_nested: {},
connector_types: {
terms: {
field: 'kibana.saved_objects.type_id',
},
aggs: {
count: {
terms: {
field: 'event.outcome',
outcome: {
reverse_nested: {},
aggs: {
count: {
terms: {
field: 'event.outcome',
},
},
},
},
},
@@ -621,12 +599,11 @@ export async function getExecutionsPerDayCount(
{}
);

const aggregations = actionResults.aggregations as {
avg_run_duration_by_connector_type: {
connector_types: AggregationsTermsAggregateBase<AvgActionRunDurationByConnectorTypeBucket>;
};
const aggsCountConnectorTypeByActionRun = actionResults.aggregations as {
count_connector_types_by_action_run_outcome_per_day: {
connector_types: AggregationsTermsAggregateBase<AvgActionRunOutcomeByConnectorTypeBucket>;
actionSavedObjects: {
connector_types: AggregationsTermsAggregateBase<AvgActionRunOutcomeByConnectorTypeBucket>;
};
};
};

@@ -652,11 +629,9 @@ export async function getExecutionsPerDayCount(
),
avgExecutionTime: aggsAvgExecutionTime,
avgExecutionTimeByType,
avgRunDurationByConnectorType: parseDurationsByConnectorTypesBucket(
aggregations.avg_run_duration_by_connector_type.connector_types.buckets
),
countRunOutcomeByConnectorType: parseActionRunOutcomeByConnectorTypesBucket(
aggregations.count_connector_types_by_action_run_outcome_per_day.connector_types.buckets
aggsCountConnectorTypeByActionRun.count_connector_types_by_action_run_outcome_per_day
.actionSavedObjects.connector_types.buckets
),
};
} catch (err) {
@@ -673,7 +648,6 @@ export async function getExecutionsPerDayCount(
countFailedByType: {},
avgExecutionTime: 0,
avgExecutionTimeByType: {},
avgRunDurationByConnectorType: {},
countRunOutcomeByConnectorType: {},
};
}
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ export function createActionsUsageCollector(
unknown: { type: 'long' },
},
},
avg_actions_run_duration_by_connector_type_per_day: { DYNAMIC_KEY: { type: 'long' } },
},
fetch: async () => {
try {
@@ -86,7 +85,6 @@ export function createActionsUsageCollector(
avg_execution_time_per_day: 0,
avg_execution_time_by_type_per_day: {},
count_connector_types_by_action_run_outcome_per_day: {},
avg_actions_run_duration_by_connector_type_per_day: {},
};
}
},
Original file line number Diff line number Diff line change
@@ -5,74 +5,7 @@
* 2.0.
*/

import {
parseDurationsByConnectorTypesBucket,
parseActionRunOutcomeByConnectorTypesBucket,
} from './parse_connector_type_bucket';

describe('parseDurationsByConnectorTypesBucket', () => {
test('should correctly parse connector type bucket results', () => {
expect(
parseDurationsByConnectorTypesBucket([
{
key: '.server-log',
doc_count: 78,
duration: { average: { value: 10.2 } },
},
{
key: '.index',
doc_count: 42,
duration: { average: { value: 11.6 } },
},
{
key: '.slack',
doc_count: 28,
duration: { average: { value: 12.4 } },
},
])
).toEqual({
'__server-log': 10,
__index: 12,
__slack: 12,
});
});

test('should handle missing values', () => {
expect(
parseDurationsByConnectorTypesBucket([
// @ts-expect-error
{
key: '.server-log',
doc_count: 78,
},
{
key: '.index',
doc_count: 42,
// @ts-expect-error
duration: {},
},
{
key: '.slack',
doc_count: 28,
// @ts-expect-error
duration: { average: {} },
},
])
).toEqual({
'__server-log': 0,
__index: 0,
__slack: 0,
});
});

test('should handle empty input', () => {
expect(parseDurationsByConnectorTypesBucket([])).toEqual({});
});
//
test('should handle undefined input', () => {
expect(parseDurationsByConnectorTypesBucket(undefined)).toEqual({});
});
});
import { parseActionRunOutcomeByConnectorTypesBucket } from './parse_connector_type_bucket';

describe('parseActionRunOutcomeByConnectorTypesBucket', () => {
test('should correctly parse connector type bucket results', () => {
Original file line number Diff line number Diff line change
@@ -8,26 +8,6 @@
import { AggregationsBuckets } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { replaceFirstAndLastDotSymbols } from '../actions_telemetry';

export interface AvgActionRunDurationByConnectorTypeBucket {
key: string;
doc_count: number; // Not used for duration telemetry but can be helpful later.
duration: { average: { value: number } };
}

export function parseDurationsByConnectorTypesBucket(
connectorTypeBuckets: AggregationsBuckets<AvgActionRunDurationByConnectorTypeBucket> = []
) {
const buckets = connectorTypeBuckets as AvgActionRunDurationByConnectorTypeBucket[];
return buckets.reduce((acc, connectorType) => {
return {
...acc,
[replaceFirstAndLastDotSymbols(connectorType.key)]: Math.round(
connectorType.duration?.average?.value || 0
),
};
}, {});
}

export interface AvgActionRunOutcomeByConnectorTypeBucket {
key: string;
doc_count: number; // Not used for duration telemetry but can be helpful later.
2 changes: 0 additions & 2 deletions x-pack/plugins/actions/server/usage/task.ts
Original file line number Diff line number Diff line change
@@ -130,8 +130,6 @@ export function telemetryTaskRunner(
totalExecutionsPerDay.countFailedByType,
avg_execution_time_per_day: totalExecutionsPerDay.avgExecutionTime,
avg_execution_time_by_type_per_day: totalExecutionsPerDay.avgExecutionTimeByType,
avg_actions_run_duration_by_connector_type_per_day:
totalExecutionsPerDay.avgRunDurationByConnectorType,
count_connector_types_by_action_run_outcome_per_day:
totalExecutionsPerDay.countRunOutcomeByConnectorType,
},
1 change: 0 additions & 1 deletion x-pack/plugins/actions/server/usage/types.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ export interface ActionsUsage {
count_connector_types_by_action_run_outcome_per_day: Record<string, Record<string, number>>;
avg_execution_time_per_day: number;
avg_execution_time_by_type_per_day: Record<string, number>;
avg_actions_run_duration_by_connector_type_per_day: Record<string, number>;
}

export const byTypeSchema: MakeSchemaFrom<ActionsUsage>['count_by_type'] = {
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ export default function createAlertingAndActionsTelemetryTests({ getService }: F
const esTestIndexTool = new ESTestIndexTool(es, retry);
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('telemetry', () => {
describe('telemetry xxx', () => {
const alwaysFiringRuleId: { [key: string]: string } = {};

beforeEach(async () => {
@@ -246,6 +246,10 @@ export default function createAlertingAndActionsTelemetryTests({ getService }: F
expect(telemetry.count_actions_executions_failed_by_type_per_day['test.throw'] > 0).to.be(
true
);

expect(
telemetry.count_connector_types_by_action_run_outcome_per_day['test.throw'].failure
).to.greaterThan(0);
}

function verifyAlertingTelemetry(telemetry: any) {
@@ -529,24 +533,6 @@ export default function createAlertingAndActionsTelemetryTests({ getService }: F
alertsFixture: { test__noop: 9, test__throw: 9, __slack: 3 },
});

expect(
telemetry.avg_actions_run_duration_by_connector_type_per_day['test__cumulative-firing']
).to.be.greaterThan(0);
expect(
telemetry.avg_actions_run_duration_by_connector_type_per_day.test__throw
).to.be.greaterThan(0);

expect(
telemetry.count_connector_types_by_action_run_outcome_per_day['test__cumulative-firing']
.failure
).to.greaterThan(0);
expect(
telemetry.count_connector_types_by_action_run_outcome_per_day.test__throw.failure
).to.greaterThan(0);

expect(telemetry.count_rules_by_execution_status_per_day.failure).to.greaterThan(0);
expect(telemetry.count_rules_by_execution_status_per_day.success).to.greaterThan(0);

expect(telemetry.count_rules_by_execution_status_per_day.failure).to.greaterThan(0);
expect(telemetry.count_rules_by_execution_status_per_day.success).to.greaterThan(0);
}

0 comments on commit b9c8252

Please sign in to comment.