Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

suppport HC detector in profile api #274

Merged
merged 2 commits into from
Oct 19, 2020

Conversation

ylwu-amzn
Copy link
Contributor

Issue #, if available:

Description of changes:

Support high cardinality detector in profile API.
1.Total entity count
2.Active entity count
3.Profile entity status: active or not

Add job and detection state index in AD stats API

Did test by starting cluster locally for both single and HC detector.
Exclude some classes which coverage lower than our limitation. Will add more test case in another PR>

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Oct 19, 2020

Codecov Report

Merging #274 into master will decrease coverage by 1.97%.
The diff coverage is 26.44%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #274      +/-   ##
============================================
- Coverage     73.22%   71.24%   -1.98%     
- Complexity     1749     1760      +11     
============================================
  Files           180      185       +5     
  Lines          8119     8430     +311     
  Branches        670      719      +49     
============================================
+ Hits           5945     6006      +61     
- Misses         1864     2088     +224     
- Partials        310      336      +26     
Flag Coverage Δ Complexity Δ
#plugin 70.49% <26.44%> (-2.14%) 1760.00 <18.00> (+11.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...distroforelasticsearch/ad/model/EntityProfile.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...icsearch/ad/rest/RestGetAnomalyDetectorAction.java 40.00% <0.00%> (-2.11%) 4.00 <0.00> (ø)
...asticsearch/ad/transport/EntityProfileRequest.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...sticsearch/ad/transport/EntityProfileResponse.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...earch/ad/transport/GetAnomalyDetectorResponse.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...roforelasticsearch/ad/transport/ProfileAction.java 100.00% <ø> (ø) 2.00 <0.00> (ø)
...stroforelasticsearch/ad/util/RestHandlerUtils.java 96.96% <ø> (ø) 13.00 <0.00> (ø)
...stroforelasticsearch/ad/model/DetectorProfile.java 31.01% <13.33%> (-3.38%) 16.00 <2.00> (+2.00) ⬇️
...d/transport/GetAnomalyDetectorTransportAction.java 47.25% <18.18%> (-3.97%) 9.00 <0.00> (ø)
...elasticsearch/ad/AnomalyDetectorProfileRunner.java 50.98% <28.33%> (-20.69%) 41.00 <9.00> (+2.00) ⬇️
... and 15 more

@ohltyler ohltyler added the enhancement New feature or request label Oct 19, 2020
@@ -140,19 +158,67 @@ private void prepareProfile(

if (profilesToCollect.contains(ProfileName.ERROR)) {
GetRequest getStateRequest = new GetRequest(DetectorInternalState.DETECTOR_STATE_INDEX, detectorId);
client.get(getStateRequest, onGetDetectorState(listener, detectorId, enabledTimeMs));
client.get(getStateRequest, onGetDetectorState(listener, detectorId, enabledTimeMs));// +1
Copy link
Contributor

Choose a reason for hiding this comment

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

extra comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove this

AnomalyDetector detector = AnomalyDetector.parse(parser, detectorId);
List<String> categoryField = detector.getCategoryField();
if (categoryField == null || categoryField.size() != 1) {
listener.onResponse(new EntityProfile(categoryField.get(0), entityValue, false));
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess categoryField.get(0) will throw NPE if categoryField is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. will fix.

Copy link
Contributor

@yizheliu-amazon yizheliu-amazon left a comment

Choose a reason for hiding this comment

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

thanks for the change

@ylwu-amzn ylwu-amzn merged commit 3a9d6c9 into opendistro-for-elasticsearch:master Oct 19, 2020
@@ -23,7 +23,7 @@
public class ProfileAction extends ActionType<ProfileResponse> {

public static final ProfileAction INSTANCE = new ProfileAction();
public static final String NAME = "cluster:admin/ad/detector/profile";
public static final String NAME = "cluster:admin/opendistro/ad/detectors/profile";
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need also update this name for the FGAC changes? I remember we need have these names in the permission

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Sarat will address all transport action names later. External and internal transport name should follow different pattern. This action should be internal action.

@@ -111,4 +111,8 @@ public void failImmediately(String errMsg, Exception e) {
public void respondImmediately(T o) {
this.delegate.onResponse(o);
}

public void compareAndSetMaxResponseCount(int oldValue, int newValue) {
this.maxResponseCount.compareAndSet(oldValue, newValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

how about the false result? do we need handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The client of this method need to take care of this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think this will cause any big issue. but logically, should the result be returned to the client if they need take care of it?

aggBuilder.field(categoryField.get(0));
searchSourceBuilder.aggregation(aggBuilder);

SearchRequest request = new SearchRequest(detector.getIndices().toArray(new String[0]), searchSourceBuilder);
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this detector index managed? Are there one/multi indices for each detector? I have this question because i don't see detector id in the search request.

String nodeId = node.get().getId();
DiscoveryNode localNode = clusterService.localNode();
if (localNode.getId().equals(nodeId)) {
listener.onResponse(new EntityProfileResponse((cacheProvider.get().isActive(adID, modelId))));
Copy link
Contributor

Choose a reason for hiding this comment

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

how about cache missing case?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants