Skip to content

Commit

Permalink
added a lot of nasty boilerplate but simplified the eventreporter int…
Browse files Browse the repository at this point in the history
…erface and usage process
  • Loading branch information
Miles Crabill committed Aug 9, 2016
1 parent 93df0fe commit a6e7e9a
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 58 deletions.
2 changes: 1 addition & 1 deletion events/datadog.go
Expand Up @@ -11,7 +11,7 @@ import (

// DatadogConfig is the configuration for a Datadog
type DatadogConfig struct {
*eventReporterConfig
*EventReporterConfig
Host string
Port string
}
Expand Down
15 changes: 15 additions & 0 deletions events/datadog_events.go
Expand Up @@ -99,3 +99,18 @@ func (e *DatadogEvents) NewBatchReapableEvent(rs []Reapable, tags []string) erro
}
return nil
}

// NewCountStatistic is a method of EventReporter
func (e *DatadogEvents) NewCountStatistic(string, []string) error {
return nil
}

// NewStatistic is a method of EventReporter
func (e *DatadogEvents) NewStatistic(string, float64, []string) error {
return nil
}

// GetConfig is a method of EventReporter
func (e *DatadogEvents) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}
10 changes: 10 additions & 0 deletions events/datadog_statistics.go
Expand Up @@ -54,6 +54,11 @@ func (e *DatadogStatistics) NewCountStatistic(name string, tags []string) error
return err
}

// GetConfig is a method of EventReporter
func (e *DatadogStatistics) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}

