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

Explain all and Get all API #352

Merged
merged 11 commits into from
Jan 27, 2021
Merged

Explain all and Get all API #352

merged 11 commits into from
Jan 27, 2021

Conversation

bowenlan-amzn
Copy link
Contributor

@bowenlan-amzn bowenlan-amzn commented Dec 9, 2020

Issue #, if available:
#292

Description of changes:
Explain and Get Policy API now support get all functionality, to use it, just don't give any specific query object, directly call GET _opendistro/_ism/explain or _opendistro/_ism/policies, then you can retrieve all managed indices or all policies.

Such get all API can have several query parameters, for example:
GET _opendistro/_ism/policies?from=0&size=20&sortOrder=desc&sortField=policy.last_updated_time&queryString=p*

Transport action name of get all policies API is cluster:admin/opendistro/ism/policy/search
to be consistent with ODFE permission names

Testing

The IT for Get all policies and Explain All are in IndexStateManagementRestApiIT.kt and RestExplainActionIT.kt

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


Example req and res

GET _opendistro/_ism/policies

{
  "policies" : [
    {
      "_id" : "test",
      "_seq_no" : 0,
      "_primary_term" : 1,
      "policy" : {
        "policy_id" : "test",
        "description" : "A simple default policy that changes the replica count between hot and cold states.",
        "last_updated_time" : 1611712067239,
        "schema_version" : 1,
        "error_notification" : null,
        "default_state" : "hot",
        "states" : [
          {
            "name" : "hot",
            "actions" : [
              {
                "replica_count" : {
                  "number_of_replicas" : 0
                }
              }
            ],
            "transitions" : [ ]
          }
        ]
      }
    }
  ],
  "total_policies" : 1
}

GET _opendistro/_ism/explain

{
  "testindex1" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "testindex1",
    "index_uuid" : "WfnICHPuQ9OlYLXupg96Uw",
    "policy_id" : "test",
    "enabled" : true
  },
  "wildindex" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "wildindex",
    "index_uuid" : "47zfTb3JSfe9PGP287glMQ",
    "policy_id" : "test",
    "policy_seq_no" : 0,
    "policy_primary_term" : 1,
    "state" : {
      "name" : "hot",
      "start_time" : 1611712523140
    },
    "retry_info" : {
      "failed" : false,
      "consumed_retries" : 0
    },
    "info" : {
      "message" : "Successfully initialized policy: test"
    },
    "enabled" : true
  },
  "total_managed_indices" : 2
}

GET _opendistro/_ism/explain/testindex1,wildindex

{
  "testindex1" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "testindex1",
    "index_uuid" : "WfnICHPuQ9OlYLXupg96Uw",
    "policy_id" : "test",
    "policy_seq_no" : 0,
    "policy_primary_term" : 1,
    "policy_completed" : true
  },
  "wildindex" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "wildindex",
    "index_uuid" : "47zfTb3JSfe9PGP287glMQ",
    "policy_id" : "test",
    "policy_seq_no" : 0,
    "policy_primary_term" : 1,
    "policy_completed" : true
  }
}

GET _opendistro/_ism/explain/test*

{
  "testindex1" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "testindex1",
    "index_uuid" : "WfnICHPuQ9OlYLXupg96Uw",
    "policy_id" : "test",
    "policy_seq_no" : 0,
    "policy_primary_term" : 1,
    "policy_completed" : true
  }
}

GET _opendistro/_ism/explain?queryString=test*
total managed indices is determined by search response, according to previous logic

{
  "testindex1" : {
    "index.opendistro.index_state_management.policy_id" : "test",
    "index" : "testindex1",
    "index_uuid" : "WfnICHPuQ9OlYLXupg96Uw",
    "policy_id" : "test",
    "policy_seq_no" : 0,
    "policy_primary_term" : 1,
    "state" : {
      "name" : "hot",
      "start_time" : 1611712582258
    },
    "retry_info" : {
      "failed" : false,
      "consumed_retries" : 0
    },
    "info" : {
      "message" : "Successfully initialized policy: test"
    },
    "enabled" : true
  },
  "total_managed_indices" : 1
}

@bowenlan-amzn bowenlan-amzn added Refactor enhancement An improvement on the existing feature’s functionalities labels Dec 9, 2020
@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #352 (1c36ca3) into master (7e52f26) will increase coverage by 0.40%.
The diff coverage is 91.26%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #352      +/-   ##
============================================
+ Coverage     76.72%   77.13%   +0.40%     
- Complexity     1460     1487      +27     
============================================
  Files           188      194       +6     
  Lines          7335     7552     +217     
  Branches       1190     1210      +20     
============================================
+ Hits           5628     5825     +197     
- Misses         1061     1071      +10     
- Partials        646      656      +10     
Impacted Files Coverage Δ Complexity Δ
...ndexstatemanagement/IndexStateManagementHistory.kt 76.19% <ø> (ø) 26.00 <0.00> (ø)
...agement/indexstatemanagement/ManagedIndexRunner.kt 55.04% <ø> (ø) 41.00 <0.00> (ø)
...indexstatemanagement/model/ManagedIndexMetaData.kt 90.06% <ø> (+0.62%) 41.00 <0.00> (ø)
.../indexstatemanagement/model/action/ActionConfig.kt 84.61% <ø> (ø) 9.00 <0.00> (ø)
...ement/step/forcemerge/AttemptCallForceMergeStep.kt 66.66% <ø> (ø) 7.00 <0.00> (ø)
...action/changepolicy/TransportChangePolicyAction.kt 76.72% <ø> (ø) 4.00 <0.00> (ø)
...gement/transport/action/explain/ExplainResponse.kt 100.00% <ø> (ø) 8.00 <0.00> (ø)
...ment/indexstatemanagement/util/RestHandlerUtils.kt 100.00% <ø> (ø) 0.00 <0.00> (ø)
...nt/refreshanalyzer/RefreshSearchAnalyzerRequest.kt 50.00% <ø> (ø) 1.00 <0.00> (ø)
...nt/transport/action/getpolicy/GetPoliciesAction.kt 66.66% <66.66%> (ø) 2.00 <2.00> (?)
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e52f26...1cbcc9e. Read the comment docs.

fix tests after change
@dbbaughe
Copy link
Contributor

Can you add example request/responses to the PR description? Want to see what they look like; try adding different examples, e.g. of no indices (all), multiple indices, wildcards etc.

total_managed_indices
bug fix: when query size = 0 still show total managed indices
@bowenlan-amzn bowenlan-amzn merged commit 2f7d778 into opendistro-for-elasticsearch:master Jan 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement An improvement on the existing feature’s functionalities Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants