Skip to content

Commit

Permalink
Removed file changes to resolve conflict. (prometheus#1318)
Browse files Browse the repository at this point in the history
Signed-off-by: manosf <manosf@protonmail.com>
  • Loading branch information
manosf authored and stuartnelson3 committed Apr 17, 2018
1 parent e7bc6e2 commit 300a87e
Show file tree
Hide file tree
Showing 23 changed files with 856 additions and 593 deletions.
45 changes: 6 additions & 39 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s Secret) MarshalJSON() ([]byte, error) {
// Load parses the YAML input s into a Config.
func Load(s string) (*Config, error) {
cfg := &Config{}
err := yaml.Unmarshal([]byte(s), cfg)
err := yaml.UnmarshalStrict([]byte(s), cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -111,24 +111,10 @@ type Config struct {
Receivers []*Receiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
Templates []string `yaml:"templates" json:"templates"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`

// original is the input from which the config was parsed.
original string
}

func checkOverflow(m map[string]interface{}, ctx string) error {
if len(m) > 0 {
var keys []string
for k := range m {
keys = append(keys, k)
}
return fmt.Errorf("unknown fields in %s: %s", ctx, strings.Join(keys, ", "))
}
return nil
}

func (c Config) String() string {
b, err := yaml.Marshal(c)
if err != nil {
Expand Down Expand Up @@ -331,11 +317,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

// Validate that all receivers used in the routing tree are defined.
if err := checkReceiver(c.Route, names); err != nil {
return err
}

return checkOverflow(c.XXX, "config")
return checkReceiver(c.Route, names)
}

// checkReceiver returns an error if a node in the routing tree
Expand Down Expand Up @@ -397,19 +379,13 @@ type GlobalConfig struct {
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
VictorOpsAPIURL string `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultGlobalConfig
type plain GlobalConfig
if err := unmarshal((*plain)(c)); err != nil {
return err
}
return checkOverflow(c.XXX, "global")
return unmarshal((*plain)(c))
}

// A Route is a node that contains definitions of how to handle alerts.
Expand All @@ -425,9 +401,6 @@ type Route struct {
GroupWait *model.Duration `yaml:"group_wait,omitempty" json:"group_wait,omitempty"`
GroupInterval *model.Duration `yaml:"group_interval,omitempty" json:"group_interval,omitempty"`
RepeatInterval *model.Duration `yaml:"repeat_interval,omitempty" json:"repeat_interval,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand Down Expand Up @@ -465,7 +438,7 @@ func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
return fmt.Errorf("repeat_interval cannot be zero")
}

return checkOverflow(r.XXX, "route")
return nil
}

// InhibitRule defines an inhibition rule that mutes alerts that match the
Expand All @@ -487,9 +460,6 @@ type InhibitRule struct {
// A set of labels that must be equal between the source and target alert
// for them to be a match.
Equal model.LabelNames `yaml:"equal,omitempty" json:"equal,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand Down Expand Up @@ -523,7 +493,7 @@ func (r *InhibitRule) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
}

return checkOverflow(r.XXX, "inhibit rule")
return nil
}

// Receiver configuration provides configuration on how to contact a receiver.
Expand All @@ -540,9 +510,6 @@ type Receiver struct {
WechatConfigs []*WechatConfig `yaml:"wechat_configs,omitempty" json:"wechat_configs,omitempty"`
PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"`
VictorOpsConfigs []*VictorOpsConfig `yaml:"victorops_configs,omitempty" json:"victorops_configs,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -554,7 +521,7 @@ func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.Name == "" {
return fmt.Errorf("missing name in receiver")
}
return checkOverflow(c.XXX, "receiver config")
return nil
}

// Regexp encapsulates a regexp.Regexp and makes it YAML marshalable.
Expand Down
5 changes: 2 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ func TestDefaultReceiverExists(t *testing.T) {
route:
group_wait: 30s
`
conf := &Config{}
err := yaml.Unmarshal([]byte(in), conf)
_, err := Load(in)

expected := "root route must specify a default receiver"
expected := "root route must specify a default receiver"

if err == nil {
t.Fatalf("no error returned, expected:\n%v", expected)
Expand Down
51 changes: 9 additions & 42 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ type EmailConfig struct {
HTML string `yaml:"html,omitempty" json:"html,omitempty"`
Text string `yaml:"text,omitempty" json:"text,omitempty"`
RequireTLS *bool `yaml:"require_tls,omitempty" json:"require_tls,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -188,7 +185,7 @@ func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
c.Headers = normalizedHeaders

return checkOverflow(c.XXX, "email config")
return nil
}

// PagerdutyConfig configures notifications via PagerDuty.
Expand All @@ -208,9 +205,6 @@ type PagerdutyConfig struct {
Class string `yaml:"class,omitempty" json:"class,omitempty"`
Component string `yaml:"component,omitempty" json:"component,omitempty"`
Group string `yaml:"group,omitempty" json:"group,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -223,7 +217,7 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
if c.RoutingKey == "" && c.ServiceKey == "" {
return fmt.Errorf("missing service or routing key in PagerDuty config")
}
return checkOverflow(c.XXX, "pagerduty config")
return nil
}

// SlackConfig configures notifications via Slack.
Expand All @@ -250,19 +244,13 @@ type SlackConfig struct {
IconEmoji string `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty"`
IconURL string `yaml:"icon_url,omitempty" json:"icon_url,omitempty"`
LinkNames bool `yaml:"link_names,omitempty" json:"link_names,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *SlackConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultSlackConfig
type plain SlackConfig
if err := unmarshal((*plain)(c)); err != nil {
return err
}
return checkOverflow(c.XXX, "slack config")
return unmarshal((*plain)(c))
}

// HipchatConfig configures notifications via Hipchat.
Expand All @@ -279,9 +267,6 @@ type HipchatConfig struct {
Message string `yaml:"message,omitempty" json:"message,omitempty"`
MessageFormat string `yaml:"message_format,omitempty" json:"message_format,omitempty"`
Color string `yaml:"color,omitempty" json:"color,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" ,json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -294,8 +279,7 @@ func (c *HipchatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.RoomID == "" {
return fmt.Errorf("missing room id in Hipchat config")
}

return checkOverflow(c.XXX, "hipchat config")
return nil
}

// WebhookConfig configures notifications via a generic webhook.
Expand All @@ -306,9 +290,6 @@ type WebhookConfig struct {

// URL to send POST request to.
URL string `yaml:"url" json:"url"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -329,7 +310,7 @@ func (c *WebhookConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
return fmt.Errorf("scheme required for webhook url")
}
c.URL = url.String()
return checkOverflow(c.XXX, "webhook config")
return nil
}

// WechatConfig configures notifications via Wechat.
Expand All @@ -346,9 +327,6 @@ type WechatConfig struct {
ToParty string `yaml:"to_party,omitempty" json:"to_party,omitempty"`
ToTag string `yaml:"to_tag,omitempty" json:"to_tag,omitempty"`
AgentID string `yaml:"agent_id,omitempty" json:"agent_id,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -364,7 +342,7 @@ func (c *WechatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.CorpID == "" {
return fmt.Errorf("missing Wechat CorpID in Wechat config")
}
return checkOverflow(c.XXX, "Wechat config")
return nil
}

// OpsGenieConfig configures notifications via OpsGenie.
Expand All @@ -383,19 +361,13 @@ type OpsGenieConfig struct {
Tags string `yaml:"tags,omitempty" json:"tags,omitempty"`
Note string `yaml:"note,omitempty" json:"note,omitempty"`
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultOpsGenieConfig
type plain OpsGenieConfig
if err := unmarshal((*plain)(c)); err != nil {
return err
}
return checkOverflow(c.XXX, "opsgenie config")
return unmarshal((*plain)(c))
}

// VictorOpsConfig configures notifications via VictorOps.
Expand All @@ -411,8 +383,6 @@ type VictorOpsConfig struct {
StateMessage string `yaml:"state_message" json:"state_message"`
EntityDisplayName string `yaml:"entity_display_name" json:"entity_display_name"`
MonitoringTool string `yaml:"monitoring_tool" json:"monitoring_tool"`

XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -425,7 +395,7 @@ func (c *VictorOpsConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
if c.RoutingKey == "" {
return fmt.Errorf("missing Routing key in VictorOps config")
}
return checkOverflow(c.XXX, "victorops config")
return nil
}

type duration time.Duration
Expand Down Expand Up @@ -455,9 +425,6 @@ type PushoverConfig struct {
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"`
Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand All @@ -473,5 +440,5 @@ func (c *PushoverConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
if c.Token == "" {
return fmt.Errorf("missing token in Pushover config")
}
return checkOverflow(c.XXX, "pushover config")
return nil
}
Loading

0 comments on commit 300a87e

Please sign in to comment.