Skip to content

Conversation

@cwperks
Copy link
Owner

@cwperks cwperks commented Nov 8, 2024

Description

Adds an API to get scheduled job info provided a job type.

Example API request and response:

> curl -XPOST https://admin:myStrongPassword123\!@localhost:9200/_plugins/_job_scheduler/_schedule\?pretty -H "Content-Type: application/json" --data '{"job_type": "opensearch_time_series_analytics"}' -k

{
  "HKSOCJMBydpWtiBFr9X-" : {
    "index_name" : ".opendistro-anomaly-detector-jobs",
    "job_id" : "HKSOCJMBydpWtiBFr9X-",
    "job_parameter" : {
      "name" : "HKSOCJMBydpWtiBFr9X-",
      "schedule" : {
        "interval" : {
          "start_time" : 1731073222668,
          "period" : 1,
          "unit" : "Minutes"
        }
      },
      "window_delay" : {
        "period" : {
          "interval" : 1,
          "unit" : "Minutes"
        }
      },
      "enabled" : true,
      "enabled_time" : 1731073222668,
      "last_update_time" : 1731073222668,
      "lock_duration_seconds" : 60,
      "type" : "AD",
      "user" : {
        "name" : "admin",
        "backend_roles" : [
          "admin"
        ],
        "roles" : [
          "own_index",
          "all_access"
        ],
        "custom_attribute_names" : [ ],
        "user_requested_tenant" : null
      },
      "result_index" : "opensearch-ad-plugin-result-test"
    },
    "descheduled" : false,
    "actual_previous_execution_time" : "2024-11-08T14:57:22.673439Z",
    "expected_previous_execution_time" : "2024-11-08T14:57:22.668499Z",
    "expected_execution_time" : "2024-11-08T14:58:22.668499Z"
  }
}

Testing

To setup, install JS and AD plugin:

  1. Create index
curl -XPUT https://admin:myStrongPassword123\!@localhost:9200/server_log -k
  1. Index single document
curl -XPOST "https://admin:myStrongPassword123\!@localhost:9200/server_log/_doc/your-document-id" -H "Content-Type: application/json" -k -d'
{
  "field1": "value1",
  "field2": "value2",
  "timestamp": "2024-11-07T00:00:00Z"
}'
  1. Create detector
curl -XPOST https://admin:myStrongPassword123\!@localhost:9200/_plugins/_anomaly_detection/detectors -k -H "Content-Type: application/json" --data '{
  "name": "test-detector",
  "description": "Test detector",
  "time_field": "timestamp",
  "indices": [
    "server_log*"
  ],
  "feature_attributes": [
    {
      "feature_name": "test",
      "feature_enabled": true,
      "aggregation_query": {
        "test": {
          "sum": {
            "field": "value"
          }
        }
      }
    }
  ],
  "filter_query": {
    "bool": {
      "filter": [
        {
          "range": {
            "value": {
              "gt": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "detection_interval": {
    "period": {
      "interval": 1,
      "unit": "Minutes"
    }
  },
  "window_delay": {
    "period": {
      "interval": 1,
      "unit": "Minutes"
    }
  },
  "result_index" : "opensearch-ad-plugin-result-test"
}'
  1. Start Detector
curl -XPOST https://admin:myStrongPassword123\!@localhost:9200/_plugins/_anomaly_detection/detectors/HKSOCJMBydpWtiBFr9X-/_start -k
  1. Call API to get job info provided job type

Related Issues

Related to: opensearch-project#95

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Craig Perkins <[email protected]>
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.

2 participants