Ack watch API

ウォッチの確認により、ウォッチのアクションの実行を手動でスロットルできます。

Request

PUT _watcher/watch/<watch_id>/_ack

PUT _watcher/watch/<watch_id>/_ack/<action_id>

Prerequisites

  • このAPIを使用するには、manage_watcherクラスターの権限が必要です。詳細については、セキュリティ権限を参照してください。

Description

アクションの確認状態は、status.actions.<id>.ack.state構造体に保存されます。

指定されたウォッチが現在実行中の場合、このAPIはエラーを返します。これは、ウォッチの実行からウォッチの状態が上書きされるのを防ぐためです。

Path parameters

  • <action_id>
  • (オプション、リスト)確認するアクションIDのカンマ区切りリスト。 このパラメータを省略すると、ウォッチのすべてのアクションが確認されます。
  • <watch_id>
  • (必須、文字列)ウォッチの識別子。

Examples

新しいウォッチを作成してみましょう:

Python

  1. resp = client.watcher.put_watch(
  2. id="my_watch",
  3. trigger={
  4. "schedule": {
  5. "yearly": {
  6. "in": "february",
  7. "on": 29,
  8. "at": "noon"
  9. }
  10. }
  11. },
  12. input={
  13. "simple": {
  14. "payload": {
  15. "send": "yes"
  16. }
  17. }
  18. },
  19. condition={
  20. "always": {}
  21. },
  22. actions={
  23. "test_index": {
  24. "throttle_period": "15m",
  25. "index": {
  26. "index": "test"
  27. }
  28. }
  29. },
  30. )
  31. print(resp)

Js

  1. const response = await client.watcher.putWatch({
  2. id: "my_watch",
  3. trigger: {
  4. schedule: {
  5. yearly: {
  6. in: "february",
  7. on: 29,
  8. at: "noon",
  9. },
  10. },
  11. },
  12. input: {
  13. simple: {
  14. payload: {
  15. send: "yes",
  16. },
  17. },
  18. },
  19. condition: {
  20. always: {},
  21. },
  22. actions: {
  23. test_index: {
  24. throttle_period: "15m",
  25. index: {
  26. index: "test",
  27. },
  28. },
  29. },
  30. });
  31. console.log(response);

Console

  1. PUT _watcher/watch/my_watch
  2. {
  3. "trigger" : {
  4. "schedule" : {
  5. "yearly" : { "in" : "february", "on" : 29, "at" : "noon" }
  6. }
  7. },
  8. "input": {
  9. "simple": {
  10. "payload": {
  11. "send": "yes"
  12. }
  13. }
  14. },
  15. "condition": {
  16. "always": {}
  17. },
  18. "actions": {
  19. "test_index": {
  20. "throttle_period": "15m",
  21. "index": {
  22. "index": "test"
  23. }
  24. }
  25. }
  26. }

ウォッチを呼び出すと、ウォッチの定義とともにウォッチの現在の状態とそのアクションの状態が返されます。Get Watch API:

Python

  1. resp = client.watcher.get_watch(
  2. id="my_watch",
  3. )
  4. print(resp)

Js

  1. const response = await client.watcher.getWatch({
  2. id: "my_watch",
  3. });
  4. console.log(response);

Console

  1. GET _watcher/watch/my_watch

新しく作成されたウォッチのアクション状態はawaits_successful_executionです:

Console-Result

  1. {
  2. "found": true,
  3. "_seq_no": 0,
  4. "_primary_term": 1,
  5. "_version": 1,
  6. "_id": "my_watch",
  7. "status": {
  8. "version": 1,
  9. "actions": {
  10. "test_index": {
  11. "ack": {
  12. "timestamp": "2015-05-26T18:04:27.723Z",
  13. "state": "awaits_successful_execution"
  14. }
  15. }
  16. },
  17. "state": ...
  18. },
  19. "watch": ...
  20. }

ウォッチが実行され、条件が一致すると、ack.stateの値がackableに変わります。ウォッチの実行を強制し、再度取得して状態を確認しましょう:

Python

  1. resp = client.watcher.execute_watch(
  2. id="my_watch",
  3. record_execution=True,
  4. )
  5. print(resp)
  6. resp1 = client.watcher.get_watch(
  7. id="my_watch",
  8. )
  9. print(resp1)

Js

  1. const response = await client.watcher.executeWatch({
  2. id: "my_watch",
  3. record_execution: true,
  4. });
  5. console.log(response);
  6. const response1 = await client.watcher.getWatch({
  7. id: "my_watch",
  8. });
  9. console.log(response1);

Console

  1. POST _watcher/watch/my_watch/_execute
  2. {
  3. "record_execution" : true
  4. }
  5. GET _watcher/watch/my_watch

