Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update file_config to honor GRPCServerParameters.Enabled #771

Merged
merged 7 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion config/metadata/configMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions config/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MockConfig struct {
GetPeerListenAddrErr error
GetPeerListenAddrVal string
GetCompressPeerCommunicationsVal bool
GetGRPCEnabledVal bool
GetGRPCListenAddrErr error
GetGRPCListenAddrVal string
GetLoggerTypeErr error
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rules.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 8 additions & 0 deletions tools/convert/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions tools/convert/templates/configV2.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down