diff --git a/config.md b/config.md index ce4b7b6e21..9a569c5026 100644 --- a/config.md +++ b/config.md @@ -1,7 +1,7 @@ # Honeycomb Refinery Configuration Documentation This is the documentation for the configuration file for Honeycomb's Refinery. -It was automatically generated on 2023-07-10 at 16:05:02 UTC. +It was automatically generated on 2023-07-10 at 20:11:38 UTC. ## The Config file diff --git a/config/config.go b/config/config.go index fca8ab6987..0e58e7a1f4 100644 --- a/config/config.go +++ b/config/config.go @@ -35,6 +35,9 @@ type Config interface { // data before forwarding it to a peer. GetCompressPeerCommunication() bool + // GetGRPCEnabled returns or not the GRPC server is enabled. + GetGRPCEnabled() bool + // GetGRPCListenAddr returns the address and port on which to listen for // incoming events over gRPC GetGRPCListenAddr() (string, error) diff --git a/config/config_test.go b/config/config_test.go index 929be7855f..63fec681c8 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -598,6 +598,8 @@ func TestGRPCServerParameters(t *testing.T) { "GRPCServerParameters.MaxConnectionAgeGrace", "3m", "GRPCServerParameters.KeepAlive", "4m", "GRPCServerParameters.KeepAliveTimeout", "5m", + "GRPCServerParameters.ListenAddr", "localhost:4317", + "GRPCServerParameters.Enabled", true, ) rm := makeYAML("ConfigVersion", 2) config, rules := createTempConfigs(t, cm, rm) @@ -611,6 +613,10 @@ func TestGRPCServerParameters(t *testing.T) { assert.Equal(t, 3*time.Minute, c.GetGRPCMaxConnectionAgeGrace()) assert.Equal(t, 4*time.Minute, c.GetGRPCKeepAlive()) assert.Equal(t, 5*time.Minute, c.GetGRPCKeepAliveTimeout()) + assert.Equal(t, true, c.GetGRPCEnabled()) + addr, err := c.GetGRPCListenAddr() + assert.NoError(t, err) + assert.Equal(t, "localhost:4317", addr) } func TestHoneycombAdditionalErrorConfig(t *testing.T) { diff --git a/config/file_config.go b/config/file_config.go index af9f80646e..b67e4cfdb2 100644 --- a/config/file_config.go +++ b/config/file_config.go @@ -224,7 +224,7 @@ type IDFieldsConfig struct { // by refinery's own GRPC server: // https://pkg.go.dev/google.golang.org/grpc/keepalive#ServerParameters type GRPCServerParameters struct { - Enabled bool `yaml:"Enabled"` + Enabled bool `yaml:"Enabled" default:"true"` ListenAddr string `yaml:"ListenAddr" cmdenv:"GRPCListenAddr"` MaxConnectionIdle Duration `yaml:"MaxConnectionIdle" default:"1m"` MaxConnectionAge Duration `yaml:"MaxConnectionAge" default:"3m"` @@ -463,6 +463,12 @@ func (f *fileConfig) GetCompressPeerCommunication() bool { return f.mainConfig.Specialized.CompressPeerCommunication } +func (f *fileConfig) GetGRPCEnabled() bool { + f.mux.RLock() + defer f.mux.RUnlock() + return f.mainConfig.GRPCServerParameters.Enabled +} + func (f *fileConfig) GetGRPCListenAddr() (string, error) { f.mux.RLock() defer f.mux.RUnlock() diff --git a/config/metadata/configMeta.yaml b/config/metadata/configMeta.yaml index 5b9f47e0c2..e6bf12ca08 100644 --- a/config/metadata/configMeta.yaml +++ b/config/metadata/configMeta.yaml @@ -1134,7 +1134,8 @@ groups: fields: - name: Enabled type: bool - valuetype: nondefault + valuetype: conditional + extra: "nonempty GRPCListenAddr" default: false reload: false summary: specifies whether the gRPC server is enabled. diff --git a/config/mock.go b/config/mock.go index d6fc29d273..cb7ea33865 100644 --- a/config/mock.go +++ b/config/mock.go @@ -22,6 +22,7 @@ type MockConfig struct { GetPeerListenAddrErr error GetPeerListenAddrVal string GetCompressPeerCommunicationsVal bool + GetGRPCEnabledVal bool GetGRPCListenAddrErr error GetGRPCListenAddrVal string GetLoggerTypeErr error @@ -160,6 +161,12 @@ func (m *MockConfig) GetCompressPeerCommunication() bool { return m.GetCompressPeerCommunicationsVal } +func (m *MockConfig) GetGRPCEnabled() bool { + m.Mux.RLock() + defer m.Mux.RUnlock() + return m.GetGRPCEnabledVal +} + func (m *MockConfig) GetGRPCListenAddr() (string, error) { m.Mux.RLock() defer m.Mux.RUnlock() diff --git a/route/route.go b/route/route.go index 10272b0f7e..bd83ee4c63 100644 --- a/route/route.go +++ b/route/route.go @@ -208,7 +208,7 @@ func (r *Router) LnS(incomingOrPeer string) { Handler: muxxer, } - if len(grpcAddr) > 0 { + if r.Config.GetGRPCEnabled() && len(grpcAddr) > 0 { l, err := net.Listen("tcp", grpcAddr) if err != nil { r.iopLogger.Error().Logf("failed to listen to grpc addr: " + grpcAddr) diff --git a/rules.md b/rules.md index ab2e1b7314..3c29ea0a12 100644 --- a/rules.md +++ b/rules.md @@ -1,7 +1,7 @@ # Honeycomb Refinery Rules Documentation This is the documentation for the rules configuration for Honeycomb's Refinery. -It was automatically generated on 2023-07-10 at 16:05:02 UTC. +It was automatically generated on 2023-07-10 at 20:11:39 UTC. ## The Rules file diff --git a/tools/convert/helpers.go b/tools/convert/helpers.go index d464ffdb1a..960bfb1f87 100644 --- a/tools/convert/helpers.go +++ b/tools/convert/helpers.go @@ -110,6 +110,14 @@ func conditional(data map[string]any, key string, extra string) string { return fmt.Sprintf("%s: true", key) } } + case "nonempty": + k := extras[1] + if value, ok := _fetch(data, k); ok { + v := fmt.Sprintf("%v", value) + if v != "" { + return fmt.Sprintf("%s: true", key) + } + } default: panic("Unknown conditional: " + extra) } diff --git a/tools/convert/templates/configV2.tmpl b/tools/convert/templates/configV2.tmpl index ffcadd004e..e153ed88ba 100644 --- a/tools/convert/templates/configV2.tmpl +++ b/tools/convert/templates/configV2.tmpl @@ -2,7 +2,7 @@ ## Honeycomb Refinery Configuration ## ###################################### # -# created {{ now }} from {{ .Input }} using a template generated on 2023-07-10 at 16:05:01 UTC +# created {{ now }} from {{ .Input }} using a template generated on 2023-07-10 at 20:11:37 UTC # This file contains a configuration for the Honeycomb Refinery. It is in YAML # format, organized into named groups, each of which contains a set of @@ -905,7 +905,7 @@ GRPCServerParameters: ## accepted. ## ## Not eligible for live reload. - {{ nonDefaultOnly .Data "Enabled" "Enabled" false }} + {{ conditional .Data "Enabled" "nonempty GRPCListenAddr" }} ## ListenAddr is the address Refinery listens to for incoming GRPC ## OpenTelemetry events.