dev/buildchecker: unify reporting runs, remove top-level slack token requirement (#38020)

History reporting is an expensive operation - we pull what could be many pages of builds from Buildkite in order to generate a report. This PR removes the duplicated reporting so that only one run is required, and also removes the slack token that is actually only required for checks.
This commit is contained in:
Robert Lin 2022-06-30 14:04:38 -07:00 committed by GitHub
parent d4546b5d0d
commit aed4b51508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 40 deletions

View File

@ -24,19 +24,4 @@ jobs:
BUILDKITE_TOKEN: ${{ secrets.AUTOBUILDSHERRIF_BUILDKITE_TOKEN }}
HONEYCOMB_TOKEN: ${{ secrets.AUTOBUILDSHERRIF_HONEYCOMB_TOKEN }}
CI_OKAYHQ_TOKEN: ${{ secrets.CI_OKAYHQ_TOKEN }}
report-to-slack:
runs-on: ubuntu-latest
environment: autobuildsherrif
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with: { go-version: '1.18' }
- run: ./dev/buildchecker/run-slack-history.sh
env:
BUILDKITE_TOKEN: ${{ secrets.AUTOBUILDSHERRIF_BUILDKITE_TOKEN }}
SLACK_TOKEN: ${{ secrets.AUTOBUILDSHERRIF_SLACK_TOKEN }}
SLACK_REPORT_WEBHOOK: ${{ secrets.AUTOBUILDSHERRIF_SLACK_REPORT_WEBHOOK}},${{secrets.AUTOBUILDSHERRIF_SLACK_DX_WEBHOOK}}

View File

@ -25,7 +25,6 @@ type Flags struct {
BuildkiteToken string
Pipeline string
Branch string
SlackToken string
FailuresThreshold int
FailuresTimeoutMins int
}
@ -34,7 +33,6 @@ func (f *Flags) Parse() {
flag.StringVar(&f.BuildkiteToken, "buildkite.token", "", "mandatory buildkite token")
flag.StringVar(&f.Pipeline, "pipeline", "sourcegraph", "name of the pipeline to inspect")
flag.StringVar(&f.Branch, "branch", "main", "name of the branch to inspect")
flag.StringVar(&f.SlackToken, "slack.token", "", "mandatory slack api token")
flag.IntVar(&f.FailuresThreshold, "failures.threshold", 3, "failures required to trigger an incident")
flag.IntVar(&f.FailuresTimeoutMins, "failures.timeout", 60, "duration of a run required to be considered a failure (minutes)")
@ -50,6 +48,7 @@ func main() {
checkFlags := &cmdCheckFlags{}
flag.StringVar(&checkFlags.githubToken, "github.token", "", "mandatory github token")
flag.StringVar(&checkFlags.slackAnnounceWebhooks, "slack.announce-webhook", "", "Slack Webhook URL to post the results on (comma-delimited for multiple values)")
flag.StringVar(&checkFlags.slackToken, "slack.token", "", "Slack token used for resolving Slack handles to mention")
flag.StringVar(&checkFlags.slackDebugWebhook, "slack.debug-webhook", "", "Slack Webhook URL to post debug results on")
flag.StringVar(&checkFlags.slackDiscussionChannel, "slack.discussion-channel", "#buildkite-main", "Slack channel to ask everyone to head over to for discusison")
@ -84,6 +83,7 @@ func main() {
type cmdCheckFlags struct {
githubToken string
slackToken string
slackAnnounceWebhooks string
slackDebugWebhook string
slackDiscussionChannel string
@ -102,9 +102,6 @@ func cmdCheck(ctx context.Context, flags *Flags, checkFlags *cmdCheckFlags) {
&oauth2.Token{AccessToken: checkFlags.githubToken},
)))
// Slack client
slc := slack.New(flags.SlackToken)
// Newest is returned first https://buildkite.com/docs/apis/rest-api/builds#list-builds-for-a-pipeline
builds, _, err := bkc.Builds.ListByPipeline("sourcegraph", flags.Pipeline, &buildkite.BuildsListOptions{
Branch: flags.Branch,
@ -124,7 +121,7 @@ func cmdCheck(ctx context.Context, flags *Flags, checkFlags *cmdCheckFlags) {
results, err := CheckBuilds(
ctx,
NewBranchLocker(ghc, "sourcegraph", "sourcegraph", flags.Branch),
team.NewTeammateResolver(ghc, slc),
team.NewTeammateResolver(ghc, slack.New(checkFlags.slackToken)),
builds,
opts,
)

View File

@ -1,18 +0,0 @@
#! /usr/bin/env bash
# Make this script independent of where it's called
cd "$(dirname "${BASH_SOURCE[0]}")"/../..
set -eu
created_from=$(date -d "7 days ago" '+%Y-%m-%d')
created_to=$(date -d "2 days ago" '+%Y-%m-%d')
echo "--- Running 'buildchecker history' from $created_from to $created_to"
go run ./dev/buildchecker/ \
-buildkite.token="$BUILDKITE_TOKEN" \
-created.from="$created_from" \
-created.to="$created_to" \
-slack.token="$SLACK_TOKEN" \
-slack.report-webhook="$SLACK_REPORT_WEBHOOK" \
history

View File

@ -15,5 +15,5 @@ go run ./dev/buildchecker/ \
-created.to="$created_to" \
-honeycomb.dataset="buildkite-history" \
-honeycomb.token="$HONEYCOMB_TOKEN" \
-okayhq.token="$CI_OKAYHQ_TOKEN" \
-slack.report-webhook="$SLACK_REPORT_WEBHOOK" \
history