アクションは現在ackable状態にあります:

Console-Result

  1. {
  2. "found": true,
  3. "_id": "my_watch",
  4. "_seq_no": 1,
  5. "_primary_term": 1,
  6. "_version": 2,
  7. "status": {
  8. "version": 2,
  9. "actions": {
  10. "test_index": {
  11. "ack": {
  12. "timestamp": "2015-05-26T18:04:27.723Z",
  13. "state": "ackable"
  14. },
  15. "last_execution" : {
  16. "timestamp": "2015-05-25T18:04:27.723Z",
  17. "successful": true
  18. },
  19. "last_successful_execution" : {
  20. "timestamp": "2015-05-25T18:04:27.723Z",
  21. "successful": true
  22. }
  23. }
  24. },
  25. "state": ...,
  26. "execution_state": "executed",
  27. "last_checked": ...,
  28. "last_met_condition": ...
  29. },
  30. "watch": ...
  31. }

これを確認できます:

Python

  1. resp = client.watcher.ack_watch(
  2. watch_id="my_watch",
  3. action_id="test_index",
  4. )
  5. print(resp)
  6. resp1 = client.watcher.get_watch(
  7. id="my_watch",
  8. )
  9. print(resp1)

Js

  1. const response = await client.watcher.ackWatch({
  2. watch_id: "my_watch",
  3. action_id: "test_index",
  4. });
  5. console.log(response);
  6. const response1 = await client.watcher.getWatch({
  7. id: "my_watch",
  8. });
  9. console.log(response1);

Console

  1. PUT _watcher/watch/my_watch/_ack/test_index
  2. GET _watcher/watch/my_watch

Console-Result

  1. {
  2. "found": true,
  3. "_id": "my_watch",
  4. "_seq_no": 2,
  5. "_primary_term": 1,
  6. "_version": 3,
  7. "status": {
  8. "version": 3,
  9. "actions": {
  10. "test_index": {
  11. "ack": {
  12. "timestamp": "2015-05-26T18:04:27.723Z",
  13. "state": "acked"
  14. },
  15. "last_execution" : {
  16. "timestamp": "2015-05-25T18:04:27.723Z",
  17. "successful": true
  18. },
  19. "last_successful_execution" : {
  20. "timestamp": "2015-05-25T18:04:27.723Z",
  21. "successful": true
  22. }
  23. }
  24. },
  25. "state": ...,
  26. "execution_state": "executed",
  27. "last_checked": ...,
  28. "last_met_condition": ...
  29. },
  30. "watch": ...
  31. }

アクションを確認すると、そのアクションのさらなる実行がack.stateawaits_successful_executionにリセットされるまでスロットルされます。これは、ウォッチの条件が満たされないときに発生します(条件がfalseに評価されます)。

  1. #### Python
  2. ``````python
  3. resp = client.watcher.ack_watch(
  4. watch_id="my_watch",
  5. action_id="action1,action2",
  6. )
  7. print(resp)
  8. `

Js

  1. const response = await client.watcher.ackWatch({
  2. watch_id: "my_watch",
  3. action_id: "action1,action2",
  4. });
  5. console.log(response);

Console

  1. POST _watcher/watch/my_watch/_ack/action1,action2

ウォッチのすべてのアクションを確認するには、actionsパラメータを省略するだけです:

Python

  1. resp = client.watcher.ack_watch(
  2. watch_id="my_watch",
  3. )
  4. print(resp)

Js

  1. const response = await client.watcher.ackWatch({
  2. watch_id: "my_watch",
  3. });
  4. console.log(response);

Console

  1. POST _watcher/watch/my_watch/_ack

レスポンスはウォッチ取得レスポンスのように見えますが、状態のみを含みます:

Console-Result

  1. {
  2. "status": {
  3. "state": {
  4. "active": true,
  5. "timestamp": "2015-05-26T18:04:27.723Z"
  6. },
  7. "last_checked": "2015-05-26T18:04:27.753Z",
  8. "last_met_condition": "2015-05-26T18:04:27.763Z",
  9. "actions": {
  10. "test_index": {
  11. "ack" : {
  12. "timestamp": "2015-05-26T18:04:27.713Z",
  13. "state": "acked"
  14. },
  15. "last_execution" : {
  16. "timestamp": "2015-05-25T18:04:27.733Z",
  17. "successful": true
  18. },
  19. "last_successful_execution" : {
  20. "timestamp": "2015-05-25T18:04:27.773Z",
  21. "successful": true
  22. }
  23. }
  24. },
  25. "execution_state": "executed",
  26. "version": 2
  27. }
  28. }