Browse Source

Use enums instead

pull/91/head
Kegan Dougal 8 years ago
parent
commit
19eeb96610
  1. 25
      src/github.com/matrix-org/go-neb/metrics/metrics.go
  2. 6
      src/github.com/matrix-org/go-neb/plugin/plugin.go

25
src/github.com/matrix-org/go-neb/metrics/metrics.go

@ -4,6 +4,14 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
type CommandStatus int
const (
Pending CommandStatus = iota
Success
Failure
)
var (
numIncomingCmds = prometheus.NewCounter(prometheus.CounterOpts{
Name: "num_incoming_commands_total",
@ -19,19 +27,16 @@ var (
})
)
// IncIncomingCommand increments the incoming command counter (TODO: cmd type)
func IncIncomingCommand() {
// IncrementCommand increments the incoming command counter (TODO: cmd type)
func IncrementCommand(st CommandStatus) {
switch st {
case Pending:
numIncomingCmds.Inc()
}
// IncSuccessCommand increments the success command counter (TODO: cmd type)
func IncSuccessCommand() {
case Success:
numSuccessCmds.Inc()
}
// IncErrorCommand increments the error command counter (TODO: cmd type)
func IncErrorCommand() {
case Failure:
numErrorCmds.Inc()
}
}
func init() {

6
src/github.com/matrix-org/go-neb/plugin/plugin.go

@ -72,7 +72,7 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string)
"user_id": event.Sender,
"command": bestMatch.Path,
}).Info("Executing command")
metrics.IncIncomingCommand()
metrics.IncrementCommand(metrics.Pending)
content, err := bestMatch.Command(event.RoomID, event.Sender, cmdArgs)
if err != nil {
if content != nil {
@ -84,10 +84,10 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string)
"args": cmdArgs,
}).Warn("Command returned both error and content.")
}
metrics.IncErrorCommand()
metrics.IncrementCommand(metrics.Failure)
content = matrix.TextMessage{"m.notice", err.Error()}
} else {
metrics.IncSuccessCommand()
metrics.IncrementCommand(metrics.Success)
}
return content

Loading…
Cancel
Save