-
Notifications
You must be signed in to change notification settings - Fork 9
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
Make HA as configurable plugin by Blip users #116
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ha | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cashapp/blip" | ||
"sync" | ||
) | ||
|
||
type HAManagerFactory interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove "HA" prefix. In Go, pkg name is considered part of the full name context, so |
||
Make(monitor blip.ConfigMonitor) (Manager, error) | ||
} | ||
|
||
type defaultFactory struct { | ||
} | ||
|
||
var df = &defaultFactory{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In keeping with other pkgs (iirc): // Internal factory disabled by default (HA not used).
var f = Disabled Then put the factor Then in |
||
|
||
func Register(f HAManagerFactory) error { | ||
hf.Lock() | ||
defer hf.Unlock() | ||
// Check if it's different from the default factory | ||
if hf.ha != df { | ||
return fmt.Errorf("HA already registered") | ||
} | ||
hf.ha = f | ||
blip.Debug("register HA") | ||
return nil | ||
} | ||
|
||
func Make(args blip.ConfigMonitor) (Manager, error) { | ||
hf.Lock() | ||
defer hf.Unlock() | ||
if hf.ha == nil { | ||
return nil, fmt.Errorf("HA not registered") | ||
} | ||
return hf.ha.Make(args) | ||
} | ||
|
||
type haf struct { | ||
*sync.Mutex | ||
ha HAManagerFactory | ||
} | ||
|
||
var hf = &haf{ | ||
Mutex: &sync.Mutex{}, | ||
ha: df, | ||
} | ||
|
||
func (f *defaultFactory) Make(_ blip.ConfigMonitor) (Manager, error) { | ||
return Disabled, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"crypto/sha256" | ||
"errors" | ||
"fmt" | ||
"github.com/cashapp/blip/ha" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort the imports:
|
||
"os" | ||
"sync" | ||
"time" | ||
|
@@ -463,11 +464,19 @@ func (ml *Loader) makeMonitor(cfg blip.ConfigMonitor) (*Monitor, error) { | |
sinks = append(sinks, sink) | ||
} | ||
|
||
// Configure the HA Manager for the monitor | ||
var ham ha.Manager | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "ham" 😆 This component will now officially be known as "the ham". |
||
ham, err := ha.Make(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mon := NewMonitor(MonitorArgs{ | ||
Config: cfg, | ||
DbMaker: ml.factory.DbConn, | ||
PlanLoader: ml.planLoader, | ||
Sinks: sinks, | ||
HA: ham, | ||
TransformMetric: ml.plugin.TransformMetrics, | ||
}) | ||
return mon, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this all in ha/ha.go since it's all closely related--one less file.