// NewReapableEvent is a method of EventReporter
func (e *DatadogStatistics) NewReapableEvent(r Reapable, tags []string) error {
return nil
Expand All @@ -63,3 +68,8 @@ func (e *DatadogStatistics) NewReapableEvent(r Reapable, tags []string) error {
func (e *DatadogStatistics) NewBatchReapableEvent(rs []Reapable, tags []string) error {
return nil
}

// NewEvent is a method of EventReporter
func (e *DatadogStatistics) NewEvent(string, string, map[string]string, []string) error {
return nil
}
12 changes: 4 additions & 8 deletions events/events.go
Expand Up @@ -24,7 +24,7 @@ type Reapable interface {
}

// EventReporterConfig has configuration variables for EventReporters
type eventReporterConfig struct {
type EventReporterConfig struct {
Enabled bool
DryRun bool

Expand All @@ -34,7 +34,7 @@ type eventReporterConfig struct {
Triggers []string
}

func (e *eventReporterConfig) parseTriggers() (triggers []state.StateEnum) {
func (e *EventReporterConfig) parseTriggers() (triggers []state.StateEnum) {
for _, t := range e.Triggers {
switch t {
case "first":
Expand All @@ -54,7 +54,7 @@ func (e *eventReporterConfig) parseTriggers() (triggers []state.StateEnum) {
return
}

func (e *eventReporterConfig) shouldTriggerFor(r Reapable) bool {
func (e *EventReporterConfig) shouldTriggerFor(r Reapable) bool {
triggering := false
// if the reapable's state is set to trigger this EventReporter
for _, trigger := range e.parseTriggers() {
Expand All @@ -81,15 +81,11 @@ type Cleaner interface {
// EventReporter contains different event and statistics reporting
// embeds ReapableEventReporter
type EventReporter interface {
ReapableEventReporter
NewEvent(title string, text string, fields map[string]string, tags []string) error
NewStatistic(name string, value float64, tags []string) error
NewCountStatistic(name string, tags []string) error
}

// ReapableEventReporter handles Reapable events
type ReapableEventReporter interface {
NewReapableEvent(r Reapable, tags []string) error
NewBatchReapableEvent(rs []Reapable, tags []string) error
SetDryRun(b bool)
GetConfig() EventReporterConfig
}
22 changes: 21 additions & 1 deletion events/interactive.go
Expand Up @@ -9,7 +9,7 @@ import (

// InteractiveEventConfig is the configuration for an InteractiveEvent
type InteractiveEventConfig struct {
*eventReporterConfig
*EventReporterConfig
}

// InteractiveEvent implements ReapableEventReporter, offers choices
Expand Down Expand Up @@ -74,3 +74,23 @@ func (e *InteractiveEvent) NewBatchReapableEvent(rs []Reapable, tags []string) e
}
return nil
}

// GetConfig is a method of EventReporter
func (e *InteractiveEvent) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}

// NewCountStatistic is a method of EventReporter
func (e *InteractiveEvent) NewCountStatistic(string, []string) error {
return nil
}

// NewStatistic is a method of EventReporter
func (e *InteractiveEvent) NewStatistic(string, float64, []string) error {
return nil
}

// NewEvent is a method of EventReporter
func (e *InteractiveEvent) NewEvent(string, string, map[string]string, []string) error {
return nil
}
22 changes: 21 additions & 1 deletion events/mailer.go
Expand Up @@ -31,7 +31,7 @@ type HTTPConfig struct {
// MailerConfig is the configuration for a Mailer
type MailerConfig struct {
HTTPConfig
*eventReporterConfig
*EventReporterConfig

CopyEmailAddresses []string

Expand Down Expand Up @@ -180,3 +180,23 @@ func (e *Mailer) send(to mail.Address, subject string, htmlBody *bytes.Buffer) e

return m.Send(e.Config.Addr(), e.Config.Auth())
}

// GetConfig is a method of EventReporter
func (e *Mailer) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}

// NewCountStatistic is a method of EventReporter
func (e *Mailer) NewCountStatistic(string, []string) error {
return nil
}

// NewStatistic is a method of EventReporter
func (e *Mailer) NewStatistic(string, float64, []string) error {
return nil
}

// NewEvent is a method of EventReporter
func (e *Mailer) NewEvent(string, string, map[string]string, []string) error {
return nil
}
22 changes: 21 additions & 1 deletion events/reaperevent.go
Expand Up @@ -8,7 +8,7 @@ import (

// ReaperEventConfig is the configuration for a ReaperEvent
type ReaperEventConfig struct {
*eventReporterConfig
*EventReporterConfig

Mode string
}
Expand Down Expand Up @@ -61,3 +61,23 @@ func (e *ReaperEvent) NewBatchReapableEvent(rs []Reapable, tags []string) error
}
return nil
}

// GetConfig is a method of EventReporter
func (e *ReaperEvent) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}

// NewCountStatistic is a method of EventReporter
func (e *ReaperEvent) NewCountStatistic(string, []string) error {
return nil
}

// NewStatistic is a method of EventReporter
func (e *ReaperEvent) NewStatistic(string, float64, []string) error {
return nil
}

// NewEvent is a method of EventReporter
func (e *ReaperEvent) NewEvent(string, string, map[string]string, []string) error {
return nil
}
22 changes: 21 additions & 1 deletion events/tagger.go
Expand Up @@ -4,7 +4,7 @@ import log "github.com/mozilla-services/reaper/reaperlog"

// TaggerConfig is the configuration for a Tagger
type TaggerConfig struct {
*eventReporterConfig
*EventReporterConfig
}

// Tagger is an ReapableEventReporter that tags AWS Resources
Expand Down Expand Up @@ -49,3 +49,23 @@ func (e *Tagger) NewBatchReapableEvent(rs []Reapable, tags []string) error {
}
return nil
}

// GetConfig is a method of EventReporter
func (e *Tagger) GetConfig() EventReporterConfig {
return *e.Config.EventReporterConfig
}

// NewCountStatistic is a method of EventReporter
func (e *Tagger) NewCountStatistic(string, []string) error {
return nil
}

// NewStatistic is a method of EventReporter
func (e *Tagger) NewStatistic(string, float64, []string) error {
return nil
}

// NewEvent is a method of EventReporter
func (e *Tagger) NewEvent(string, string, map[string]string, []string) error {
return nil
}
10 changes: 5 additions & 5 deletions main.go
Expand Up @@ -14,7 +14,7 @@ import (

var (
config reaper.Config
eventReporters []reaperevents.ReapableEventReporter
eventReporters []reaperevents.EventReporter
)

func init() {
Expand Down Expand Up @@ -64,7 +64,7 @@ func init() {
eventReporters = append(eventReporters, reaperevents.NewDatadogEvents(&config.Events.DatadogEvents))
}

// if Email ReapableEventReporter is enabled
// if Email EventReporter is enabled
if config.Events.Email.Enabled {
log.Info("Email EventReporter enabled.")
eventReporters = append(eventReporters, reaperevents.NewMailer(&config.Events.Email))
Expand All @@ -73,13 +73,13 @@ func init() {
log.Debug("SMTP From: %s", &config.Events.Email.From)
}

// if Tagger ReapableEventReporter is enabled
// if Tagger EventReporter is enabled
if config.Events.Tagger.Enabled {
log.Info("Tagger EventReporter enabled.")
eventReporters = append(eventReporters, reaperevents.NewTagger(&config.Events.Tagger))
}

// if Reaper ReapableEventReporter is enabled
// if Reaper EventReporter is enabled
if config.Events.Reaper.Enabled {
log.Info("Reaper EventReporter enabled.")
eventReporters = append(eventReporters, reaperevents.NewReaperEvent(&config.Events.Reaper))
Expand All @@ -90,7 +90,7 @@ func init() {
config.Interactive = *interactive
if *interactive {
log.Info("Interactive mode enabled, you will be prompted to handle reapables. All other EventReporters are disabled.")
eventReporters = []reaperevents.ReapableEventReporter{reaperevents.NewInteractiveEvent(&config.Events.Interactive)}
eventReporters = []reaperevents.EventReporter{reaperevents.NewInteractiveEvent(&config.Events.Interactive)}
}

// if a WhitelistTag is set
Expand Down

0 comments on commit a6e7e9a

Please sign in to comment.