Skip to content

Commit c6d4f68

Browse files
committed
feat: Adds 'config' to 'debug/vars' http endpoint (#26624)
(cherry picked from commit c28b917)
1 parent e51acc4 commit c6d4f68

File tree

9 files changed

+85
-13
lines changed

9 files changed

+85
-13
lines changed

cmd/influxd/run/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
199199

200200
config: c,
201201
}
202-
s.Monitor = monitor.New(s, c.Monitor)
202+
s.Monitor = monitor.New(s, c.Monitor, &c.Data)
203203
s.config.registerDiagnostics(s.Monitor)
204204

205205
if err := s.MetaClient.Open(); err != nil {

monitor/build_info_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"testing"
66

77
"github.com/influxdata/influxdb/monitor"
8+
"github.com/influxdata/influxdb/tsdb"
89
)
910

1011
func TestDiagnostics_BuildInfo(t *testing.T) {
11-
s := monitor.New(nil, monitor.Config{})
12+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
1213
s.Version = "1.2.0"
1314
s.Commit = "b7bb7e8359642b6e071735b50ae41f5eb343fd42"
1415
s.Branch = "1.2"

monitor/go_runtime_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"testing"
77

88
"github.com/influxdata/influxdb/monitor"
9+
"github.com/influxdata/influxdb/tsdb"
910
)
1011

1112
func TestDiagnostics_GoRuntime(t *testing.T) {
12-
s := monitor.New(nil, monitor.Config{})
13+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
1314
if err := s.Open(); err != nil {
1415
t.Fatalf("unexpected error: %s", err)
1516
}

monitor/network_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/influxdata/influxdb/monitor"
9+
"github.com/influxdata/influxdb/tsdb"
910
)
1011

1112
func TestDiagnostics_Network(t *testing.T) {
@@ -14,7 +15,7 @@ func TestDiagnostics_Network(t *testing.T) {
1415
t.Fatalf("unexpected error retrieving hostname: %s", err)
1516
}
1617

17-
s := monitor.New(nil, monitor.Config{})
18+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
1819
if err := s.Open(); err != nil {
1920
t.Fatalf("unexpected error: %s", err)
2021
}

monitor/service.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/influxdata/influxdb/models"
1818
"github.com/influxdata/influxdb/monitor/diagnostics"
1919
"github.com/influxdata/influxdb/services/meta"
20+
"github.com/influxdata/influxdb/tsdb"
2021
"go.uber.org/zap"
2122
)
2223

@@ -96,6 +97,9 @@ type Monitor struct {
9697
// Writer for pushing stats back into the database.
9798
PointsWriter PointsWriter
9899

100+
// TSDB configuration for diagnostics
101+
TSDBConfig *tsdb.Config
102+
99103
Logger *zap.Logger
100104
}
101105

@@ -105,7 +109,7 @@ type PointsWriter interface {
105109
}
106110

