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

Migrate Search Detector tasks to SDK using SDKRestClient #380

Closed
2 tasks done
Tracked by #5224
dbwiddis opened this issue Jan 29, 2023 · 2 comments
Closed
2 tasks done
Tracked by #5224

Migrate Search Detector tasks to SDK using SDKRestClient #380

dbwiddis opened this issue Jan 29, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@dbwiddis
Copy link
Member

dbwiddis commented Jan 29, 2023

Is your feature request related to a problem?

Part of opensearch-project/OpenSearch#5224

What solution would you like?

Migrate the Search Detector tasks Rest API to Extensions SDK using SDKRestClient.

Use the implementation of #353 as a reference. Add new issues for any steps you skip.

Implement the following API endpoints:

  • GET _plugins/_anomaly_detection/detectors/tasks/_search
  • POST _plugins/_anomaly_detection/detectors/tasks/_search
@owaiskazi19
Copy link
Member

The migration work is done in the attached PR.
Wasn't able to test the workflow as the API fails with

 "error": "Request failed with exception: [[.opendistro-anomaly-detection-state] OpenSearchStatusException[OpenSearch exception [type=index_not_found_exception, reason=no such index [.opendistro-anomaly-detection-state]]]]"

.opendistro-anomaly-detection-state index will be created as the part of #383

@owaiskazi19
Copy link
Member

API: 127.0.0.1:9200/_extensions/_ad-extension/detectors/tasks/_search with GET and POST
Query:

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "detector_id": "-TZfXYcBZWahDDF-C6Mh"
          }
        },
        {
          "term": {
            "task_type": "REALTIME_SINGLE_ENTITY"
          }
        },
        {
          "term": {
            "is_latest": "true"
          }
        }
      ]
    }
  }
}

Response:

{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": ".opendistro-anomaly-detection-state",
                "_id": "-zZfXYcBZWahDDF-a6MO",
                "_version": 1,
                "_seq_no": 105,
                "_primary_term": 29,
                "_score": 0.0,
                "_source": {
                    "detector_id": "-TZfXYcBZWahDDF-C6Mh",
                    "task_progress": 0.0,
                    "last_update_time": 1680898747146,
                    "execution_start_time": 1680898747146,
                    "state": "CREATED",
                    "task_type": "REALTIME_SINGLE_ENTITY",
                    "init_progress": 0.0,
                    "is_latest": true,
                    "detector": {
                        "description": "Test detector",
                        "feature_attributes": [
                            {
                                "feature_id": "n4JeXYcBnxLZhpku4uYI",
                                "feature_enabled": true,
                                "feature_name": "test",
                                "aggregation_query": {
                                    "test": {
                                        "sum": {
                                            "field": "value"
                                        }
                                    }
                                }
                            }
                        ],
                        "schema_version": 0,
                        "time_field": "timestamp",
                        "last_update_time": 1680898722589,
                        "indices": [
                            "server_log*"
                        ],
                        "window_delay": {
                            "period": {
                                "unit": "Minutes",
                                "interval": 1
                            }
                        },
                        "result_index": "opensearch-ad-plugin-result-test1",
                        "detection_interval": {
                            "period": {
                                "unit": "Minutes",
                                "interval": 1
                            }
                        },
                        "name": "test-detector13",
                        "filter_query": {
                            "bool": {
                                "filter": [
                                    {
                                        "range": {
                                            "value": {
                                                "include_lower": false,
                                                "include_upper": true,
                                                "from": 1,
                                                "boost": 1.0,
                                                "to": null
                                            }
                                        }
                                    }
                                ],
                                "adjust_pure_negative": true,
                                "boost": 1.0
                            }
                        },
                        "shingle_size": 8,
                        "detector_type": "SINGLE_ENTITY"
                    }
                }
            }
        ]
    }
}

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

No branches or pull requests

2 participants