From 04ac51acf5c491a270765aef8a59ab4e90589cba Mon Sep 17 00:00:00 2001 From: dianasaur323 Date: Mon, 18 Dec 2017 00:51:25 -0500 Subject: [PATCH] server: do not send diagonistics if internal to crdb --- pkg/server/updates.go | 4 ++++ pkg/server/updates_test.go | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/server/updates.go b/pkg/server/updates.go index f212a2cf5281..ff5852dfc4f9 100644 --- a/pkg/server/updates.go +++ b/pkg/server/updates.go @@ -25,6 +25,7 @@ import ( "net/url" "reflect" "strconv" + "strings" "time" "github.com/mitchellh/reflectwalk" @@ -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" @@ -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 { diff --git a/pkg/server/updates_test.go b/pkg/server/updates_test.go index 74e5d4966cec..3f179c283dc8 100644 --- a/pkg/server/updates_test.go +++ b/pkg/server/updates_test.go @@ -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) { @@ -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) } @@ -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 { @@ -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) } @@ -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 { @@ -330,6 +343,7 @@ type mockRecorder struct { uuid string version string licenseType string + internal string diagnosticspb.DiagnosticReport rawReportBody string } @@ -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)