Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
move murron log type configuration into a command line flag
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Demmer <[email protected]>
  • Loading branch information
demmer committed Oct 10, 2018
1 parent 841f096 commit 17aaaf6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go/cmd/vtgate/plugin_murron_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
}

func initMurronLogger() {
logger, err := slack.InitMurronLogger("vtgate_querylog")
logger, err := slack.InitMurronLogger()
if err != nil {
log.Errorf("error initializing murron logger: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vttablet/plugin_murron_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
}

func initMurronLogger() {
logger, err := slack.InitMurronLogger("vtgate_querylog")
logger, err := slack.InitMurronLogger()
if err != nil {
log.Errorf("error initializing murron logger: %v", err)
return
Expand Down
23 changes: 14 additions & 9 deletions go/slack/murronlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package slack
import (
"bytes"
"flag"
"fmt"
"os"
"time"

Expand All @@ -34,6 +35,7 @@ import (

var (
murronConfigFile = flag.String("murron_config_file", "", "If specified, enables murron logging using the agent configuration in the given file.")
murronLogType = flag.String("murron_querylog_type", "", "Type string for query logs sent to murron. Must be set if murron logging is enabled.")

murronLogs = stats.NewCounter("MurronLogs", "count of logs dispatched to the murron queue")
murronErrors = stats.NewCountersWithSingleLabel("MurronErrors", "count of errors sending to murron by error type", "Type")
Expand All @@ -48,15 +50,19 @@ func MurronLoggerEnabled() bool {

// MurronLogger is a logger abstraction to send to murron
type MurronLogger struct {
logType string
queue chan *murronpb.MurronMessage
client murronoutputs.OutputService
queue chan *murronpb.MurronMessage
client murronoutputs.OutputService
}

// InitMurronLogger creates a new logger to send to murron
// Should only be called with a valid config file
func InitMurronLogger(logType string) (*MurronLogger, error) {
log.Infof("enabling %s query logging to murron", logType)
// Should only be called with a valid config file and if log type is set
func InitMurronLogger() (*MurronLogger, error) {

if *murronConfigFile == "" || *murronLogType == "" {
return nil, fmt.Errorf("murron logging requires -murron_config_file and -murron_querylog_type to be set")
}

log.Infof("enabling %s query logging to murron", *murronLogType)

/* Load murron configuration */
config, err := murronlib.ReadConfig(*murronConfigFile)
Expand All @@ -65,8 +71,7 @@ func InitMurronLogger(logType string) (*MurronLogger, error) {
}

ml := &MurronLogger{
logType: logType,
queue: make(chan *murronpb.MurronMessage, config.QueueSize),
queue: make(chan *murronpb.MurronMessage, config.QueueSize),
}

servenv.OnClose(func() {
Expand Down Expand Up @@ -99,7 +104,7 @@ func (ml *MurronLogger) SendMessage(formatter streamlog.LogFormatter, message in
OriginHost: hostname,
Timestamp: time.Now().UnixNano(),
Host: hostname,
Type: ml.logType,
Type: *murronLogType,
Message: buf.Bytes(),
}
select {
Expand Down

0 comments on commit 17aaaf6

Please sign in to comment.