Skip to content

Commit b7eb62b

Browse files
permissions-center: use new permissionSyncJobs query. (#942)
Test plan: `src snapshot test` runs successfully and fetches perms sync information from a local sg instance.
1 parent a84baf7 commit b7eb62b

File tree

5 files changed

+51
-49
lines changed

5 files changed

+51
-49
lines changed

cmd/src/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type command struct {
2323
// handler is the function that is invoked to handle this command.
2424
handler func(args []string) error
2525

26-
// flagSet.Usage function to invoke on e.g. -h flag. If nil, a default one
27-
// one is used.
26+
// flagSet.Usage function to invoke on e.g. -h flag. If nil, a default one is
27+
// used.
2828
usageFunc func()
2929
}
3030

@@ -48,7 +48,7 @@ type commander []*command
4848
func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []string) {
4949
// Parse flags.
5050
flagSet.Usage = func() {
51-
fmt.Fprint(flag.CommandLine.Output(), usageText)
51+
_, _ = fmt.Fprint(flag.CommandLine.Output(), usageText)
5252
}
5353
if !flagSet.Parsed() {
5454
_ = flagSet.Parse(args)
@@ -68,7 +68,7 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []
6868
continue
6969
}
7070
cmd.flagSet.Usage = func() {
71-
fmt.Fprintf(flag.CommandLine.Output(), "Usage of '%s %s':\n", cmdName, cmd.flagSet.Name())
71+
_, _ = fmt.Fprintf(flag.CommandLine.Output(), "Usage of '%s %s':\n", cmdName, cmd.flagSet.Name())
7272
cmd.flagSet.PrintDefaults()
7373
}
7474
}

cmd/src/snapshot_testcmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/google/go-cmp/cmp"
12+
1213
"github.com/sourcegraph/sourcegraph/lib/errors"
1314
"github.com/sourcegraph/sourcegraph/lib/output"
1415

@@ -93,7 +94,7 @@ TEST DATA
9394
"No critical issues found!"))
9495
return nil
9596
},
96-
usageFunc: func() { fmt.Fprint(flag.CommandLine.Output(), usage) },
97+
usageFunc: func() { _, _ = fmt.Fprint(flag.CommandLine.Output(), usage) },
9798
})
9899
}
99100

