This repository was archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1161 from grafana/notifier-stuff
notifier: deprecate NSQ ( rip :'( ) + add mt-kafka-persist-sniff tool
- Loading branch information
Showing
51 changed files
with
174 additions
and
5,882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/grafana/metrictank/mdata" | ||
"github.com/raintank/schema" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type PrintNotifierHandler struct{} | ||
|
||
func NewPrintNotifierHandler() PrintNotifierHandler { | ||
return PrintNotifierHandler{} | ||
} | ||
|
||
func (dn PrintNotifierHandler) PartitionOf(key schema.MKey) (int32, bool) { | ||
return 0, false | ||
} | ||
|
||
func (dn PrintNotifierHandler) Handle(data []byte) { | ||
version := uint8(data[0]) | ||
if version == uint8(mdata.PersistMessageBatchV1) { | ||
batch := mdata.PersistMessageBatch{} | ||
err := json.Unmarshal(data[1:], &batch) | ||
if err != nil { | ||
log.Errorf("failed to unmarsh batch message: %s -- skipping", err) | ||
return | ||
} | ||
for _, c := range batch.SavedChunks { | ||
fmt.Printf("%s %d %s\n", batch.Instance, c.T0, c.Key) | ||
} | ||
} else { | ||
log.Errorf("unknown message version %d", version) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
|
||
"github.com/grafana/metrictank/logger" | ||
"github.com/grafana/metrictank/mdata/notifierKafka" | ||
"github.com/grafana/metrictank/stats" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
fmt.Fprintln(os.Stderr, "mt-kafka-persist-sniff") | ||
fmt.Fprintln(os.Stderr, "Print what's flowing through kafka metric persist topic") | ||
fmt.Fprintf(os.Stderr, "\nFlags:\n\n") | ||
flag.PrintDefaults() | ||
notifierKafka.FlagSet.PrintDefaults() | ||
} | ||
formatter := &logger.TextFormatter{} | ||
formatter.TimestampFormat = "2006-01-02 15:04:05.000" | ||
log.SetFormatter(formatter) | ||
log.SetLevel(log.InfoLevel) | ||
instance := "mt-kafka-persist-sniff" + strconv.Itoa(rand.Int()) | ||
|
||
notifierKafka.FlagSet.Usage = flag.Usage | ||
notifierKafka.FlagSet.Parse(os.Args[1:]) | ||
// config may have had it disabled | ||
notifierKafka.Enabled = true | ||
|
||
stats.NewDevnull() // make sure metrics don't pile up without getting discarded | ||
|
||
notifierKafka.ConfigProcess(instance) | ||
|
||
done := make(chan struct{}) | ||
go func() { | ||
notifierKafka.New(instance, NewPrintNotifierHandler()) | ||
close(done) | ||
}() | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
select { | ||
case sig := <-sigChan: | ||
log.Infof("Received signal %q. Shutting down", sig) | ||
case <-done: | ||
} | ||
// notifierKafka.Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.