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
resp = client.watcher.put_watch(
id="my_watch",
trigger={
"schedule": {
"yearly": {
"in": "february",
"on": 29,
"at": "noon"
}
}
},
input={
"simple": {
"payload": {
"send": "yes"
}
}
},
condition={
"always": {}
},
actions={
"test_index": {
"throttle_period": "15m",
"index": {
"index": "test"
}
}
},
)
print(resp)
Js
const response = await client.watcher.putWatch({
id: "my_watch",
trigger: {
schedule: {
yearly: {
in: "february",
on: 29,
at: "noon",
},
},
},
input: {
simple: {
payload: {
send: "yes",
},
},
},
condition: {
always: {},
},
actions: {
test_index: {
throttle_period: "15m",
index: {
index: "test",
},
},
},
});
console.log(response);
Console
PUT _watcher/watch/my_watch
{
"trigger" : {
"schedule" : {
"yearly" : { "in" : "february", "on" : 29, "at" : "noon" }
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always": {}
},
"actions": {
"test_index": {
"throttle_period": "15m",
"index": {
"index": "test"
}
}
}
}
ウォッチを呼び出すと、ウォッチの定義とともにウォッチの現在の状態とそのアクションの状態が返されます。Get Watch API:
Python
resp = client.watcher.get_watch(
id="my_watch",
)
print(resp)
Js
const response = await client.watcher.getWatch({
id: "my_watch",
});
console.log(response);
Console
GET _watcher/watch/my_watch
新しく作成されたウォッチのアクション状態はawaits_successful_execution
です:
Console-Result
{
"found": true,
"_seq_no": 0,
"_primary_term": 1,
"_version": 1,
"_id": "my_watch",
"status": {
"version": 1,
"actions": {
"test_index": {
"ack": {
"timestamp": "2015-05-26T18:04:27.723Z",
"state": "awaits_successful_execution"
}
}
},
"state": ...
},
"watch": ...
}
ウォッチが実行され、条件が一致すると、ack.state
の値がackable
に変わります。ウォッチの実行を強制し、再度取得して状態を確認しましょう:
Python
resp = client.watcher.execute_watch(
id="my_watch",
record_execution=True,
)
print(resp)
resp1 = client.watcher.get_watch(
id="my_watch",
)
print(resp1)
Js
const response = await client.watcher.executeWatch({
id: "my_watch",
record_execution: true,
});
console.log(response);
const response1 = await client.watcher.getWatch({
id: "my_watch",
});
console.log(response1);
Console
POST _watcher/watch/my_watch/_execute
{
"record_execution" : true
}
GET _watcher/watch/my_watch
Console-Result
{
"found": true,
"_id": "my_watch",
"_seq_no": 1,
"_primary_term": 1,
"_version": 2,
"status": {
"version": 2,
"actions": {
"test_index": {
"ack": {
"timestamp": "2015-05-26T18:04:27.723Z",
"state": "ackable"
},
"last_execution" : {
"timestamp": "2015-05-25T18:04:27.723Z",
"successful": true
},
"last_successful_execution" : {
"timestamp": "2015-05-25T18:04:27.723Z",
"successful": true
}
}
},
"state": ...,
"execution_state": "executed",
"last_checked": ...,
"last_met_condition": ...
},
"watch": ...
}
これを確認できます:
Python
resp = client.watcher.ack_watch(
watch_id="my_watch",
action_id="test_index",
)
print(resp)
resp1 = client.watcher.get_watch(
id="my_watch",
)
print(resp1)
Js
const response = await client.watcher.ackWatch({
watch_id: "my_watch",
action_id: "test_index",
});
console.log(response);
const response1 = await client.watcher.getWatch({
id: "my_watch",
});
console.log(response1);
Console
PUT _watcher/watch/my_watch/_ack/test_index
GET _watcher/watch/my_watch
Console-Result
{
"found": true,
"_id": "my_watch",
"_seq_no": 2,
"_primary_term": 1,
"_version": 3,
"status": {
"version": 3,
"actions": {
"test_index": {
"ack": {
"timestamp": "2015-05-26T18:04:27.723Z",
"state": "acked"
},
"last_execution" : {
"timestamp": "2015-05-25T18:04:27.723Z",
"successful": true
},
"last_successful_execution" : {
"timestamp": "2015-05-25T18:04:27.723Z",
"successful": true
}
}
},
"state": ...,
"execution_state": "executed",
"last_checked": ...,
"last_met_condition": ...
},
"watch": ...
}
アクションを確認すると、そのアクションのさらなる実行がack.state
がawaits_successful_execution
にリセットされるまでスロットルされます。これは、ウォッチの条件が満たされないときに発生します(条件がfalse
に評価されます)。
#### Python
``````python
resp = client.watcher.ack_watch(
watch_id="my_watch",
action_id="action1,action2",
)
print(resp)
`
Js
const response = await client.watcher.ackWatch({
watch_id: "my_watch",
action_id: "action1,action2",
});
console.log(response);
Console
POST _watcher/watch/my_watch/_ack/action1,action2
ウォッチのすべてのアクションを確認するには、actions
パラメータを省略するだけです:
Python
resp = client.watcher.ack_watch(
watch_id="my_watch",
)
print(resp)
Js
const response = await client.watcher.ackWatch({
watch_id: "my_watch",
});
console.log(response);
Console
POST _watcher/watch/my_watch/_ack
レスポンスはウォッチ取得レスポンスのように見えますが、状態のみを含みます:
Console-Result
{
"status": {
"state": {
"active": true,
"timestamp": "2015-05-26T18:04:27.723Z"
},
"last_checked": "2015-05-26T18:04:27.753Z",
"last_met_condition": "2015-05-26T18:04:27.763Z",
"actions": {
"test_index": {
"ack" : {
"timestamp": "2015-05-26T18:04:27.713Z",
"state": "acked"
},
"last_execution" : {
"timestamp": "2015-05-25T18:04:27.733Z",
"successful": true
},
"last_successful_execution" : {
"timestamp": "2015-05-25T18:04:27.773Z",
"successful": true
}
}
},
"execution_state": "executed",
"version": 2
}
}