Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Replace all use of date_histogram interval with fixed_interval #76876

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@
"datafeed_id": "datafeed-farequote",
"job_id": "farequote",
"query_delay": "115823ms",
"indices": [
"farequote"
],
"indices": ["farequote"],
"query": {
"bool": {
"must": [
Expand Down Expand Up @@ -103,7 +101,7 @@
"buckets": {
"date_histogram": {
"field": "@timestamp",
"interval": 900000,
"fixed_interval": "15m",
"offset": 0,
"order": {
"_key": "asc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class DataLoader {
earliest: number | undefined,
latest: number | undefined,
fields: FieldRequestConfig[],
interval?: string
interval?: number
): Promise<any[]> {
const stats = await ml.getVisualizerFieldStats({
indexPatternTitle: this._indexPatternTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export const Page: FC = () => {
earliest,
latest,
existMetricFields,
aggInterval.expression
aggInterval.asMilliseconds()
);

// Add the metric stats to the existing stats in the corresponding config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const anomalyDataChange = function (

// Query 1 - load the raw metric data.
function getMetricData(config, range) {
const { jobId, detectorIndex, entityFields, interval } = config;
const { jobId, detectorIndex, entityFields, bucketSpanSeconds } = config;

const job = mlJobService.getJob(jobId);

Expand All @@ -122,14 +122,14 @@ export const anomalyDataChange = function (
return mlResultsService
.getMetricData(
config.datafeedConfig.indices,
config.entityFields,
entityFields,
datafeedQuery,
config.metricFunction,
config.metricFieldName,
config.timeField,
range.min,
range.max,
config.interval
bucketSpanSeconds * 1000
)
.toPromise();
} else {
Expand Down Expand Up @@ -175,7 +175,14 @@ export const anomalyDataChange = function (
};

return mlResultsService
.getModelPlotOutput(jobId, detectorIndex, criteriaFields, range.min, range.max, interval)
.getModelPlotOutput(
jobId,
detectorIndex,
criteriaFields,
range.min,
range.max,
bucketSpanSeconds * 1000
)
.toPromise()
.then((resp) => {
// Return data in format required by the explorer charts.
Expand Down Expand Up @@ -218,7 +225,7 @@ export const anomalyDataChange = function (
[config.jobId],
range.min,
range.max,
config.interval,
config.bucketSpanSeconds * 1000,
1,
MAX_SCHEDULED_EVENTS
)
Expand Down Expand Up @@ -252,7 +259,7 @@ export const anomalyDataChange = function (
config.timeField,
range.min,
range.max,
config.interval
config.bucketSpanSeconds * 1000
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class ResultsLoader {
[],
this._lastModelTimeStamp,
this._jobCreator.end,
`${this._chartInterval.getInterval().asMilliseconds()}ms`,
this._chartInterval.getInterval().asMilliseconds(),
agg.mlModelPlotAgg
)
.toPromise();
Expand Down Expand Up @@ -211,7 +211,7 @@ export class ResultsLoader {
[this._jobCreator.jobId],
this._jobCreator.start,
this._jobCreator.end,
`${this._chartInterval.getInterval().asMilliseconds()}ms`,
this._chartInterval.getInterval().asMilliseconds(),
1
);

Expand All @@ -233,7 +233,7 @@ export class ResultsLoader {
this._jobCreator.jobId,
this._jobCreator.start,
this._jobCreator.end,
`${this._chartInterval.getInterval().asMilliseconds()}ms`,
this._chartInterval.getInterval().asMilliseconds(),
this._detectorSplitFieldFilters
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getScoresByRecord(
jobId: string,
earliestMs: number,
latestMs: number,
interval: string,
intervalMs: number,
firstSplitField: SplitFieldWithValue | null
): Promise<ProcessedResults> {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -104,7 +104,7 @@ export function getScoresByRecord(
byTime: {
date_histogram: {
field: 'timestamp',
interval,
fixed_interval: `${intervalMs}ms`,
min_doc_count: 1,
extended_bounds: {
min: earliestMs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class AnomalyTimelineService {
// Pass the interval in seconds as the swim lane relies on a fixed number of seconds between buckets
// which wouldn't be the case if e.g. '1M' was used.

const interval = `${swimlaneBucketInterval.asSeconds()}s`;
const intervalMs = swimlaneBucketInterval.asMilliseconds();

let response;
if (viewBySwimlaneFieldName === VIEW_BY_JOB_LABEL) {
Expand All @@ -190,7 +190,7 @@ export class AnomalyTimelineService {
jobIds,
searchBounds.min.valueOf(),
searchBounds.max.valueOf(),
interval,
intervalMs,
perPage,
fromPage
);
Expand All @@ -201,7 +201,7 @@ export class AnomalyTimelineService {
fieldValues,
searchBounds.min.valueOf(),
searchBounds.max.valueOf(),
interval,
intervalMs,
swimlaneLimit,
perPage,
fromPage,
Expand Down Expand Up @@ -269,7 +269,7 @@ export class AnomalyTimelineService {
selectedJobIds,
earliestMs,
latestMs,
this.getSwimlaneBucketInterval(selectedJobs, swimlaneContainerWidth).asSeconds() + 's',
this.getSwimlaneBucketInterval(selectedJobs, swimlaneContainerWidth).asMilliseconds(),
swimlaneLimit
);
return Object.keys(resp.results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const mlForecastService: {
entityFields: any[],
earliestMs: number,
latestMs: number,
interval: string,
intervalMs: number,
aggType: any
) => Observable<ForecastData>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function getForecastData(
entityFields,
earliestMs,
latestMs,
interval,
intervalMs,
aggType
) {
// Extract the partition, by, over fields on which to filter.
Expand Down Expand Up @@ -257,7 +257,7 @@ function getForecastData(
times: {
date_histogram: {
field: 'timestamp',
interval: interval,
fixed_interval: `${intervalMs}ms`,
min_doc_count: 1,
},
aggs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export function mlApiServicesProvider(httpService: HttpService) {
earliest?: number;
latest?: number;
samplerShardSize?: number;
interval?: string;
interval?: number;
fields?: FieldRequestConfig[];
maxExamples?: number;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
timeFieldName: string,
earliestMs: number,
latestMs: number,
interval: string
intervalMs: number
): Observable<MetricData> {
// Build the criteria to use in the bool filter part of the request.
// Add criteria for the time range, entity fields,
Expand Down Expand Up @@ -136,7 +136,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
byTime: {
date_histogram: {
field: timeFieldName,
interval,
fixed_interval: `${intervalMs}ms`,
min_doc_count: 0,
},
},
Expand Down Expand Up @@ -202,7 +202,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
criteriaFields: any[],
earliestMs: number,
latestMs: number,
interval: string,
intervalMs: number,
aggType?: { min: any; max: any }
): Observable<ModelPlotOutput> {
const obj: ModelPlotOutput = {
Expand Down Expand Up @@ -291,7 +291,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
times: {
date_histogram: {
field: 'timestamp',
interval,
fixed_interval: `${intervalMs}ms`,
min_doc_count: 0,
},
aggs: {
Expand Down Expand Up @@ -446,7 +446,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
jobIds: string[] | undefined,
earliestMs: number,
latestMs: number,
interval: string,
intervalMs: number,
maxJobs: number,
maxEvents: number
): Observable<ScheduledEventsByBucket> {
Expand Down Expand Up @@ -518,7 +518,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
times: {
date_histogram: {
field: 'timestamp',
interval,
fixed_interval: `${intervalMs}ms`,
min_doc_count: 1,
},
aggs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function resultsServiceProvider(
jobIds: string[],
earliestMs: number,
latestMs: number,
interval: string | number,
intervalMs: number,
perPage?: number,
fromPage?: number
): Promise<any>;
Expand Down Expand Up @@ -41,7 +41,7 @@ export function resultsServiceProvider(
influencerFieldValues: string[],
earliestMs: number,
latestMs: number,
interval: string,
intervalMs: number,
maxResults: number,
perPage: number,
fromPage: number,
Expand All @@ -57,8 +57,25 @@ export function resultsServiceProvider(
timeFieldName: string,
earliestMs: number,
latestMs: number,
interval: string | number
intervalMs: number
): Promise<any>;
getEventDistributionData(
index: string,
splitField: string,
filterField: string,
query: any,
metricFunction: string, // ES aggregation name
metricFieldName: string,
timeFieldName: string,
earliestMs: number,
latestMs: number,
intervalMs: number
): Promise<any>;
getRecordMaxScoreByTime(
jobId: string,
criteriaFields: any[],
earliestMs: number,
latestMs: number,
intervalMs: number
): Promise<any>;
getEventDistributionData(): Promise<any>;
getRecordMaxScoreByTime(): Promise<any>;
};
Loading