From ba4aa98cc2cb5fe3286d1132fb052649c9e79f1e Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:49:39 +0300 Subject: [PATCH 1/5] Refactoring Makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From e12a7887cbbc6f139dbb3c423c16788471d77d11 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:50:08 +0300 Subject: [PATCH 2/5] Update documentation --- docs/state.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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 From bf5cd8b74088542932d4fcd5d7a5d7cba4e7d875 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:51:24 +0300 Subject: [PATCH 3/5] Update service.proto file and generate go-code --- state/service.pb.go | Bin 50143 -> 62235 bytes state/service.proto | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/state/service.pb.go b/state/service.pb.go index f1e08dee3d96eb0efc29f6b4f5a26363b71d5dce..b55f3c12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E z_EJ%VJ94^)06p{|TJWr_L=my9pr0uzag#<*bCSaHbD@y;8 zn-!R^P`3f7>vs3oyRQ{ubL|#d%#q;iTMdk>5ry1CSA#2+;3;+2sbI+j;N)|_!NlPT zBu3oDy}&Y$ws@5_6VhsV;%zxW7kdZ545b#{qIM!#v%|=sxmHsnlGC%mD*g9X4c=@s zHU1;?4m{`XP)N#kRsay34bTSspHlN~4T{0yFc4@kH2cB?me>=&?9Ce<%%+`$*>g=2 zfP~GgfbHY~4-5B=*v!~Zgww&cmUF^^v&Xp^cFt8Gwvg1T6_JQDX+u1dRH;6`H~3Mh zX^|vN$(S${yR$dTIg_-p8+NeTjYm1gwd$DA)Lvx|^_WxI0t+NSF__hs zFVk-GfJ5sq&)$+~N11cLx$Yf4TX?zJb0iWVs}9=5>j-4Tf#s)?vUrLE8~tv|OyXv} z!H>EQFzL|ic=o4YfQ-cy`<=6u!aRSCaP54w<{PrNVmbkDpLj7&lfIHx1!x8O=M*?# zjpsN^47S_hH2cAucc z{|5uH^O_!M?nuLal^>;4MqQqCkn2B?T-j0l`}Dh-w5!+j1P9$p>h0mtmf?)E$JvZs z89;AdokM4P<0eP8gYN8^-SN}o&mSJc2YMIR5$c X`Rm6oUp{-~c=q-8?;ZP}-@W`VN;Ka6 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; +} From cf5f6b11923a87417e1a5e5d8b20b996ed9471a7 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:52:07 +0300 Subject: [PATCH 4/5] Implement function to encode debug variables --- state/service.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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()} +} From fc91a5b2323759442472a86a33c38b6d2155c1ef Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:52:49 +0300 Subject: [PATCH 5/5] Add tests for EncodeVariables --- state/service_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 state/service_test.go 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"]) +}