Skip to content

Commit

Permalink
[ML] Anomaly Explorer Charts jest tests. (#22759) (#22796)
Browse files Browse the repository at this point in the history
After the migration to React in #22622, this PR adds more test coverage based on jest to the Anomaly Explorer charts. This is done as preparation for some further refactoring (#22626) and the integration of the support for charts for the rare detector (#21163). The tests use mock data based on a standard multi-metric job using the farequote dataset.
Besided the tests this PR includes the following changes:
- In explore_series.js the path is no longer a concatenanted string but now using a template literal
- The exploreSeries() function is no longer calling window.open by itself, it just returns the link
because of the above, renamed exploreSeries() to getExploreSeriesLink() and moved it to chart_utils.js
- explorer_charts_container_service.js is no longer requiring jQuery itself, it now receiving the required element as a factory argument. Further work on this is planned to get rid of jQuery.
  • Loading branch information
walterra authored Sep 7, 2018
1 parent 8612a53 commit e571490
Show file tree
Hide file tree
Showing 30 changed files with 1,664 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


import { notify } from 'ui/notify';
import { MLRequestFailure } from 'plugins/ml/util/ml_error';
import { MLRequestFailure } from '../../util/ml_error';

const messages = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"job_id": "mock-job-id",
"result_type": "record",
"probability": 1.6552181439816634e-32,
"record_score": 98.56065708456248,
"initial_record_score": 98.56065708456248,
"bucket_span": 900,
"detector_index": 0,
"is_interim": false,
"timestamp": 1486656000000,
"partition_field_name": "airline",
"partition_field_value": "AAL",
"function": "mean",
"function_description": "mean",
"typical": [
99.81123207526203
],
"actual": [
242.3568918440077
],
"field_name": "responsetime",
"influencers": [
{
"influencer_field_name": "airline",
"influencer_field_values": [
"AAL"
]
}
],
"airline": [
"AAL"
]
},
{
"job_id": "mock-job-id",
"result_type": "record",
"probability": 2.6276047868032343e-28,
"record_score": 96.93718,
"initial_record_score": 92.70812367638732,
"bucket_span": 900,
"detector_index": 0,
"is_interim": false,
"timestamp": 1486656900000,
"partition_field_name": "airline",
"partition_field_value": "AAL",
"function": "mean",
"function_description": "mean",
"typical": [
100.02884159032787
],
"actual": [
282.02533259111306
],
"field_name": "responsetime",
"influencers": [
{
"influencer_field_name": "airline",
"influencer_field_values": [
"AAL"
]
}
],
"airline": [
"AAL"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"job_id": "mock-job-id",
"result_type": "record",
"probability": 0.000374234162864467,
"record_score": 1.3677172011743646,
"initial_record_score": 1.3677172011743646,
"bucket_span": 900,
"detector_index": 0,
"is_interim": false,
"timestamp": 1486743300000,
"partition_field_name": "airline",
"partition_field_value": "JAL",
"function": "mean",
"function_description": "mean",
"typical": [
499.9850000350266
],
"actual": [
511.4997161865235
],
"field_name": "responsetime",
"influencers": [
{
"influencer_field_name": "airline",
"influencer_field_values": [
"JAL"
]
}
],
"airline": [
"JAL"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const chartData = [
{
date: new Date('2017-02-23T08:00:00.000Z'),
value: 228243469, anomalyScore: 63.32916, numberOfCauses: 1,
actual: [228243469], typical: [133107.7703441773]
},
{ date: new Date('2017-02-23T09:00:00.000Z'), value: null },
{ date: new Date('2017-02-23T10:00:00.000Z'), value: null },
{ date: new Date('2017-02-23T11:00:00.000Z'), value: null },
{
date: new Date('2017-02-23T12:00:00.000Z'),
value: 625736376, anomalyScore: 97.32085, numberOfCauses: 1,
actual: [625736376], typical: [132830.424736973]
},
{
date: new Date('2017-02-23T13:00:00.000Z'),
value: 201039318, anomalyScore: 59.83488, numberOfCauses: 1,
actual: [201039318], typical: [132739.5267403542]
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"mock-job-id": [
{
"detector_description": "mean(responsetime)",
"function": "mean",
"field_name": "responsetime",
"partition_field_name": "airline",
"detector_index": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"job_id": "mock-job-id",
"job_type": "anomaly_detector",
"job_version": "7.0.0-alpha1",
"description": "",
"create_time": 1532692299663,
"finished_time": 1532692304364,
"established_model_memory": 560894,
"analysis_config": {
"bucket_span": "15m",
"detectors": [
{
"detector_description": "mean(responsetime)",
"function": "mean",
"field_name": "responsetime",
"partition_field_name": "airline",
"detector_index": 0
}
],
"influencers": [
"airline"
]
},
"analysis_limits": {
"model_memory_limit": "13mb",
"categorization_examples_limit": 4
},
"data_description": {
"time_field": "@timestamp",
"time_format": "epoch_ms"
},
"model_snapshot_retention_days": 1,
"custom_settings": {
"created_by": "multi-metric-wizard"
},
"model_snapshot_id": "1532692303",
"model_snapshot_min_version": "6.4.0",
"results_index_name": "shared",
"data_counts": {
"job_id": "mock-job-id",
"processed_record_count": 86274,
"processed_field_count": 172548,
"input_bytes": 6744642,
"input_field_count": 172548,
"invalid_date_count": 0,
"missing_field_count": 0,
"out_of_order_timestamp_count": 0,
"empty_bucket_count": 0,
"sparse_bucket_count": 0,
"bucket_count": 479,
"earliest_record_timestamp": 1486425600000,
"latest_record_timestamp": 1486857594000,
"last_data_time": 1532692303844,
"input_record_count": 86274
},
"model_size_stats": {
"job_id": "mock-job-id",
"result_type": "model_size_stats",
"model_bytes": 560894,
"total_by_field_count": 21,
"total_over_field_count": 0,
"total_partition_field_count": 20,
"bucket_allocation_failures_count": 0,
"memory_status": "ok",
"log_time": 1532692303000,
"timestamp": 1486855800000
},
"datafeed_config": {
"datafeed_id": "datafeed-mock-job-id",
"job_id": "mock-job-id",
"query_delay": "86658ms",
"indices": [
"farequote-2017"
],
"types": [],
"query": {
"match_all": {
"boost": 1
}
},
"scroll_size": 1000,
"chunking_config": {
"mode": "auto"
},
"state": "stopped"
},
"state": "closed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"jobId": "population-03",
"detectorIndex": 0,
"metricFunction": "sum",
"timeField": "@timestamp",
"interval": "1h",
"datafeedConfig": {
"datafeed_id": "datafeed-population-03",
"job_id": "population-03",
"query_delay": "60s",
"frequency": "600s",
"indices": [
"filebeat-7.0.0*"
],
"types": [
"doc"
],
"query": {
"match_all": {
"boost": 1
}
},
"scroll_size": 1000,
"chunking_config": {
"mode": "auto"
},
"state": "stopped"
},
"metricFieldName": "nginx.access.body_sent.bytes",
"functionDescription": "sum",
"bucketSpanSeconds": 3600,
"detectorLabel": "high_sum(nginx.access.body_sent.bytes) over nginx.access.remote_ip (population-03)",
"fieldName": "nginx.access.body_sent.bytes",
"entityFields": [
{
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53",
"$$hashKey": "object:813"
}
],
"infoTooltip": {
"jobId": "population-03",
"aggregationInterval": "1h",
"chartFunction": "sum nginx.access.body_sent.bytes",
"entityFields": [
{
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53"
}
]
},
"loading": false,
"plotEarliest": 1487534400000,
"plotLatest": 1488168000000,
"selectedEarliest": 1487808000000,
"selectedLatest": 1487894399999
}
Loading

0 comments on commit e571490

Please sign in to comment.