Skip to content

Commit

Permalink
Allow operator to disable host resource information (os, arch, cpus, …
Browse files Browse the repository at this point in the history
…mem) on the NodeInfo endpoint
  • Loading branch information
pschork committed Jul 10, 2024
1 parent b23166c commit 44695ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
ClientIPHeader string
UseSecureGrpc bool
ReachabilityPollIntervalSec uint64
DisableNodeInfoResources bool

EthClientConfig geth.EthClientConfig
LoggerConfig common.LoggerConfig
Expand Down Expand Up @@ -201,5 +202,6 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
NumBatchDeserializationWorkers: ctx.GlobalInt(flags.NumBatchDeserializationWorkersFlag.Name),
ClientIPHeader: ctx.GlobalString(flags.ClientIPHeaderFlag.Name),
UseSecureGrpc: ctx.GlobalBoolT(flags.ChurnerUseSecureGRPC.Name),
DisableNodeInfoResources: ctx.GlobalBool(flags.DisableNodeInfoResourcesFlag.Name),
}, nil
}
8 changes: 8 additions & 0 deletions node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ var (
Value: "",
EnvVar: common.PrefixEnvVar(EnvVarPrefix, "CLIENT_IP_HEADER"),
}

DisableNodeInfoResourcesFlag = cli.BoolFlag{
Name: common.PrefixFlag(FlagPrefix, "disable-node-info-resources"),
Usage: "Disable system resource information (OS, architecture, CPU, memory) on the NodeInfo API",
Required: false,
EnvVar: common.PrefixEnvVar(EnvVarPrefix, "DISABLE_NODE_INFO_RESOURCES"),
}
)

var requiredFlags = []cli.Flag{
Expand Down Expand Up @@ -299,6 +306,7 @@ var optionalFlags = []cli.Flag{
EcdsaKeyFileFlag,
EcdsaKeyPasswordFlag,
DataApiUrlFlag,
DisableNodeInfoResourcesFlag,
}

func init() {
Expand Down
4 changes: 4 additions & 0 deletions node/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func (s *Server) serveRetrieval() error {
}

func (s *Server) NodeInfo(ctx context.Context, in *pb.NodeInfoRequest) (*pb.NodeInfoReply, error) {
if s.config.DisableNodeInfoResources {
return &pb.NodeInfoReply{Semver: node.SemVer, Os: "", Arch: "", NumCpu: 0, MemBytes: 0}, nil
}

memBytes := uint64(0)
v, err := mem.VirtualMemory()
if err == nil {
Expand Down
4 changes: 0 additions & 4 deletions node/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,6 @@ func TestNodeInfoRequest(t *testing.T) {
server := newTestServer(t, true)
resp, err := server.NodeInfo(context.Background(), &pb.NodeInfoRequest{})
assert.True(t, resp.Semver == "0.0.0")
assert.True(t, resp.Os != "")
assert.True(t, resp.Arch != "")
assert.True(t, resp.NumCpu > 0)
assert.True(t, resp.MemBytes >= 0)
assert.True(t, err == nil)
}

Expand Down

0 comments on commit 44695ea

Please sign in to comment.