-
Notifications
You must be signed in to change notification settings - Fork 54
/
events.go
41 lines (35 loc) · 1022 Bytes
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"log"
"github.com/DataDog/kafka-kit/v4/kafkametrics"
)
// Events configs.
var eventTitlePrefix = "kafka-autothrottle"
// DDEventWriter wraps a channel where *kafkametrics.Event are written
// to along with any defaults configs, such as tags to apply to each event.
type DDEventWriter struct {
c chan *kafkametrics.Event
tags []string
titlePrefix string
}
// Write takes an event title and message string and writes a
// *kafkametrics.Event to the event channel, formatted with
// the configured title and tags.
func (e *DDEventWriter) Write(t string, m string) {
e.c <- &kafkametrics.Event{
Title: fmt.Sprintf("[%s] %s", e.titlePrefix, t),
Text: m,
Tags: e.tags,
}
}
// eventWriter reads from a channel of *kafkametrics.Event and writes
// them to the Datadog API.
func eventWriter(k kafkametrics.Handler, c chan *kafkametrics.Event) {
for e := range c {
err := k.PostEvent(e)
if err != nil {
log.Printf("Error writing event: %s\n", err)
}
}
}