107111
// New returns a new instance of the monitor system.
108-
func New(r Reporter, c Config) *Monitor {
112+
func New(r Reporter, c Config, tsdbConfig *tsdb.Config) *Monitor {
109113
return &Monitor{
110114
globalTags: newTags(),
111115
diagRegistrations: make(map[string]diagnostics.Client),
@@ -114,6 +118,7 @@ func New(r Reporter, c Config) *Monitor {
114118
storeDatabase: c.StoreDatabase,
115119
storeInterval: time.Duration(c.StoreInterval),
116120
storeRetentionPolicy: MonitorRetentionPolicy,
121+
TSDBConfig: tsdbConfig,
117122
Logger: zap.NewNop(),
118123
}
119124
}
@@ -145,6 +150,9 @@ func (m *Monitor) Open() error {
145150
m.RegisterDiagnosticsClient("runtime", &goRuntime{})
146151
m.RegisterDiagnosticsClient("network", &network{})
147152
m.RegisterDiagnosticsClient("system", &system{})
153+
if m.TSDBConfig != nil {
154+
m.RegisterDiagnosticsClient("config", m.TSDBConfig)
155+
}
148156

149157
m.mu.Lock()
150158
m.done = make(chan struct{})

monitor/service_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import (
1515
"github.com/influxdata/influxdb/monitor"
1616
"github.com/influxdata/influxdb/services/meta"
1717
"github.com/influxdata/influxdb/toml"
18+
"github.com/influxdata/influxdb/tsdb"
1819
"go.uber.org/zap"
1920
"go.uber.org/zap/zaptest/observer"
2021
)
2122

2223
func TestMonitor_Open(t *testing.T) {
23-
s := monitor.New(nil, monitor.Config{})
24+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
2425
if err := s.Open(); err != nil {
2526
t.Fatalf("unexpected open error: %s", err)
2627
}
@@ -48,7 +49,7 @@ func TestMonitor_SetPointsWriter_StoreEnabled(t *testing.T) {
4849
}
4950

5051
config := monitor.NewConfig()
51-
s := monitor.New(nil, config)
52+
s := monitor.New(nil, config, &tsdb.Config{})
5253
s.MetaClient = &mc
5354
core, logs := observer.New(zap.DebugLevel)
5455
s.WithLogger(zap.New(core))
@@ -67,7 +68,7 @@ func TestMonitor_SetPointsWriter_StoreEnabled(t *testing.T) {
6768
}
6869

6970
func TestMonitor_SetPointsWriter_StoreDisabled(t *testing.T) {
70-
s := monitor.New(nil, monitor.Config{})
71+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
7172
core, logs := observer.New(zap.DebugLevel)
7273
s.WithLogger(zap.New(core))
7374

@@ -134,7 +135,7 @@ func TestMonitor_StoreStatistics(t *testing.T) {
134135

135136
config := monitor.NewConfig()
136137
config.StoreInterval = toml.Duration(10 * time.Millisecond)
137-
s := monitor.New(nil, config)
138+
s := monitor.New(nil, config, &tsdb.Config{})
138139
s.MetaClient = &mc
139140
s.PointsWriter = &pw
140141

@@ -210,7 +211,7 @@ func TestMonitor_Reporter(t *testing.T) {
210211

211212
config := monitor.NewConfig()
212213
config.StoreInterval = toml.Duration(10 * time.Millisecond)
213-
s := monitor.New(reporter, config)
214+
s := monitor.New(reporter, config, &tsdb.Config{})
214215
s.MetaClient = &mc
215216
s.PointsWriter = &pw
216217

@@ -306,7 +307,7 @@ func TestMonitor_Expvar(t *testing.T) {
306307

307308
config := monitor.NewConfig()
308309
config.StoreInterval = toml.Duration(10 * time.Millisecond)
309-
s := monitor.New(nil, config)
310+
s := monitor.New(nil, config, &tsdb.Config{})
310311
s.MetaClient = &mc
311312
s.PointsWriter = &pw
312313

@@ -400,7 +401,7 @@ func TestMonitor_QuickClose(t *testing.T) {
400401
var pw PointsWriter
401402
config := monitor.NewConfig()
402403
config.StoreInterval = toml.Duration(24 * time.Hour)
403-
s := monitor.New(nil, config)
404+
s := monitor.New(nil, config, &tsdb.Config{})
404405
s.MetaClient = &mc
405406
s.PointsWriter = &pw
406407

monitor/system_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"time"
88

99
"github.com/influxdata/influxdb/monitor"
10+
"github.com/influxdata/influxdb/tsdb"
1011
)
1112

1213
func TestDiagnostics_System(t *testing.T) {
13-
s := monitor.New(nil, monitor.Config{})
14+
s := monitor.New(nil, monitor.Config{}, &tsdb.Config{})
1415
if err := s.Open(); err != nil {
1516
t.Fatalf("unexpected error: %s", err)
1617
}

services/httpd/handler.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/influxdata/influxdb/services/storage"
3737
"github.com/influxdata/influxdb/storage/reads"
3838
"github.com/influxdata/influxdb/storage/reads/datatypes"
39+
"github.com/influxdata/influxdb/toml"
3940
"github.com/influxdata/influxdb/tsdb"
4041
"github.com/influxdata/influxdb/uuid"
4142
"github.com/influxdata/influxql"
@@ -2298,6 +2299,34 @@ func (h *Handler) serveExpvar(w http.ResponseWriter, r *http.Request) {
22982299
fmt.Fprintf(w, "\"cmdline\": %s", val)
22992300
}
23002301

2302+
if val := diags["config"]; val != nil {
2303+
jv, err := parseConfigDiagnostics(val)
2304+
if err != nil {
2305+
h.httpError(w, err.Error(), http.StatusInternalServerError)
2306+
return
2307+
}
2308+
2309+
data, err := json.Marshal(jv)
2310+
if err != nil {
2311+
h.httpError(w, err.Error(), http.StatusInternalServerError)
2312+
return
2313+
}
2314+
2315+
if !first {
2316+
_, err := fmt.Fprintln(w, ",")
2317+
if err != nil {
2318+
h.httpError(w, err.Error(), http.StatusInternalServerError)
2319+
return
2320+
}
2321+
}
2322+
first = false
2323+
_, err = fmt.Fprintf(w, "\"config\": %s", data)
2324+
if err != nil {
2325+
h.httpError(w, err.Error(), http.StatusInternalServerError)
2326+
return
2327+
}
2328+
}
2329+
23012330
// We're going to print some kind of crypto data, we just
23022331
// need to find the proper source for it.
23032332
{
@@ -2564,6 +2593,33 @@ func parseCryptoDiagnostics(d *diagnostics.Diagnostics) (map[string]interface{},
25642593
return m, nil
25652594
}
25662595

2596+
// parseConfigDiagnostics converts the config diagnostics into proper format
2597+
// for JSON marshaling, handling toml.Size and toml.Duration types properly.
2598+
func parseConfigDiagnostics(d *diagnostics.Diagnostics) (map[string]interface{}, error) {
2599+
if len(d.Rows) == 0 {
2600+
return nil, fmt.Errorf("no config diagnostic data available")
2601+
}
2602+
2603+
m := make(map[string]interface{})
2604+
for i, col := range d.Columns {
2605+
if i >= len(d.Rows[0]) {
2606+
continue
2607+
}
2608+
2609+
val := d.Rows[0][i]
2610+
switch v := val.(type) {
2611+
case toml.Size:
2612+
m[col] = uint64(v)
2613+
case toml.Duration:
2614+
m[col] = time.Duration(v).String()
2615+
default:
2616+
m[col] = v
2617+
}
2618+
}
2619+
2620+
return m, nil
2621+
}
2622+
25672623
// httpError writes an error to the client in a standard format.
25682624
func (h *Handler) httpError(w http.ResponseWriter, errmsg string, code int) {
25692625
if code == http.StatusUnauthorized {

tsdb/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,8 @@ func (c Config) Diagnostics() (*diagnostics.Diagnostics, error) {
286286
"max-index-log-file-size": c.MaxIndexLogFileSize,
287287
"series-id-set-cache-size": c.SeriesIDSetCacheSize,
288288
"series-file-max-concurrent-compactions": c.SeriesFileMaxConcurrentSnapshotCompactions,
289+
"aggressive-points-per-block": c.AggressivePointsPerBlock,
290+
"compact-throughput": c.CompactThroughput,
291+
"compact-throughput-burst": c.CompactThroughputBurst,
289292
}), nil
290293
}

0 commit comments

Comments
 (0)