Skip to content

Commit

Permalink
Merge pull request #20790 from dianasaur323/update-diagnostics
Browse files Browse the repository at this point in the history
server: flag Cockroach Labs testing servers as internal in diagnostics reporting
  • Loading branch information
dianasaur323 authored Feb 10, 2018
2 parents fb37bf0 + 04ac51a commit 058a964
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/server/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/url"
"reflect"
"strconv"
"strings"
"time"

"github.com/mitchellh/reflectwalk"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/diagnosticspb"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -164,6 +166,8 @@ func addInfoToURL(ctx context.Context, url *url.URL, s *Server, runningTime time
q.Set("nodeid", s.NodeID().String())
q.Set("uptime", strconv.Itoa(int(runningTime.Seconds())))
q.Set("insecure", strconv.FormatBool(s.cfg.Insecure))
q.Set("internal",
strconv.FormatBool(strings.Contains(sql.ClusterOrganization.Get(&s.st.SV), "Cockroach Labs")))

licenseType, err := LicenseTypeFn(s.st)
if err == nil {
Expand Down
17 changes: 16 additions & 1 deletion pkg/server/updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func TestCheckVersion(t *testing.T) {
if expected, actual := "OSS", r.last.licenseType; expected != actual {
t.Errorf("expected license type %v, got %v", expected, actual)
}

if expected, actual := "false", r.last.internal; expected != actual {
t.Errorf("expected internal to be %v, got %v", expected, actual)
}
}

func TestReportUsage(t *testing.T) {
Expand Down Expand Up @@ -157,6 +161,11 @@ func TestReportUsage(t *testing.T) {
t.Fatal(err)
}
}
// Set cluster to an internal testing cluster
q := `SET CLUSTER SETTING cluster.organization = 'Cockroach Labs - Production Testing'`
if _, err := db.Exec(q); err != nil {
t.Fatal(err)
}
if _, err := db.Exec(`RESET application_name`); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -224,6 +233,9 @@ func TestReportUsage(t *testing.T) {
if minExpected, actual := len(params.StoreSpecs), len(r.last.Stores); minExpected > actual {
return errors.Errorf("expected at least %v stores got %v", minExpected, actual)
}
if expected, actual := "true", r.last.internal; expected != actual {
t.Errorf("expected internal to be %v, got %v", expected, actual)
}

for _, store := range r.last.Stores {
if minExpected, actual := keyCounts[store.StoreID], store.KeyCount; minExpected > actual {
Expand Down Expand Up @@ -271,7 +283,7 @@ func TestReportUsage(t *testing.T) {
}
}

if expected, actual := 9, len(r.last.SqlStats); expected != actual {
if expected, actual := 10, len(r.last.SqlStats); expected != actual {
t.Fatalf("expected %d queries in stats report, got %d", expected, actual)
}

Expand All @@ -297,6 +309,7 @@ func TestReportUsage(t *testing.T) {
elemName: {
`SELECT _ FROM _ WHERE (_ = _) AND (lower(_) = lower(_))`,
`UPDATE _ SET _ = _ + _`,
`SET CLUSTER SETTING _._ = _`,
},
} {
if app, ok := bucketByApp[sql.HashAppName(appName)]; !ok {
Expand Down Expand Up @@ -330,6 +343,7 @@ type mockRecorder struct {
uuid string
version string
licenseType string
internal string
diagnosticspb.DiagnosticReport
rawReportBody string
}
Expand All @@ -348,6 +362,7 @@ func makeMockRecorder(t *testing.T) *mockRecorder {
rec.last.uuid = r.URL.Query().Get("uuid")
rec.last.version = r.URL.Query().Get("version")
rec.last.licenseType = r.URL.Query().Get("licensetype")
rec.last.internal = r.URL.Query().Get("internal")
body, err := ioutil.ReadAll(r.Body)
if err != nil {
panic(err)
Expand Down

0 comments on commit 058a964

Please sign in to comment.