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

Make profile and stats API compatible with multi-category field. #79

Closed
wants to merge 3 commits into from

Conversation

kaituo
Copy link
Collaborator

@kaituo kaituo commented May 26, 2021

Description

Previously, our profile API only took one entity key and value pair in the command as parameters. Using parameters won't work when moving to multi-category fields. This PR allows users to put the entity information on the request body in JSON format.

Also, we use the GET method to call profile API. As mentioned earlier, we added a request body with entity attributes. Some CLI tools require an API with a request body that uses the POST method. So we also allow a profile API with the POST method.

What's more, we didn't show entity attributes on model output as the model id carries entity values. A multi-category entity's model id is a hash instead of concrete entity attributes. So we added the entity attributes to the response output. Similar changes are also added for stats API.

Testing done:

  1. manual testing using a local cluster.

Profile API:

Sample  request:
http://localhost:9200/_opendistro/_anomaly_detection/detectors/TSB5cnkBbTSBdroveJIW/_profile/models
{
	"entity": [{
			"name": "service",
			"value": "app_6"
		},
		{
			"name": "host",
			"value": "server_1"
		}
	]
}

Response:
{
	"model": {
		"model_id": "7sF5qXkBxjkVBFJhhe5K_entity_ZoNYVJsq5ry6e-SWXmAt1Q",
		"entity": [{
				"name": "host",
				"value": "server_1"
			},
			{
				"name": "service",
				"value": "app_6"
			}
		],
		"model_size_in_bytes": 712480,
		"node_id": "LSNdy0zzR_273CGX1EFR2A"
	}
}

Stats API:

Sample request:
localhost:9200/_opendistro/_anomaly_detection/stats

response:

{
	"anomaly_detectors_index_status": "yellow",
	"anomaly_detection_state_status": "yellow",
	"detector_count": 1,
	"anomaly_detection_job_index_status": "yellow",
	"models_checkpoint_index_status": "yellow",
	"anomaly_results_index_status": "yellow",
	"historical_single_entity_detector_count": 0,
	"nodes": {
		"LSNdy0zzR_273CGX1EFR2A": {
			"ad_execute_request_count": 30,
			"models": [{
					"detector_id": "7sF5qXkBxjkVBFJhhe5K",
					"model_type": "entity",
					"model_id": "7sF5qXkBxjkVBFJhhe5K_entity_412FoQwCykWTAhjVfDGQDg",
					"entity": [{
							"name": "host",
							"value": "server_1"
						},
						{
							"name": "service",
							"value": "app_2"
						}
					]
				},
				{
					"detector_id": "7sF5qXkBxjkVBFJhhe5K",
					"model_type": "entity",
					"model_id": "7sF5qXkBxjkVBFJhhe5K_entity_FuqXh0HBXlPhKepOc6JADQ",
					"entity": [{
							"name": "host",
							"value": "server_3"
						},
						{
							"name": "service",
							"value": "app_6"
						}
					]
				}, …
				{
					"detector_id": "7sF5qXkBxjkVBFJhhe5K",
					"model_type": "entity",
					"model_id": "7sF5qXkBxjkVBFJhhe5K_entity_B4zrbSQ1-pvdBLx0FzQxvw",
					"entity": [{
							"name": "host",
							"value": "server_3"
						},
						{
							"name": "service",
							"value": "app_3"
						}
					]
				}
			],
			"ad_canceled_batch_task_count": 0,
			"ad_hc_execute_request_count": 30,
			"ad_hc_execute_failure_count": 0,
			"ad_execute_failure_count": 0,
			"ad_batch_task_failure_count": 0,
			"ad_total_batch_task_execution_count": 0,
			"ad_executing_batch_task_count": 0
		}
	}
}

Check List

  • [ Y ] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Previously, our profile API only took one entity key and value pair in the command as parameters. Using parameters won't work when moving to multi-category fields. This PR allows users to put the entity information on the request body in JSON format.

Also, we use the GET method to call profile API. As mentioned earlier, we added a request body with entity attributes. Some CLI tools require an API with a request body that uses the POST method. So we also allow a profile API with the POST method.

What's more, we didn't show entity attributes on model output as the model id carries entity values. A multi-category entity's model id is a hash instead of concrete entity attributes. So we added the entity attributes to the response output. Similar changes are also added for stats API.

Testing done:
1. manual testing using a local cluster.
return;
}
for (String field : categoryFields) {
if (false == attributes.containsKey(field)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you could write as !attributes.containsKey(field)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchRequest searchRequest = new SearchRequest(detector.getIndices().toArray(new String[0]), searchSourceBuilder)
.preference(Preference.LOCAL.toString());

client.search(searchRequest, ActionListener.wrap(searchResponse -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share some information here: why do you run search for an entity validation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to do it in case of typos for example. The entity is given by the API user. Not sure it actually exists or not. Added a method comment to explain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user delete the entity after job start, then we will not be able to get this entity in index. For this case, we will not return profile for this entity even it's running on some data node?

Copy link
Collaborator Author

@kaituo kaituo Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the entity's model will be deleted by other entity or by maintenance due to long inactivity. Added to comments.

/* HCAD profile request:
* GET _opendistro/_anomaly_detection/detectors/<detectorId>/_profile/init_progress
* {
* "entity": [{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: add * to every lines to keep the same style of the comments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Contributor

@spbjss spbjss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

*/

/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this license header for new file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@kaituo kaituo closed this Jun 29, 2021
kaituo added a commit that referenced this pull request Jul 12, 2021
This PR is a conglomerate of the following PRs.

#60
#64
#65
#67
#68
#69
#70
#71
#74
#75
#76
#77
#78
#79
#82
#83
#84
#92
#94
#93
#95
kaituo#1
kaituo#2
kaituo#3
kaituo#4
kaituo#5
kaituo#6
kaituo#7
kaituo#8
kaituo#9
kaituo#10

This spreadsheet contains the mappings from files to PR number (bug fix in my AD fork and tests are not included):
https://gist.github.com/kaituo/9e1592c4ac4f2f449356cb93d0591167
ohltyler pushed a commit that referenced this pull request Sep 1, 2021
This PR is a conglomerate of the following PRs.

#60
#64
#65
#67
#68
#69
#70
#71
#74
#75
#76
#77
#78
#79
#82
#83
#84
#92
#94
#93
#95
kaituo#1
kaituo#2
kaituo#3
kaituo#4
kaituo#5
kaituo#6
kaituo#7
kaituo#8
kaituo#9
kaituo#10

This spreadsheet contains the mappings from files to PR number (bug fix in my AD fork and tests are not included):
https://gist.github.com/kaituo/9e1592c4ac4f2f449356cb93d0591167
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants