diff --git a/Makefile b/Makefile
index 43f46426..a20243e6 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,6 @@ deps:
@go mod vendor
@echo "${B}${G}=> Cleanup old files ${R}"
- @find . -type f -name '*.pb.go' -not -path './vendor/*' -exec rm {} \;
@find . -type f -name '*.proto' -not -path './vendor/*' -not -name '*_test.proto' -exec rm {} \;
@echo "${B}${G}=> NeoFS Proto files ${R}"
@@ -49,6 +48,9 @@ docgen: deps
# Regenerate proto files:
protoc: deps
+ @echo "${B}${G}=> Cleanup old files ${R}"
+ @find . -type f -name '*.pb.go' -not -path './vendor/*' -exec rm {} \;
+
@echo "${B}${G}=> Install specific version for gogo-proto ${R}"
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/gogo/protobuf | xargs go get -v
@echo "${B}${G}=> Install specific version for protobuf lib ${R}"
@@ -60,3 +62,5 @@ protoc: deps
--proto_path=.:./vendor:/usr/local/include \
--gofast_out=plugins=grpc,paths=source_relative:. $$f; \
done
+
+update: docgen protoc
diff --git a/docs/state.md b/docs/state.md
index 79504554..2b3de4a0 100644
--- a/docs/state.md
+++ b/docs/state.md
@@ -10,6 +10,8 @@
- Messages
- [DumpRequest](#state.DumpRequest)
- [DumpResponse](#state.DumpResponse)
+ - [DumpVarsRequest](#state.DumpVarsRequest)
+ - [DumpVarsResponse](#state.DumpVarsResponse)
- [HealthRequest](#state.HealthRequest)
- [HealthResponse](#state.HealthResponse)
- [MetricsRequest](#state.MetricsRequest)
@@ -39,6 +41,7 @@ rpc Netmap(NetmapRequest) returns (.bootstrap.SpreadMap);
rpc Metrics(MetricsRequest) returns (MetricsResponse);
rpc HealthCheck(HealthRequest) returns (HealthResponse);
rpc DumpConfig(DumpRequest) returns (DumpResponse);
+rpc DumpVars(DumpVarsRequest) returns (DumpVarsResponse);
```
@@ -73,6 +76,15 @@ The request should be signed.
| Name | Input | Output |
| ---- | ----- | ------ |
| DumpConfig | [DumpRequest](#state.DumpRequest) | [DumpResponse](#state.DumpResponse) |
+#### Method DumpVars
+
+DumpVars returns debug variables for the current node.
+To permit access, used server config options.
+The request should be signed.
+
+| Name | Input | Output |
+| ---- | ----- | ------ |
+| DumpVars | [DumpVarsRequest](#state.DumpVarsRequest) | [DumpVarsResponse](#state.DumpVarsResponse) |
@@ -100,6 +112,30 @@ Config stored in JSON encoded into slice of bytes.
| Config | [bytes](#bytes) | | |
+
+
+### Message DumpVarsRequest
+DumpVarsRequest message to fetch current server debug variables.
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) |
+| Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) |
+
+
+
+
+### Message DumpVarsResponse
+DumpVarsResponse message contains current server debug variables.
+Variables stored in JSON encoded into slice of bytes.
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| Variables | [bytes](#bytes) | | |
+
+
### Message HealthRequest
diff --git a/state/service.go b/state/service.go
index 343a8222..577046cc 100644
--- a/state/service.go
+++ b/state/service.go
@@ -1,7 +1,10 @@
package state
import (
+ "bytes"
"encoding/json"
+ "expvar"
+ "fmt"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
@@ -61,3 +64,25 @@ func EncodeConfig(v *viper.Viper) (*DumpResponse, error) {
return &DumpResponse{Config: data}, nil
}
+
+// EncodeVariables encodes debug variables into DumpVarsResponse message.
+// Variables encoded into JSON and stored as slice of bytes.
+func EncodeVariables() *DumpVarsResponse {
+ buf := new(bytes.Buffer)
+ buf.WriteString("{\n")
+ first := true
+
+ expvar.Do(func(kv expvar.KeyValue) {
+ if !first {
+ buf.WriteString(",\n")
+ }
+
+ first = false
+
+ _, _ = fmt.Fprintf(buf, "%q: %s", kv.Key, kv.Value)
+ })
+
+ buf.WriteString("\n}\n")
+
+ return &DumpVarsResponse{Variables: buf.Bytes()}
+}
diff --git a/state/service.pb.go b/state/service.pb.go
index f1e08dee..b55f3c12 100644
Binary files a/state/service.pb.go and b/state/service.pb.go differ
diff --git a/state/service.proto b/state/service.proto
index 312d465c..dc5efe40 100644
--- a/state/service.proto
+++ b/state/service.proto
@@ -23,6 +23,10 @@ service Status {
// To permit access, used server config options.
// The request should be signed.
rpc DumpConfig(DumpRequest) returns (DumpResponse);
+ // DumpVars returns debug variables for the current node.
+ // To permit access, used server config options.
+ // The request should be signed.
+ rpc DumpVars(DumpVarsRequest) returns (DumpVarsResponse);
}
// NetmapRequest message to request current node netmap
@@ -77,3 +81,17 @@ message DumpRequest {
message DumpResponse {
bytes Config = 1;
}
+
+// DumpVarsRequest message to fetch current server debug variables.
+message DumpVarsRequest {
+ // RequestMetaHeader contains information about request meta headers (should be embedded into message)
+ service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
+ // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message)
+ service.RequestVerificationHeader Verify = 99 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
+}
+
+// DumpVarsResponse message contains current server debug variables.
+// Variables stored in JSON encoded into slice of bytes.
+message DumpVarsResponse {
+ bytes Variables = 1;
+}
diff --git a/state/service_test.go b/state/service_test.go
new file mode 100644
index 00000000..2c089ad1
--- /dev/null
+++ b/state/service_test.go
@@ -0,0 +1,28 @@
+package state
+
+import (
+ "encoding/json"
+ "expvar"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestEncodeVariables(t *testing.T) {
+ dump := make(map[string]interface{})
+
+ expvar.NewString("test1").Set("test1")
+ expvar.NewString("test2").Set("test2")
+
+ res := EncodeVariables()
+
+ require.NoError(t, json.Unmarshal(res.Variables, &dump))
+ require.NotEmpty(t, dump)
+
+ // dump should contains keys `test1` and `test2`
+ require.Contains(t, dump, "test1")
+ require.Equal(t, "test1", dump["test1"])
+
+ require.Contains(t, dump, "test2")
+ require.Equal(t, "test2", dump["test2"])
+}