Skip to content

Commit

Permalink
fix measurements reload to actually update interval/attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryFissionGames committed Aug 19, 2024
1 parent 72bf50c commit 9e33cc1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ misspell-fix:

.PHONY: test
test:
$(MAKE) for-all CMD="go test -race ./..."
$(MAKE) for-all CMD="go test -ldflags="-extldflags='-ld_classic'" -race ./..."

.PHONY: test-with-cover
test-with-cover:
Expand Down
19 changes: 16 additions & 3 deletions opamp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"crypto/x509"
"errors"
"fmt"
"maps"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -57,7 +58,7 @@ type Config struct {
Labels *string `yaml:"labels,omitempty"`
AgentName *string `yaml:"agent_name,omitempty"`
MeasurementsInterval time.Duration `yaml:"measurements_interval,omitempty"`
ExtraMeasurementsAttributes map[string]string `yaml:"extra_measurements_interval,omitempty"`
ExtraMeasurementsAttributes map[string]string `yaml:"extra_measurements_attributes,omitempty"`
}

// TLSConfig represents the TLS config to connect to OpAmp server
Expand Down Expand Up @@ -156,8 +157,9 @@ func ParseConfig(configLocation string) (*Config, error) {
func (c Config) Copy() *Config {

cfgCopy := &Config{
Endpoint: c.Endpoint,
AgentID: c.AgentID,
Endpoint: c.Endpoint,
AgentID: c.AgentID,
MeasurementsInterval: c.MeasurementsInterval,
}

if c.SecretKey != nil {
Expand All @@ -175,6 +177,9 @@ func (c Config) Copy() *Config {
if c.TLS != nil {
cfgCopy.TLS = c.TLS.copy()
}
if c.ExtraMeasurementsAttributes != nil {
cfgCopy.ExtraMeasurementsAttributes = maps.Clone(c.ExtraMeasurementsAttributes)
}

return cfgCopy
}
Expand Down Expand Up @@ -215,6 +220,14 @@ func (c Config) CmpUpdatableFields(o Config) (equal bool) {
return false
}

if c.MeasurementsInterval != o.MeasurementsInterval {
return false
}

if !maps.Equal(c.ExtraMeasurementsAttributes, o.ExtraMeasurementsAttributes) {
return false
}

return cmpStringPtr(c.Labels, o.Labels)
}

Expand Down
2 changes: 2 additions & 0 deletions opamp/observiq/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ func (m *measurementsSender) loop() {
case <-m.done:
return
case <-t.Chan():
m.logger.Info("Ticker fired, sending measurements")
if m.reporter == nil {
// Continue if no reporter available
m.logger.Info("No reporter, skipping sending measurements.")
continue
}

Expand Down
2 changes: 2 additions & 0 deletions opamp/observiq/observiq_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ func (c *Client) onMessageFuncHandler(ctx context.Context, msg *types.MessageDat
}
if msg.CustomCapabilities != nil {
if slices.Contains(msg.CustomCapabilities.Capabilities, measurements.ReportMeasurementsV1Capability) {
c.logger.Info("Server supports custom message measurements, starting sender.")
c.measurementsSender.Start()
} else {
c.logger.Info("Server does not support custom message measurements, stopping sender.")
c.measurementsSender.Stop()
}
}
Expand Down
1 change: 1 addition & 0 deletions opamp/observiq/reload_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func managerReload(client *Client, managerConfigPath string) opamp.ReloadFunc {
client.currentConfig.AgentName = newConfig.AgentName
client.currentConfig.Labels = newConfig.Labels
client.currentConfig.MeasurementsInterval = newConfig.MeasurementsInterval
client.currentConfig.ExtraMeasurementsAttributes = newConfig.ExtraMeasurementsAttributes

// Update identity
client.ident.agentName = newConfig.AgentName
Expand Down

0 comments on commit 9e33cc1

Please sign in to comment.