Skip to content

Commit

Permalink
Merge branch 'feat/kafka-receiver-2' into feat/kafka-receiver
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Khac Thanh <[email protected]>
  • Loading branch information
magiskboy committed Jan 14, 2025
2 parents 9ce6ecc + 9a1f674 commit c193a5a
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 8 deletions.
1 change: 1 addition & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ go:
# Whenever the Go version is updated here,
# .circle/config.yml should also be updated.
version: 1.23
cgo: true
repository:
path: github.com/prometheus/alertmanager
build:
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ type Receiver struct {
MSTeamsV2Configs []*MSTeamsV2Config `yaml:"msteamsv2_configs,omitempty" json:"msteamsv2_configs,omitempty"`
JiraConfigs []*JiraConfig `yaml:"jira_configs,omitempty" json:"jira_configs,omitempty"`
RocketchatConfigs []*RocketchatConfig `yaml:"rocketchat_configs,omitempty" json:"rocketchat_configs,omitempty"`
KafkaConfigs []*KafkaConfig `yaml:"kafka_configs,omitempty" json:"kafka_configs,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface for Receiver.
Expand Down
26 changes: 26 additions & 0 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ var (
Description: `{{ template "jira.default.description" . }}`,
Priority: `{{ template "jira.default.priority" . }}`,
}

DefaultKafkaConfig = KafkaConfig{
NotifierConfig: NotifierConfig{
VSendResolved: true,
},

BootstrapServers: `{{ template "kafka.default.bootstrap_servers" . }}`,
Topic: `{{ template "kafka.default.topic" . }}`,
NumberOfPartition: 0,
}
)

// NotifierConfig contains base options common across all notifier configurations.
Expand Down Expand Up @@ -996,3 +1006,19 @@ func (c *RocketchatConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
}
return nil
}

type KafkaConfig struct {
NotifierConfig `yaml:",inline" json:",inline"`

BootstrapServers string `yaml:"bootstrap_servers" json:"bootstrap_servers"`
Topic string `yaml:"topic" json:"topic"`
ExtrasConfigs *map[string]string `yaml:"extras_configs" json:"extras_configs"`
NumberOfPartition int `yaml:"number_of_partitions" json:"number_of_partitions"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *KafkaConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultKafkaConfig
type plain KafkaConfig
return unmarshal((*plain)(c))
}
4 changes: 4 additions & 0 deletions config/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prometheus/alertmanager/notify/discord"
"github.com/prometheus/alertmanager/notify/email"
"github.com/prometheus/alertmanager/notify/jira"
"github.com/prometheus/alertmanager/notify/kafka"
"github.com/prometheus/alertmanager/notify/msteams"
"github.com/prometheus/alertmanager/notify/msteamsv2"
"github.com/prometheus/alertmanager/notify/opsgenie"
Expand Down Expand Up @@ -109,6 +110,9 @@ func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg
for i, c := range nc.RocketchatConfigs {
add("rocketchat", i, c, func(l *slog.Logger) (notify.Notifier, error) { return rocketchat.New(c, tmpl, l, httpOpts...) })
}
for i, c := range nc.KafkaConfigs {
add("kafka", i, c, func(l *slog.Logger) (notify.Notifier, error) { return kafka.New(c, l) })
}

if errs.Len() > 0 {
return nil, &errs
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/coder/quartz v0.1.2
github.com/confluentinc/confluent-kafka-go/v2 v2.8.0
github.com/emersion/go-smtp v0.21.3
github.com/go-openapi/analysis v0.23.0
github.com/go-openapi/errors v0.22.0
Expand Down Expand Up @@ -65,13 +66,13 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.1 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -92,7 +93,7 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand Down
Loading

0 comments on commit c193a5a

Please sign in to comment.