From c3ff96743ab0c285e62f41e4a98af14bf3bbb76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20St=C3=B6lzle?= Date: Thu, 8 Oct 2020 11:01:33 +0200 Subject: [PATCH] Add a view for failed webhooks (#212) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📦 Add failed webhooks view --- docs/_data/navigation.yml | 2 + docs/demo-data/failed-webhooks-detailed.tsv | 5 ++ docs/demo-data/failed-webhooks.tsv | 7 +++ docs/housekeeping-failed-webhooks.html | 62 +++++++++++++++++++++ updater/reports/ReportFailedWebhooks.py | 19 +++++++ updater/scripts/failed-webhooks.sh | 19 +++++++ updater/update-stats.py | 2 + 7 files changed, 116 insertions(+) create mode 100644 docs/demo-data/failed-webhooks-detailed.tsv create mode 100644 docs/demo-data/failed-webhooks.tsv create mode 100644 docs/housekeeping-failed-webhooks.html create mode 100644 updater/reports/ReportFailedWebhooks.py create mode 100755 updater/scripts/failed-webhooks.sh diff --git a/docs/_data/navigation.yml b/docs/_data/navigation.yml index dc524359..0bdfae9a 100644 --- a/docs/_data/navigation.yml +++ b/docs/_data/navigation.yml @@ -55,6 +55,8 @@ url: "/housekeeping-repo-location" - title: "Forks" url: "/housekeeping-forks" + - title: "Failed Webhooks" + url: "/housekeeping-failed-webhooks" - title: "Recommendations" url: "/recommendations-tokenless-auth" subnavigation: diff --git a/docs/demo-data/failed-webhooks-detailed.tsv b/docs/demo-data/failed-webhooks-detailed.tsv new file mode 100644 index 00000000..229cb0e8 --- /dev/null +++ b/docs/demo-data/failed-webhooks-detailed.tsv @@ -0,0 +1,5 @@ +hook_id type host message count +1 business 10.0.0.1 request timed out 3 +2 integration 10.0.0.2 Couldn't connect to server 2 +3 repository 10.0.0.3 Couldn't connect to server 1 +4 organization 10.0.0.4 Couldn't resolve host name 1 diff --git a/docs/demo-data/failed-webhooks.tsv b/docs/demo-data/failed-webhooks.tsv new file mode 100644 index 00000000..01b1be5e --- /dev/null +++ b/docs/demo-data/failed-webhooks.tsv @@ -0,0 +1,7 @@ +date failed webhooks +2020-10-01 0 +2020-10-02 1 +2020-10-03 5 +2020-10-04 7 +2020-10-05 5 +2020-10-06 4 diff --git a/docs/housekeeping-failed-webhooks.html b/docs/housekeeping-failed-webhooks.html new file mode 100644 index 00000000..28bad6a1 --- /dev/null +++ b/docs/housekeeping-failed-webhooks.html @@ -0,0 +1,62 @@ +--- +layout: default +title: Failed Webhooks +permalink: /housekeeping-failed-webhooks +--- + +
+

Failed Webhooks

+ +
+
+ +
+
+ +
+

+

+

+
+
+ + + diff --git a/updater/reports/ReportFailedWebhooks.py b/updater/reports/ReportFailedWebhooks.py new file mode 100644 index 00000000..2a36fe7f --- /dev/null +++ b/updater/reports/ReportFailedWebhooks.py @@ -0,0 +1,19 @@ +from .ReportDaily import * + +# Report how many webhooks failed +class ReportFailedWebhooks(ReportDaily): + def name(self): + return "failed-webhooks" + + def updateDailyData(self): + self.detailedHeader, newData = self.parseData( + self.executeScript(self.scriptPath("failed-webhooks.sh"))) + self.header = ["date", "failed webhooks"] + self.data.append( + [ + str(self.yesterday()), + sum(map(lambda x: int(x[4] if len(x) > 3 else 0), newData)), + ]) + self.detailedData = newData[:25] + self.truncateData(self.timeRangeTotal()) + self.sortDataByDate() diff --git a/updater/scripts/failed-webhooks.sh b/updater/scripts/failed-webhooks.sh new file mode 100755 index 00000000..c63eb077 --- /dev/null +++ b/updater/scripts/failed-webhooks.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# +# List failed webhooks +# + +echo -e "hook_id\ttype\thost\tmessage\tcount" + +zcat -f /var/log/hookshot/exceptions.log.1* | + jq --slurp '.[] | del(.backtrace) | {hook_id,service_host,message,class,parent}' | + jq --slurp -c 'sort_by(.hook_id) | .[] | {id: .hook_id,url: .service_host, data: (.parent|tostring), msg: .message}' | + # remove this part as it's not real JSON and breaks the remaining chain + sed -e 's/{\\"url[^}]*}, //' | + # this can probably be done more elegantly + jq -r -c --slurp '.[] | "\(.id)\t\((.data|tostring|fromjson)[0] | sub("-[0-9]+"; ""))\t\(.url)\t\(.msg)"' | + sort | + uniq -ic | + sort -rn | + perl -pne 's/([0-9]+)\s(.*)/\2\t\1/' diff --git a/updater/update-stats.py b/updater/update-stats.py index f1f6166e..3998e7aa 100755 --- a/updater/update-stats.py +++ b/updater/update-stats.py @@ -12,6 +12,7 @@ from reports.ReportAPIRequestsByUser import * from reports.ReportContributorsByOrg import * from reports.ReportContributorsByRepo import * +from reports.ReportFailedWebhooks import * from reports.ReportForksToOrgs import * from reports.ReportGitDownload import * from reports.ReportGitProtocol import * @@ -80,6 +81,7 @@ def main(): ReportAPIRequestsByUser(configuration, dataDirectory, metaStats).update() ReportContributorsByOrg(configuration, dataDirectory, metaStats).update() ReportContributorsByRepo(configuration, dataDirectory, metaStats).update() + ReportFailedWebhooks(configuration, dataDirectory, metaStats).update() ReportForksToOrgs(configuration, dataDirectory, metaStats).update() ReportGitDownload(configuration, dataDirectory, metaStats).update() ReportGitProtocol(configuration, dataDirectory, metaStats).update()