Skip to content

Commit

Permalink
Merge branch 'main' into kent.2.7.last_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kentquirk authored Jul 26, 2024
2 parents cac889e + 38883ff commit ba18c66
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
33 changes: 18 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,31 @@ type App struct {
// Start exits, Stop will be called on all dependencies then on App then the
// program will exit.
func (a *App) Start() error {
// little helper function to record the current config and rules hashes; we call it in
// the callback but also at startup
record_hashes := func(msg string) {
cfgHash, rulesHash := a.Config.GetHashes()
if a.Logger != nil {
a.Logger.Warn().WithFields(map[string]interface{}{
"configHash": cfgHash,
"rulesHash": rulesHash,
}).Logf(msg)
}
cfgMetric := config.ConfigHashMetrics(cfgHash)
ruleMetric := config.ConfigHashMetrics(rulesHash)
a.Metrics.Gauge("config_hash", cfgMetric)
a.Metrics.Gauge("rule_config_hash", ruleMetric)
}

a.Logger.Debug().Logf("Starting up App...")
a.Metrics.Register("config_hash", "gauge")
a.Metrics.Register("rule_config_hash", "gauge")

a.IncomingRouter.SetVersion(a.Version)
a.PeerRouter.SetVersion(a.Version)

record_hashes("loaded configuration at startup")
a.Config.RegisterReloadCallback(func(configHash, rulesHash string) {
if a.Logger != nil {
a.Logger.Warn().WithFields(map[string]interface{}{
"configHash": configHash,
"rulesHash": rulesHash,
}).Logf("configuration change was detected and the configuration was reloaded.")

cfgMetric := config.ConfigHashMetrics(configHash)
ruleMetric := config.ConfigHashMetrics(rulesHash)

a.Metrics.Gauge("config_hash", cfgMetric)
a.Metrics.Gauge("rule_config_hash", ruleMetric)

}

record_hashes("configuration change was detected and the configuration was reloaded.")
})

// launch our main routers to listen for incoming event traffic from both peers
Expand Down
24 changes: 8 additions & 16 deletions cmd/refinery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func main() {
os.Exit(1)
}

// set up the peer management and pubsub implementations
var peers peer.Peers
var pubsubber pubsub.PubSub
ptype, err := c.GetPeerManagementType()
Expand All @@ -124,24 +125,15 @@ func main() {
}
switch ptype {
case "file":
// we want to use the file peers object to ask if we have only one peer, so we need to instantiate it
// with a dummy metrics object. we'll replace it with the real one later.
peers = &peer.FilePeers{Cfg: c, Metrics: &metrics.NullMetrics{}}
// if we only have one, we can use the local pubsub implementation.
peerList, err := peers.GetPeers()
if err != nil {
panic(err)
}
if len(peerList) == 1 {
pubsubber = &pubsub.LocalPubSub{}
} else {
pubsubber = &pubsub.GoRedisPubSub{}
}
// now erase the peers Metrics object so that it will get injected with the right one later
peers.(*peer.FilePeers).Metrics = nil
// In the case of file peers, we do not use Redis for anything, including pubsub, so
// we use the local pubsub implementation. Even if we have multiple peers, these
// peers cannot communicate using pubsub.
peers = &peer.FilePeers{}
pubsubber = &pubsub.LocalPubSub{}
case "redis":
pubsubber = &pubsub.GoRedisPubSub{}
// if we're using redis, we need to set it up for both peers and pubsub
peers = &peer.RedisPubsubPeers{}
pubsubber = &pubsub.GoRedisPubSub{}
default:
// this should have been caught by validation
panic("invalid config option 'PeerManagement.Type'")
Expand Down
11 changes: 7 additions & 4 deletions config/metadata/configMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -835,12 +835,15 @@ groups:
Peer management is the mechanism by which Refinery locates its peers.
`file` means that Refinery gets its peer list from the Peers list in
this config file.
this config file. It also prevents Refinery from using a publish/subscribe
mechanism to propagate peer lists, stress levels, and configuration changes.
`redis` means that Refinery uses a Publish/Subscribe mechanism,
implemented on Redis, to propagate peer lists much more quickly than
the legacy mechanism. This is the recommended setting, especially for
new installations.
implemented on Redis, to propagate peer lists, stress levels, and
notification of configuration changes much more quickly than the
legacy mechanism. This is the recommended setting, especially for new
installations. If this is specified, fields in `RedisPeerManagement`
must also be set.
- name: Identifier
v1group: PeerManagement
Expand Down
6 changes: 3 additions & 3 deletions test/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Network:

Logger:
Type: stdout
Level: debug
Level: info

LegacyMetrics:
Enabled: true
Dataset: refinery_metrics
APIKey: HTab42OXw838zcJDH3eJEH
APIKey: $REFINERY_HONEYCOMB_API_KEY
APIHost: https://api-dogfood.honeycomb.io

OTelMetrics:
Enabled: true
Dataset: refinery_metrics_otel
APIKey: HTab42OXw838zcJDH3eJEH
APIKey: $REFINERY_HONEYCOMB_API_KEY
APIHost: https://api-dogfood.honeycomb.io

RefineryTelemetry:
Expand Down

0 comments on commit ba18c66

Please sign in to comment.