Skip to content

Commit

Permalink
fix: grafana internals for tools/flakeytests (#12269)
Browse files Browse the repository at this point in the history
Co-authored-by: chainchad <[email protected]>
  • Loading branch information
erikburt and chainchad authored Mar 7, 2024
1 parent 6d264de commit f38b936
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,18 @@ jobs:
run: go build ./tools/flakeytests/cmd/runner
- name: Re-run tests
env:
GRAFANA_CLOUD_BASIC_AUTH: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }}
GRAFANA_CLOUD_HOST: ${{ secrets.GRAFANA_CLOUD_HOST }}
GRAFANA_INTERNAL_BASIC_AUTH: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }}
GRAFANA_INTERNAL_HOST: ${{ secrets.GRAFANA_INTERNAL_HOST }}
GRAFANA_INTERNAL_TENANT_ID: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
./runner \
-grafana_auth=$GRAFANA_CLOUD_BASIC_AUTH \
-grafana_host=$GRAFANA_CLOUD_HOST \
-grafana_auth=$GRAFANA_INTERNAL_BASIC_AUTH \
-grafana_host=$GRAFANA_INTERNAL_HOST \
-grafana_org_id=$GRAFANA_INTERNAL_TENANT_ID \
-gh_sha=$GITHUB_SHA \
-gh_event_path=$GITHUB_EVENT_PATH \
-gh_event_name=$GITHUB_EVENT_NAME \
Expand Down
7 changes: 6 additions & 1 deletion tools/flakeytests/cmd/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {

grafanaHost := flag.String("grafana_host", "", "grafana host URL")
grafanaAuth := flag.String("grafana_auth", "", "grafana basic auth for Loki API")
grafanaOrgID := flag.String("grafana_org_id", "", "grafana org ID")
command := flag.String("command", "", "test command being rerun; used to tag metrics")
ghSHA := flag.String("gh_sha", "", "commit sha for which we're rerunning tests")
ghEventPath := flag.String("gh_event_path", "", "path to associated gh event")
Expand All @@ -40,6 +41,10 @@ func main() {
log.Fatal("Error re-running flakey tests: `grafana_auth` is required")
}

if *grafanaOrgID == "" {
log.Fatal("Error re-running flakey tests: `grafana_org_id` is required")
}

if *command == "" {
log.Fatal("Error re-running flakey tests: `command` is required")
}
Expand All @@ -58,7 +63,7 @@ func main() {
}

meta := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath, *ghRunID)
rep := flakeytests.NewLokiReporter(*grafanaHost, *grafanaAuth, *command, meta)
rep := flakeytests.NewLokiReporter(*grafanaHost, *grafanaAuth, *grafanaOrgID, *command, meta)
r := flakeytests.NewRunner(readers, rep, numReruns)
err := r.Run(ctx)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions tools/flakeytests/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Context struct {
type LokiReporter struct {
host string
auth string
orgId string
command string
now func() time.Time
ctx Context
Expand Down Expand Up @@ -155,6 +156,7 @@ func (l *LokiReporter) makeRequest(ctx context.Context, pushReq pushRequest) err
fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(l.auth))),
)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Scope-OrgID", l.orgId)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
Expand All @@ -177,6 +179,6 @@ func (l *LokiReporter) Report(ctx context.Context, report *Report) error {
return l.makeRequest(ctx, pushReq)
}

func NewLokiReporter(host, auth, command string, ctx Context) *LokiReporter {
return &LokiReporter{host: host, auth: auth, command: command, now: time.Now, ctx: ctx}
func NewLokiReporter(host, auth, orgId, command string, ctx Context) *LokiReporter {
return &LokiReporter{host: host, auth: auth, orgId: orgId, command: command, now: time.Now, ctx: ctx}
}
10 changes: 5 additions & 5 deletions tools/flakeytests/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestMakeRequest_SingleTest(t *testing.T) {
},
},
}
lr := &LokiReporter{auth: "bla", host: "bla", command: "go_core_tests", now: func() time.Time { return now }}
lr := &LokiReporter{auth: "bla", host: "bla", orgId: "bla", command: "go_core_tests", now: func() time.Time { return now }}
pr, err := lr.createRequest(r)
require.NoError(t, err)
assert.Len(t, pr.Streams, 1)
Expand All @@ -41,7 +41,7 @@ func TestMakeRequest_MultipleTests(t *testing.T) {
},
},
}
lr := &LokiReporter{auth: "bla", host: "bla", command: "go_core_tests", now: func() time.Time { return now }}
lr := &LokiReporter{auth: "bla", host: "bla", orgId: "bla", command: "go_core_tests", now: func() time.Time { return now }}
pr, err := lr.createRequest(r)
require.NoError(t, err)
assert.Len(t, pr.Streams, 1)
Expand All @@ -58,7 +58,7 @@ func TestMakeRequest_NoTests(t *testing.T) {
now := time.Now()
ts := fmt.Sprintf("%d", now.UnixNano())
r := NewReport()
lr := &LokiReporter{auth: "bla", host: "bla", command: "go_core_tests", now: func() time.Time { return now }}
lr := &LokiReporter{auth: "bla", host: "bla", orgId: "bla", command: "go_core_tests", now: func() time.Time { return now }}
pr, err := lr.createRequest(r)
require.NoError(t, err)
assert.Len(t, pr.Streams, 1)
Expand All @@ -72,7 +72,7 @@ func TestMakeRequest_WithContext(t *testing.T) {
now := time.Now()
ts := fmt.Sprintf("%d", now.UnixNano())
r := NewReport()
lr := &LokiReporter{auth: "bla", host: "bla", command: "go_core_tests", now: func() time.Time { return now }, ctx: Context{CommitSHA: "42"}}
lr := &LokiReporter{auth: "bla", host: "bla", orgId: "bla", command: "go_core_tests", now: func() time.Time { return now }, ctx: Context{CommitSHA: "42"}}
pr, err := lr.createRequest(r)
require.NoError(t, err)
assert.Len(t, pr.Streams, 1)
Expand All @@ -95,7 +95,7 @@ func TestMakeRequest_Panics(t *testing.T) {
"core/assets": 1,
},
}
lr := &LokiReporter{auth: "bla", host: "bla", command: "go_core_tests", now: func() time.Time { return now }}
lr := &LokiReporter{auth: "bla", host: "bla", orgId: "bla", command: "go_core_tests", now: func() time.Time { return now }}
pr, err := lr.createRequest(r)
require.NoError(t, err)
assert.Len(t, pr.Streams, 1)
Expand Down

0 comments on commit f38b936

Please sign in to comment.