Skip to content

Commit

Permalink
server/status: add NodeStatus.{Args,Env}
Browse files Browse the repository at this point in the history
Add the COCKROACH_* and GO* env vars and the command line flags to
NodeStatus so that they will be collected by the debug zip command.

Fixes #14065
  • Loading branch information
petermattis committed Mar 10, 2017
1 parent 323df96 commit f6e2313
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 30 deletions.
4 changes: 4 additions & 0 deletions pkg/server/status/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"strconv"

"golang.org/x/net/context"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb"
"github.com/cockroachdb/cockroach/pkg/ts/tspb"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/metric"
Expand Down Expand Up @@ -261,6 +263,8 @@ func (mr *MetricsRecorder) GetStatusSummary() *NodeStatus {
StartedAt: mr.mu.startedAt,
StoreStatuses: make([]StoreStatus, 0, mr.mu.lastSummaryCount),
Metrics: make(map[string]float64, mr.mu.lastNodeMetricCount),
Args: os.Args,
Env: envutil.GetEnvVarsUsed(),
}

eachRecordableValue(mr.mu.nodeRegistry, func(name string, val float64) {
Expand Down
17 changes: 16 additions & 1 deletion pkg/server/status/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package status

import (
"os"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -331,13 +332,27 @@ func TestMetricsRecorder(t *testing.T) {
},
}

// Make sure there is at least one environment variable that will be
// reported.
if err := os.Setenv("GOGC", "100"); err != nil {
t.Fatal(err)
}

nodeSummary := recorder.GetStatusSummary()
if nodeSummary == nil {
t.Fatalf("recorder did not return nodeSummary")
}
if len(nodeSummary.Args) == 0 {
t.Fatalf("expected args to be present")
}
if len(nodeSummary.Env) == 0 {
t.Fatalf("expected env to be present")
}
nodeSummary.Args = nil
nodeSummary.Env = nil

sort.Sort(byStoreDescID(nodeSummary.StoreStatuses))
if a, e := nodeSummary, expectedNodeSummary; !reflect.DeepEqual(a, e) {
t.Errorf("recorder did not produce expected NodeSummary; diff:\n %v", pretty.Diff(e, a))
t.Errorf("recorder did not produce expected NodeSummary; diff:\n %s", pretty.Diff(e, a))
}
}
158 changes: 131 additions & 27 deletions pkg/server/status/status.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/server/status/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ message NodeStatus {
optional int64 updated_at = 4 [(gogoproto.nullable) = false];
map<string, double> metrics = 5;
repeated StoreStatus store_statuses = 6 [(gogoproto.nullable) = false];
repeated string args = 7 [(gogoproto.nullable) = false];
repeated string env = 8 [(gogoproto.nullable) = false];
}

18 changes: 18 additions & 0 deletions pkg/ui/app/js/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -3519,6 +3519,24 @@ module.exports = require("protobufjs").newBuilder({})['import']({
"options": {
"(gogoproto.nullable)": false
}
},
{
"rule": "repeated",
"type": "string",
"name": "args",
"id": 7,
"options": {
"(gogoproto.nullable)": false
}
},
{
"rule": "repeated",
"type": "string",
"name": "env",
"id": 8,
"options": {
"(gogoproto.nullable)": false
}
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/embedded.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pkg/ui/generated/protos.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6239,6 +6239,24 @@ getStoreStatuses?() : StoreStatus[];



args?: string[];


getArgs?() : string[];
setArgs?(args : string[]): void;




env?: string[];


getEnv?() : string[];
setEnv?(env : string[]): void;




}

export interface NodeStatusMessage extends NodeStatus {
Expand Down
18 changes: 18 additions & 0 deletions pkg/ui/generated/protos.json
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,24 @@
"options": {
"(gogoproto.nullable)": false
}
},
{
"rule": "repeated",
"type": "string",
"name": "args",
"id": 7,
"options": {
"(gogoproto.nullable)": false
}
},
{
"rule": "repeated",
"type": "string",
"name": "env",
"id": 8,
"options": {
"(gogoproto.nullable)": false
}
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/util/envutil/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ func GetEnvVarsUsed() []string {
var vars []string
for k, v := range envVarRegistry.cache {
if v.present {
vars = append(vars, k)
vars = append(vars, k+"="+os.Getenv(k))
}
}

for _, name := range []string{"GOGC", "GODEBUG", "GOMAXPROCS", "GOTRACEBACK"} {
if val, ok := os.LookupEnv(name); ok {
vars = append(vars, name+"="+val)
}
}
return vars
Expand Down

0 comments on commit f6e2313

Please sign in to comment.