@@ -105,7 +106,7 @@ func compareSnapshotSummaries(out *output.Output, recordedSummary, newSummary sn
105106
diff := cmp.Diff(recordedSummary, newSummary)
106107
if diff != "" {
107108
b.WriteLine(output.Line(output.EmojiFailure, output.StyleFailure, "Snapshot diff detected:"))
108-
b.WriteCode("diff", diff)
109+
_ = b.WriteCode("diff", diff)
109110
return errors.New("snapshot mismatch")
110111
}
111112
b.WriteLine(output.Emoji(output.EmojiSuccess, "Snapshots match!"))

internal/instancehealth/checks.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ func checkPermissionsSyncing(
134134
var syncCount int
135135
var syncErrors []string
136136
var seenProviders = make(map[string]map[string]string) // provider : state : message
137-
for _, sync := range instanceHealth.PermissionsSyncJobs.Nodes {
138-
if sync.CompletedAt.Before(time.Now().Add(-since)) {
137+
for _, sync := range instanceHealth.PermissionSyncJobs.Nodes {
138+
if sync.FinishedAt.Before(time.Now().Add(-since)) {
139139
continue
140140
}
141141
syncCount += 1
142-
if sync.Status == "ERROR" {
143-
syncErrors = append(syncErrors, sync.Message)
142+
if sync.State == "ERROR" || sync.State == "FAILED" {
143+
syncErrors = append(syncErrors, sync.FailureMessage)
144144
}
145-
for _, p := range sync.Providers {
146-
key := fmt.Sprintf("%s - %s", p.Type, p.ID)
145+
for _, p := range sync.CodeHostStates {
146+
key := fmt.Sprintf("%s - %s", p.ProviderType, p.ProviderID)
147147
if _, ok := seenProviders[key]; !ok {
148148
seenProviders[key] = make(map[string]string)
149149
}

internal/instancehealth/checks_test.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/sourcegraph/sourcegraph/lib/output"
1110
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
12+
13+
"github.com/sourcegraph/sourcegraph/lib/output"
1314
)
1415

1516
// run with -v for output
@@ -23,7 +24,7 @@ func TestCheckPermissionsSyncing(t *testing.T) {
2324
}{{
2425
name: "no jobs",
2526
instanceHealth: Indicators{
26-
PermissionsSyncJobs: struct{ Nodes []permissionsSyncJob }{
27+
PermissionSyncJobs: struct{ Nodes []permissionSyncJob }{
2728
Nodes: nil,
2829
},
2930
},
@@ -32,14 +33,14 @@ func TestCheckPermissionsSyncing(t *testing.T) {
3233
}, {
3334
name: "healthy",
3435
instanceHealth: Indicators{
35-
PermissionsSyncJobs: struct{ Nodes []permissionsSyncJob }{
36-
Nodes: []permissionsSyncJob{{
37-
CompletedAt: time.Now(),
38-
Status: "SUCCESS",
39-
Providers: []permissionsProviderStatus{{
40-
Type: "github",
41-
ID: "https://github.com/",
42-
Status: "SUCCESS",
36+
PermissionSyncJobs: struct{ Nodes []permissionSyncJob }{
37+
Nodes: []permissionSyncJob{{
38+
FinishedAt: time.Now(),
39+
State: "SUCCESS",
40+
CodeHostStates: []permissionsProviderStatus{{
41+
ProviderType: "github",
42+
ProviderID: "https://github.com/",
43+
Status: "SUCCESS",
4344
}},
4445
}},
4546
},
@@ -49,15 +50,15 @@ func TestCheckPermissionsSyncing(t *testing.T) {
4950
}, {
5051
name: "unhealthy",
5152
instanceHealth: Indicators{
52-
PermissionsSyncJobs: struct{ Nodes []permissionsSyncJob }{
53-
Nodes: []permissionsSyncJob{{
54-
CompletedAt: time.Now(),
55-
Status: "ERROR",
56-
Message: "oh no!",
57-
Providers: []permissionsProviderStatus{{
58-
Type: "github",
59-
ID: "https://github.com/",
60-
Status: "ERROR",
53+
PermissionSyncJobs: struct{ Nodes []permissionSyncJob }{
54+
Nodes: []permissionSyncJob{{
55+
FinishedAt: time.Now(),
56+
State: "ERROR",
57+
FailureMessage: "oh no!",
58+
CodeHostStates: []permissionsProviderStatus{{
59+
ProviderType: "github",
60+
ProviderID: "https://github.com/",
61+
Status: "ERROR",
6162
}},
6263
}},
6364
},

internal/instancehealth/summary.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ type Indicators struct {
4040
}
4141
}
4242
}
43-
PermissionsSyncJobs struct {
44-
Nodes []permissionsSyncJob
43+
PermissionSyncJobs struct {
44+
Nodes []permissionSyncJob
4545
}
4646
}
4747

48-
type permissionsSyncJob struct {
49-
Status string
50-
Message string
51-
CompletedAt time.Time
52-
Providers []permissionsProviderStatus
48+
type permissionSyncJob struct {
49+
State string
50+
FailureMessage string
51+
FinishedAt time.Time
52+
CodeHostStates []permissionsProviderStatus
5353
}
5454

5555
type permissionsProviderStatus struct {
56-
Type string
57-
ID string
58-
Status string
59-
Message string
56+
ProviderType string
57+
ProviderID string
58+
Status string
59+
Message string
6060
}
6161

6262
// GetIndicators retrieves summary data from a Sourcegraph instance's GraphQL API for
@@ -95,14 +95,14 @@ func GetIndicators(ctx context.Context, client api.Client) (*Indicators, error)
9595
}
9696
}
9797
98-
permissionsSyncJobs(first:500) {
98+
permissionSyncJobs(first:500) {
9999
nodes {
100-
status
101-
completedAt
102-
message
103-
providers {
104-
type
105-
id
100+
state
101+
finishedAt
102+
failureMessage
103+
codeHostStates {
104+
providerType
105+
providerID
106106
status
107107
message
108108
}

0 commit comments

Comments
 (0)