Datadog
連接
從終端機連接Datadog。傳入--help可查看Datadog接受的旗標。
polylane integration connect --type datadog你Datadog站台的API金鑰與應用程式金鑰。
連接Datadog,讓代理可以在調查期間查詢你的日誌、指標、監控器與儀表板。
設定
- 選擇你的Datadog站台(US1、US3、US5、EU1、AP1等)。檢查你的Datadog URL:
app.datadoghq.com是US1,app.datadoghq.eu是EU1。 - 輸入來自Organization Settings → API Keys的API金鑰。
- 輸入來自Organization Settings → Application Keys的應用程式金鑰。
- Polylane驗證兩把金鑰並完成連接。
沒有範圍限制的應用程式金鑰擁有與你使用者相同的存取權,可直接使用。如果你為金鑰設定範圍,請包含user_app_keys(連接所必需)加上logs_read_data、timeseries_query、metrics_read、monitors_read、monitors_write、monitors_downtime、dashboards_read、slos_read、hosts_read、events_read、incident_read、apm_read、aws_configuration_read與create_webhooks。你的金鑰在儲存前會先加密,代理永遠看不到它們。
連接會在Datadog中建立一個名為polylane的webhook並讓每個監控器訂閱它,所以警示會落到Polylane並在觸發時被分流。
代理能做什麼
- 以Datadog查詢語法搜尋與篩選日誌
- 讀取指標值與隨時間的趨勢
- 檢查哪些監控器正在警示及其狀態
- 在調查中參照儀表板資料
中斷連接
在Polylane中斷Datadog的連接,然後在Datadog中撤銷應用程式金鑰與API金鑰。
把Datadog的警示與你以Terraform管理的資源一起註冊到Polylane。
Polylane透過在監控器的訊息中附加@webhook-polylane提及並加入polylane:managed標籤來訂閱該監控器。一個週期性同步會把兩者套用到每個監控器,所以以Terraform管理的監控器在其Terraform設定也帶有它們之前會顯示漂移。把兩者都加到每個監控器:
resource "datadog_monitor" "high_error_rate" {
name = "High error rate on checkout"
type = "metric alert"
query = "sum(last_5m):sum:trace.http.request.errors{service:checkout}.as_count() > 50"
message = <<-EOT
{{#is_alert}}Error rate on checkout is above threshold.{{/is_alert}}
@webhook-polylane
EOT
tags = concat(var.tags, ["polylane:managed"])
}
最簡單的設定是讓webhook本身由Polylane管理,只把提及與標籤放進Terraform。如果你也在Terraform中管理webhook,請匯入現有的那一個而不是建立它,因為Datadog的webhook名稱是唯一的。先加入資源區塊,然後匯入:
resource "datadog_webhook" "polylane" {
name = "polylane"
url = "https://sinks.polylane.com/v1/datadog"
encode_as = "json"
custom_headers = jsonencode({
"x-polylane-telemetry-token" = var.polylane_telemetry_token
})
payload = jsonencode({
alert_id = "$ALERT_ID"
alert_metric = "$ALERT_METRIC"
alert_query = "$ALERT_QUERY"
alert_scope = "$ALERT_SCOPE"
alert_status = "$ALERT_STATUS"
alert_title = "$ALERT_TITLE"
alert_transition = "$ALERT_TRANSITION"
alert_type = "$ALERT_TYPE"
date = "$DATE_POSIX"
event_msg = "$EVENT_MSG"
event_title = "$EVENT_TITLE"
event_type = "$EVENT_TYPE"
hostname = "$HOSTNAME"
id = "$ID"
link = "$LINK"
logs_sample = "$LOGS_SAMPLE"
org_id = "$ORG_ID"
org_name = "$ORG_NAME"
priority = "$PRIORITY"
snapshot = "$SNAPSHOT"
tags = "$TAGS"
user = "$USER"
username = "$USERNAME"
})
}
terraform import datadog_webhook.polylane polylane
遙測權杖用來驗證送到你工作區的警示投遞。在Polylane的Settings → Telemetry tokens底下找到它(名為datadog-integration的權杖),或在同一頁建立一把新權杖。重新連接整合會用新的權杖重新建立webhook,所以匯入的webhook之後需要更新它的權杖變數。
中斷連接
中斷連接會停止所有同步與檢查,並刪除Polylane持有的憑證。 Polylane會移除Datadog的API允許它移除的東西。以下項目會留下,直到你自行移除:
- @webhook-polylane appended to every monitor message
- polylane:managed tag on every monitor
polylane integration disconnect <id>工具
12代理可以在對話串中執行的操作。