Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed Oct 3, 2023
1 parent 12d2bd8 commit e666f07
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { healthStatsMock } from './health_stats.mock';

const getEmptyClusterHealthSnapshot = (): ClusterHealthSnapshot => {
return {
stats_at_the_moment: healthStatsMock.getEmptyRuleStats(),
stats_over_interval: healthStatsMock.getEmptyRuleExecutionStats(),
state_at_the_moment: healthStatsMock.getEmptyHealthOverviewState(),
stats_over_interval: healthStatsMock.getEmptyHealthOverviewStats(),
history_over_interval: {
buckets: [
{
timestamp: '2023-05-15T16:12:14.967Z',
stats: healthStatsMock.getEmptyRuleExecutionStats(),
stats: healthStatsMock.getEmptyHealthOverviewStats(),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { HealthParameters, HealthSnapshot } from './health_metadata';
import type { RuleExecutionStats, RuleStats, StatsHistory } from './health_stats';
import type { HealthOverviewStats, HealthOverviewState, HealthHistory } from './health_stats';

/**
* Health calculation parameters for the whole cluster.
Expand All @@ -18,27 +18,27 @@ export type ClusterHealthParameters = HealthParameters;
*/
export interface ClusterHealthSnapshot extends HealthSnapshot {
/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
stats_at_the_moment: ClusterHealthStatsAtTheMoment;
state_at_the_moment: ClusterHealthState;

/**
* Health stats calculated over the interval specified in the health parameters.
*/
stats_over_interval: ClusterHealthStatsOverInterval;
stats_over_interval: ClusterHealthStats;

/**
* History of change of the same health stats during the interval.
*/
history_over_interval: StatsHistory<ClusterHealthStatsOverInterval>;
history_over_interval: HealthHistory<ClusterHealthStats>;
}

/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
export type ClusterHealthStatsAtTheMoment = RuleStats;
export type ClusterHealthState = HealthOverviewState;

/**
* Health stats calculated over a given interval.
*/
export type ClusterHealthStatsOverInterval = RuleExecutionStats;
export type ClusterHealthStats = HealthOverviewStats;
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import type {
AggregatedMetric,
RuleExecutionStats,
RuleStats,
HealthOverviewStats,
HealthOverviewState,
TotalEnabledDisabled,
} from './health_stats';

const getEmptyRuleStats = (): RuleStats => {
const getEmptyHealthOverviewState = (): HealthOverviewState => {
return {
number_of_rules: {
all: getZeroTotalEnabledDisabled(),
Expand All @@ -34,7 +34,7 @@ const getZeroTotalEnabledDisabled = (): TotalEnabledDisabled => {
};
};

const getEmptyRuleExecutionStats = (): RuleExecutionStats => {
const getEmptyHealthOverviewStats = (): HealthOverviewStats => {
return {
number_of_executions: {
total: 0,
Expand Down Expand Up @@ -70,18 +70,15 @@ const getEmptyRuleExecutionStats = (): RuleExecutionStats => {
const getZeroAggregatedMetric = (): AggregatedMetric<number> => {
return {
percentiles: {
'1.0': 0,
'5.0': 0,
'25.0': 0,
'50.0': 0,
'75.0': 0,
'95.0': 0,
'99.0': 0,
'99.9': 0,
},
};
};

export const healthStatsMock = {
getEmptyRuleStats,
getEmptyRuleExecutionStats,
getEmptyHealthOverviewState,
getEmptyHealthOverviewStats,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { RuleLastRunOutcomes } from '@kbn/alerting-plugin/common';
import type { LogLevel } from '../../model';

// -------------------------------------------------------------------------------------------------
// Stats history (date histogram)
// History of health stats (date histogram)

/**
* History of change of a set of stats over a time interval. The interval is split into discreet buckets,
Expand All @@ -19,14 +19,14 @@ import type { LogLevel } from '../../model';
* This model corresponds to the `date_histogram` aggregation of Elasticsearch:
* https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
*/
export interface StatsHistory<TStats> {
buckets: Array<StatsBucket<TStats>>;
export interface HealthHistory<TStats> {
buckets: Array<HealthBucket<TStats>>;
}

/**
* Sub-interval with stats calculated over it.
*/
export interface StatsBucket<TStats> {
export interface HealthBucket<TStats> {
/**
* Start timestamp of the sub-interval.
*/
Expand All @@ -39,23 +39,15 @@ export interface StatsBucket<TStats> {
}

// -------------------------------------------------------------------------------------------------
// Rule stats

// TODO: https://github.com/elastic/kibana/issues/125642 Add more stats, such as:
// - number of Kibana instances
// - number of Kibana spaces
// - number of rules with exceptions
// - number of rules with notification actions (total, normal, legacy)
// - number of rules with response actions
// - top X last failed status messages + rule ids for each status
// - top X last partial failure status messages + rule ids for each status
// - top X slowest rules by any metrics (last total execution time, search time, indexing time, etc)
// - top X rules with the largest schedule delay (drift)
// Health overview state

// TODO: https://github.com/elastic/kibana/issues/125642 Add more data, see health_data.md

/**
* "Static" stats calculated for a set of rules, such as number of enabled and disabled rules, etc.
* "Static" health state at the moment of the API call. Calculated for a set of rules.
* Example: number of enabled and disabled rules.
*/
export interface RuleStats {
export interface HealthOverviewState {
/**
* Various counts of different rules.
*/
Expand Down Expand Up @@ -108,19 +100,15 @@ export interface TotalEnabledDisabled {
}

// -------------------------------------------------------------------------------------------------
// Rule execution stats
// Health overview stats

// TODO: https://github.com/elastic/kibana/issues/125642 Add more stats, such as:
// - number of detected alerts (source event "hits")
// - number of created alerts (those we wrote to the .alerts-* index)
// - number of times rule hit cirquit breaker, number of not created alerts because of that
// - number of triggered actions
// - top gaps
// TODO: https://github.com/elastic/kibana/issues/125642 Add more data, see health_data.md

/**
* "Dynamic" rule execution stats. Can be calculated either for a set of rules or for a single rule.
* "Dynamic" health stats over a specified "health interval". Can be calculated either
* for a set of rules or for a single rule.
*/
export interface RuleExecutionStats {
export interface HealthOverviewStats {
/**
* Number of rule executions.
*/
Expand Down Expand Up @@ -242,13 +230,10 @@ export interface AggregatedMetric<T> {
* Distribution of values of an aggregated metric represented by a set of discreet percentiles.
* @example
* {
* '1.0': 27,
* '5.0': 150,
* '25.0': 240,
* '50.0': 420,
* '75.0': 700,
* '95.0': 2500,
* '99.0': 7800,
* '99.9': 10000,
* }
*/
export type Percentiles<T> = Record<string, T>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import type { RuleHealthSnapshot } from './rule_health';

const getEmptyRuleHealthSnapshot = (): RuleHealthSnapshot => {
return {
stats_at_the_moment: {
state_at_the_moment: {
rule: getRulesSchemaMock(),
},
stats_over_interval: healthStatsMock.getEmptyRuleExecutionStats(),
stats_over_interval: healthStatsMock.getEmptyHealthOverviewStats(),
history_over_interval: {
buckets: [
{
timestamp: '2023-05-15T16:12:14.967Z',
stats: healthStatsMock.getEmptyRuleExecutionStats(),
stats: healthStatsMock.getEmptyHealthOverviewStats(),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { RuleResponse } from '../../../model';
import type { HealthParameters, HealthSnapshot } from './health_metadata';
import type { RuleExecutionStats, StatsHistory } from './health_stats';
import type { HealthOverviewStats, HealthHistory } from './health_stats';

/**
* Health calculation parameters for a given rule.
Expand All @@ -24,25 +24,25 @@ export interface RuleHealthParameters extends HealthParameters {
*/
export interface RuleHealthSnapshot extends HealthSnapshot {
/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
stats_at_the_moment: RuleHealthStatsAtTheMoment;
state_at_the_moment: RuleHealthState;

/**
* Health stats calculated over the interval specified in the health parameters.
*/
stats_over_interval: RuleHealthStatsOverInterval;
stats_over_interval: RuleHealthStats;

/**
* History of change of the same health stats during the interval.
*/
history_over_interval: StatsHistory<RuleHealthStatsOverInterval>;
history_over_interval: HealthHistory<RuleHealthStats>;
}

/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
export interface RuleHealthStatsAtTheMoment {
export interface RuleHealthState {
/**
* Rule object including its current execution summary.
*/
Expand All @@ -52,4 +52,4 @@ export interface RuleHealthStatsAtTheMoment {
/**
* Health stats calculated over a given interval.
*/
export type RuleHealthStatsOverInterval = RuleExecutionStats;
export type RuleHealthStats = HealthOverviewStats;
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import type { SpaceHealthSnapshot } from './space_health';

const getEmptySpaceHealthSnapshot = (): SpaceHealthSnapshot => {
return {
stats_at_the_moment: healthStatsMock.getEmptyRuleStats(),
stats_over_interval: healthStatsMock.getEmptyRuleExecutionStats(),
state_at_the_moment: healthStatsMock.getEmptyHealthOverviewState(),
stats_over_interval: healthStatsMock.getEmptyHealthOverviewStats(),
history_over_interval: {
buckets: [
{
timestamp: '2023-05-15T16:12:14.967Z',
stats: healthStatsMock.getEmptyRuleExecutionStats(),
stats: healthStatsMock.getEmptyHealthOverviewStats(),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { HealthParameters, HealthSnapshot } from './health_metadata';
import type { RuleExecutionStats, RuleStats, StatsHistory } from './health_stats';
import type { HealthOverviewStats, HealthOverviewState, HealthHistory } from './health_stats';

/**
* Health calculation parameters for the current Kibana space.
Expand All @@ -18,27 +18,27 @@ export type SpaceHealthParameters = HealthParameters;
*/
export interface SpaceHealthSnapshot extends HealthSnapshot {
/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
stats_at_the_moment: SpaceHealthStatsAtTheMoment;
state_at_the_moment: SpaceHealthState;

/**
* Health stats calculated over the interval specified in the health parameters.
*/
stats_over_interval: SpaceHealthStatsOverInterval;
stats_over_interval: SpaceHealthStats;

/**
* History of change of the same health stats during the interval.
*/
history_over_interval: StatsHistory<SpaceHealthStatsOverInterval>;
history_over_interval: HealthHistory<SpaceHealthStats>;
}

/**
* Health stats at the moment of the calculation request.
* Health state at the moment of the calculation request.
*/
export type SpaceHealthStatsAtTheMoment = RuleStats;
export type SpaceHealthState = HealthOverviewState;

/**
* Health stats calculated over a given interval.
*/
export type SpaceHealthStatsOverInterval = RuleExecutionStats;
export type SpaceHealthStats = HealthOverviewStats;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { validateGetClusterHealthRequest } from './get_cluster_health_request';
/**
* Get health overview of the whole cluster. Scope: all detection rules in all Kibana spaces.
* Returns:
* - health stats at the moment of the API call
* - health state at the moment of the API call
* - health stats over a specified period of time ("health interval")
* - health stats history within the same interval in the form of a histogram
* (the same stats are calculated over each of the discreet sub-intervals of the whole interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { validateGetRuleHealthRequest } from './get_rule_health_request';
/**
* Get health overview of a rule. Scope: a given detection rule in the current Kibana space.
* Returns:
* - health stats at the moment of the API call (rule and its execution summary)
* - health state at the moment of the API call (rule and its execution summary)
* - health stats over a specified period of time ("health interval")
* - health stats history within the same interval in the form of a histogram
* (the same stats are calculated over each of the discreet sub-intervals of the whole interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { validateGetSpaceHealthRequest } from './get_space_health_request';
/**
* Get health overview of the current Kibana space. Scope: all detection rules in the space.
* Returns:
* - health stats at the moment of the API call
* - health state at the moment of the API call
* - health stats over a specified period of time ("health interval")
* - health stats history within the same interval in the form of a histogram
* (the same stats are calculated over each of the discreet sub-intervals of the whole interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const createDetectionEngineHealthClient = (
const statsBasedOnEventLog = await eventLogHealthClient.calculateRuleHealth(args);

return {
stats_at_the_moment: statsBasedOnRuleObjects.stats_at_the_moment,
state_at_the_moment: statsBasedOnRuleObjects.state_at_the_moment,
stats_over_interval: statsBasedOnEventLog.stats_over_interval,
history_over_interval: statsBasedOnEventLog.history_over_interval,
debug: {
Expand Down Expand Up @@ -76,7 +76,7 @@ export const createDetectionEngineHealthClient = (
]);

return {
stats_at_the_moment: statsBasedOnRuleObjects.stats_at_the_moment,
state_at_the_moment: statsBasedOnRuleObjects.state_at_the_moment,
stats_over_interval: statsBasedOnEventLog.stats_over_interval,
history_over_interval: statsBasedOnEventLog.history_over_interval,
debug: {
Expand Down Expand Up @@ -107,7 +107,7 @@ export const createDetectionEngineHealthClient = (
]);

return {
stats_at_the_moment: statsBasedOnRuleObjects.stats_at_the_moment,
state_at_the_moment: statsBasedOnRuleObjects.state_at_the_moment,
stats_over_interval: statsBasedOnEventLog.stats_over_interval,
history_over_interval: statsBasedOnEventLog.history_over_interval,
debug: {
Expand Down
Loading

0 comments on commit e666f07

Please sign in to comment.