นี่คือชุดข้อมูล Bigquery ธรรมดาซึ่งประกอบด้วยเหตุการณ์ Google Cloud Service Health (CSH)
คุณสามารถใช้สิ่งนี้เพื่อค้นหาเหตุการณ์และกรองเหตุการณ์ที่คุณสนใจ
มันปลุกเร้าทุกนาที หากไม่มีการอัปเดตการหยุดทำงานที่มีอยู่หรือตรวจไม่พบการหยุดทำงานใหม่ จะไม่มีการแทรกแถวใหม่
คุณยังใช้สิ่งนี้ร่วมกับ Asset Inventory API เพื่อเชื่อมโยงเหตุการณ์ในตำแหน่ง/ภูมิภาคที่กำหนดกับเนื้อหาที่อาจได้รับผลกระทบได้อีกด้วย
อย่างไรก็ตาม แดชบอร์ด CSH
ที่มีอยู่จะให้ข้อมูลในรูปแบบต่างๆ เช่น RSS
และ JSON
และในขณะที่คุณสามารถส่งคำถามและตัวกรองง่ายๆ โดยใช้ jq
curl -s https://status.cloud.google.com/incidents.json | jq -r ' .[] | select(.service_name == "Google Compute Engine") '
อย่างไรก็ตาม มันไม่ได้อยู่ในรูปแบบที่ใช้งานง่าย
ดังนั้น แทนที่จะเป็น raw json แล้วในตาราง bigquery ที่คุณหรือใครๆ ก็สามารถใช้ได้...
นี่คือชุดข้อมูล:
หากต้องการใช้สิ่งนี้ ให้เพิ่มโปรเจ็กต์ต่อไปนี้ลงใน UI gcp-status-log
ก่อน เมื่อดำเนินการเสร็จแล้ว คำถามใดๆ ที่คุณออกจะใช้ชุดข้อมูลนี้ แต่จะเรียกเก็บเงินโปรเจ็กต์ของคุณสำหรับการใช้งานของคุณเอง (เช่น ฉันแค่ให้ข้อมูล...แบบสอบถามที่คุณเรียกใช้คือสิ่งที่คุณจะจ่าย)
หมายเหตุ: Google ไม่ รองรับพื้นที่เก็บข้อมูล ชุดข้อมูล และโค้ดนี้ ตัวเตือนคำเตือน
bq query --nouse_legacy_sql '
SELECT
DISTINCT(id), service_name,severity,external_desc, begin,`end` , modified
FROM
gcp-status-log.status_dataset.status
WHERE
service_name = "Google Compute Engine"
ORDER BY
modified
'
+----------------------+-----------------------+----------+-----------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+---------------------+
| id | service_name | severity | external_desc | begin | end | modified |
+----------------------+-----------------------+----------+-----------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+---------------------+
| pxD6QciVMd9gLQGcREbV | Google Compute Engine | medium | Requests to and from Google Compute Instances in us-west2 may see increase traffic loss when using the instance's public IP | 2021-05-05 02:11:10 | 2021-05-05 04:54:57 | 2021-05-05 04:54:57 |
| LGFBxyLwbh92E47fAzJ5 | Google Compute Engine | medium | Mutliregional Price for E2 Free Tier core is set incorrectly | 2021-08-01 07:00:00 | 2021-08-04 23:18:00 | 2021-08-05 17:35:12 |
| gwKjX9Lukav15SaFPbBF | Google Compute Engine | medium | us-central1, europe-west1, us-west1, asia-east1: Issue with Local SSDs on Google Compute Engine. | 2021-09-01 02:35:00 | 2021-09-03 03:55:00 | 2021-09-07 21:39:46 |
| rjF86FbooET3FDpMV9w1 | Google Compute Engine | medium | Increased VM failure rates in a subset of Google Cloud zones | 2021-09-17 15:00:00 | 2021-09-17 18:25:00 | 2021-09-20 23:33:53 |
| ZoUf49v2qbJ9xRK63kaM | Google Compute Engine | medium | Some Users might have received credit cards deemed invalid email erroneously. | 2021-11-13 07:14:48 | 2021-11-13 08:29:30 | 2021-11-13 08:29:30 |
| SjJ3FN51MAEJy7cZmoss | Google Compute Engine | medium | Global: pubsub.googleapis.com autoscaling not worked as expected | 2021-12-07 09:56:00 | 2021-12-14 00:59:00 | 2021-12-14 19:59:08 |
+----------------------+-----------------------+----------+-----------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+---------------------+
...และนั่นคือขีดจำกัดทักษะของฉันกับ BQ หากคุณมีคำถามที่แนะนำใดๆ ที่คุณเขียน โปรดส่งข้อความถึงฉันในปัญหา GitHub
Schema ที่ใช้ในที่นี้ค่อนข้างเป็นรูปแบบเดียวกับที่ได้รับจากเอาต์พุต JSON ของแดชบอร์ดที่แสดงใน events.schema.json
ข้อแตกต่างเพียงอย่างเดียวคือแต่ละแถวใน BQ เป็นเหตุการณ์เดี่ยวๆ ซึ่งตรงข้ามกับเหตุการณ์ทั้งหมดที่รวมไว้ใน JSON เดียวตามสคีมาที่ให้ไว้ข้างต้น
นอกจากนี้ สคีมานี้ยังมีคอลัมน์ใหม่ 2 คอลัมน์:
insert_timestamp
: นี่คือ TIMESTAMP
เมื่อมีการแทรกแถว/เหตุการณ์snapshot_hash
: นี่คือแฮชที่เข้ารหัส base64 ของไฟล์ incident.json
ขณะดาวน์โหลดคุณสามารถดูสคีมาตัวอย่างได้ที่นี่ใน repo นี้
bq show --format=prettyjson --schema gcp-status-log:status_dataset.status
สำหรับคนอื่นๆ คุณสามารถตั้งค่าทั้งหมดได้ด้วยตัวเองโดยใช้การผสมผสาน
Cloud Scheduler -> Cloud Run -> BigQUery
การตั้งค่าต่อไปนี้คืออะไร:
Cloud Scheduler
จะเรียกใช้บริการ Cloud Run
อย่างปลอดภัยCloud Run
ดาวน์โหลดไฟล์จากที่เก็บข้อมูล GCS ที่เก็บแฮชของไฟล์ JSON CSH ที่แทรกครั้งล่าสุดCloud Run
ดาวน์โหลดและแยกวิเคราะห์ข้อมูล JSON CSHCloud Run
แทรกเหตุการณ์ CSH ลงใน BigQuery
แน่นอนว่าโครงร่างนี้ขึ้นอยู่กับไฟล์ JSON CSH ที่เหลืออยู่ด้วยค่าแฮชเดียวกันหากไม่มีการอัปเดต (เช่น ไม่มีการประทับเวลาความสดใหม่สำหรับการอัพเดตของตัวเอง)
export PROJECT_ID= ` gcloud config get-value core/project `
export PROJECT_NUMBER= ` gcloud projects describe $PROJECT_ID --format= ' value(projectNumber) ' `
gcloud services enable containerregistry.googleapis.com
run.googleapis.com
bigquery.googleapis.com
cloudscheduler.googleapis.com
storage.googleapis.com
# # create the datasets. We are using DAY partitioning
bq mk -d --data_location=US status_dataset
bq mk --table status_dataset.status schema.json
# # create service accounts for cloud run and scheduler
gcloud iam service-accounts create schedulerunner --project= $PROJECT_ID
gcloud iam service-accounts create cloudrunsvc --project= $PROJECT_ID
bq add-iam-policy-binding
--member=serviceAccount:cloudrunsvc@ $PROJECT_ID .iam.gserviceaccount.com
--role=roles/bigquery.admin status_dataset.status
gcloud projects add-iam-policy-binding $PROJECT_ID
--member= " serviceAccount:cloudrunsvc@ $PROJECT_ID .iam.gserviceaccount.com "
--role= " roles/bigquery.jobUser "
# create a gcs bucket to store hash of the incidents json file
# the first value of the hash will force a reload of the incidents.json file
gsutil mb -l us-central1 gs:// $PROJECT_ID -status-hash
echo -n " foo " > /tmp/hash.txt
gsutil cp /tmp/hash.txt gs:// $PROJECT_ID -status-hash/
gsutil iam ch serviceAccount:cloudrunsvc@ $PROJECT_ID .iam.gserviceaccount.com:roles/storage.admin gs:// $PROJECT_ID -status-hash/
# # you may also need to allow your users access to the dataset https://cloud.google.com/bigquery/docs/dataset-access-controls
# # build and deploy the cloud run image
docker build -t gcr.io/ $PROJECT_ID /gstatus .
docker push gcr.io/ $PROJECT_ID /gstatus
gcloud run deploy gcp-status --image gcr.io/ $PROJECT_ID /gstatus
--service-account cloudrunsvc@ $PROJECT_ID .iam.gserviceaccount.com
--set-env-vars " BQ_PROJECTID= $PROJECT_ID " --no-allow-unauthenticated
export RUN_URL= ` gcloud run services describe gcp-status --region=us-central1 --format= " value(status.address.url) " `
# # allow cloud scheduler to call cloud run
gcloud run services add-iam-policy-binding gcp-status --region=us-central1
--member=serviceAccount:schedulerunner@ $PROJECT_ID .iam.gserviceaccount.com --role=roles/run.invoker
# # deploy cloud scheduler
gcloud scheduler jobs create http status-scheduler- $region --http-method=GET --schedule " */5 * * * * "
--attempt-deadline=420s --time-zone= " Pacific/Tahiti " --location=us-central1
--oidc-service-account-email=schedulerunner@ $PROJECT_ID .iam.gserviceaccount.com
--oidc-token-audience= $RUN_URL --uri= $RUN_URL
[รอ 5 นาที]
คุณยังสามารถรวมเหตุการณ์ bq เข้ากับข้อมูลรายการสินทรัพย์เพื่อช่วยจำกัดขอบเขตว่าเหตุการณ์ส่งผลกระทบต่อบริการของคุณหรือไม่
ตัวอย่างเช่น หากคุณทราบว่ามีเหตุการณ์ใน us-central1-a
ที่ส่งผลกระทบต่ออินสแตนซ์ GCE คุณสามารถส่งคำค้นหาเพื่อจำกัดรายการเนื้อหาที่เป็นไปได้:
$ gcloud organizations list
DISPLAY_NAME ID DIRECTORY_CUSTOMER_ID
esodemoapp2.com 673202286123 C023zwabc
$ gcloud asset search-all-resources --scope= ' organizations/673202286123 '
--query= " location:us-central1-a "
--asset-types= " compute.googleapis.com/Instance " --format= " value(name) "
//compute.googleapis.com/projects/in-perimeter-gcs/zones/us-central1-a/instances/in-perimeter
//compute.googleapis.com/projects/ingress-vpcsc/zones/us-central1-a/instances/ingress
//compute.googleapis.com/projects/fabled-ray-104117/zones/us-central1-a/instances/instance-1
//compute.googleapis.com/projects/fabled-ray-104117/zones/us-central1-a/instances/nginx-vm-1
//compute.googleapis.com/projects/clamav-241815/zones/us-central1-a/instances/instance-1
//compute.googleapis.com/projects/fabled-ray-104117/zones/us-central1-a/instances/windows-1
คุณยังสอบถามบทบาทและการอนุญาต IAM ทั่วโลกโดยใช้:
เหตุการณ์ต้นทางคือ JSON ดังนั้นคุณจึงสามารถโหลดแต่ละเหตุการณ์ลงใน BQ โดยใช้ BQ Native Support สำหรับ JSON DataType
นี่อาจเป็นสิ่งที่ต้องทำและขั้นตอนการทำงานตัวอย่างอาจเป็นดังนี้:
export PROJECT_ID= ` gcloud config get-value core/project `
export PROJECT_NUMBER= ` gcloud projects describe $PROJECT_ID --format= ' value(projectNumber) ' `
bq mk --table status_dataset.json_dataset events:JSON
curl -o incidents.json -s https://status.cloud.google.com/incidents.json
cat incidents.json | jq -c ' .[] | . ' | sed ' s/"/""/g ' | awk ' { print """$0"""} ' - > items.json
bq load --source_format=CSV status_dataset.json_dataset items.json
bq show status_dataset.json_dataset
$ bq show status_dataset.json_dataset
Last modified Schema Total Rows Total Bytes Expiration Time Partitioning Clustered Fields Labels
----------------- ----------------- ------------ ------------- ------------ ------------------- ------------------ --------
08 Apr 09:39:48 | - events: json 125 822184
จากนั้น หากต้องการสอบถาม คุณสามารถอ้างอิงแต่ละไฟล์ได้โดยตรง:
$ bq query --nouse_legacy_sql '
SELECT events["id"] as id, events["number"] as number, events["begin"] as begin
FROM `status_dataset.json_dataset`
LIMIT 10
'
+------------------------+------------------------+-----------------------------+
| id | number | begin |
+------------------------+------------------------+-----------------------------+
| " ukkfXQc8CEeFZbSTYQi7 " | " 14166479295409213890 " | " 2022-03-31T19:15:00+00:00 " |
| " RmPhfQT9RDGwWLCXS2sC " | " 3617221773064871579 " | " 2022-03-31T18:07:00+00:00 " |
| " B1hD4KAtcxiyAWkcANfV " | " 17742360388109155603 " | " 2022-03-31T15:30:00+00:00 " |
| " 4rRjbE16mteQwUeXPZwi " | " 8134027662519725646 " | " 2022-03-29T21:00:00+00:00 " |
| " 2j8xsJMSyDhmgfJriGeR " | " 5259740469836333814 " | " 2022-03-28T22:30:00+00:00 " |
| " MtMwhU6SXrpBeg5peXqY " | " 17330021626924647123 " | " 2022-03-25T07:00:00+00:00 " |
| " R9vAbtGnhzo6n48SnqTj " | " 2948654908633925955 " | " 2022-03-22T22:30:00+00:00 " |
| " aA3kbJm5nwvVTKnYbrWM " | " 551739384385711524 " | " 2022-03-18T22:20:00+00:00 " |
| " LuGcJVjNTeC5Sb9pSJ9o " | " 5384612291846020564 " | " 2022-03-08T18:07:00+00:00 " |
| " Hko5cWSXxGSsxfiSpg4n " | " 6491961050454270833 " | " 2022-02-22T05:45:00+00:00 " |
+------------------------+------------------------+-----------------------------+
การแก้ไข Cloud Run ที่เกี่ยวข้องกับการสร้างโหลดในรูปแบบ CSV (ตั้งแต่วันที่ 4/8/22
รองรับตัวโหลด CSV ดั้งเดิม)
var rlines [] string
for _ , event := range events {
event . InsertTimestamp = now
event . SnapshotHash = sha256Value
strEvent , err := json . Marshal ( event )
if err != nil {
fmt . Printf ( "Error Marshal Event %v" , err )
http . Error ( w , err . Error (), http . StatusInternalServerError )
return
}
// for JSON Datatype
// https://cloud.google.com/bigquery/docs/reference/standard-sql/json-data
line := strings . Replace ( string ( strEvent ), " " " , " " " " , - 1 )
line = fmt . Sprintf ( " " %s " " , line )
rlines = append ( rlines , line )
}
dataString := strings . Join ( rlines , " n " )
rolesSource := bigquery . NewReaderSource ( strings . NewReader ( dataString ))
rolesSource . SourceFormat = bigquery . CSV
อย่างไรก็ตาม ประเภทข้อมูล JSON เป็นเพียงสิ่งที่ต้องทำ และฉันไม่แน่ใจว่าจำเป็นหรือไม่ในขณะนี้
เหตุใดฉันจึงเลือกเวลาตาฮิติอีกครั้งเพื่อเป็นตัวกำหนดตารางเวลา
ทำไมไม่ลองดูด้วยตัวคุณเอง: