add skaffold and fix bugs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@@ -14,27 +13,12 @@ import (
|
||||
|
||||
const promSubsystem = "database"
|
||||
|
||||
var (
|
||||
promDbHeartbeat = promauto.NewHistogramVec(prom.HistogramOpts{
|
||||
Namespace: globals.PrometheusPrefix, Subsystem: promSubsystem,
|
||||
Name: "heartbeat_time",
|
||||
Help: "Time in seconds for succeeded heartbeat, or 0 on failure",
|
||||
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
|
||||
}, []string{"connection_id"})
|
||||
|
||||
promDbCmd = promauto.NewHistogramVec(prom.HistogramOpts{
|
||||
Namespace: globals.PrometheusPrefix, Subsystem: promSubsystem,
|
||||
Name: "operation_latency", // "command_time",
|
||||
Help: "Time in seconds of commands",
|
||||
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
|
||||
}, []string{"connection_id", "command_name"})
|
||||
|
||||
promDbCmdErr = promauto.NewCounterVec(prom.CounterOpts{
|
||||
Namespace: globals.PrometheusPrefix, Subsystem: promSubsystem,
|
||||
Name: "errors",
|
||||
Help: "Failed commands (also reflected elsewhere)",
|
||||
}, []string{"connection_id", "command_name"})
|
||||
)
|
||||
var promDbHeartbeat = promauto.NewHistogramVec(prom.HistogramOpts{
|
||||
Namespace: globals.PrometheusPrefix, Subsystem: promSubsystem,
|
||||
Name: "heartbeat_time",
|
||||
Help: "Time in seconds for succeeded heartbeat, or 0 on failure",
|
||||
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
|
||||
}, []string{"connection_id"})
|
||||
|
||||
func monitoredClientOptions() *mongoOpt.ClientOptions {
|
||||
return mongoOpt.Client().
|
||||
@@ -46,15 +30,5 @@ func monitoredClientOptions() *mongoOpt.ClientOptions {
|
||||
promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0)
|
||||
log.Printf("database heartbeat failed on connection %q: %e", ev.ConnectionID, ev.Failure)
|
||||
},
|
||||
}).
|
||||
SetMonitor(&mongoEvent.CommandMonitor{
|
||||
Succeeded: func(_ context.Context, ev *mongoEvent.CommandSucceededEvent) {
|
||||
promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds())
|
||||
},
|
||||
Failed: func(_ context.Context, ev *mongoEvent.CommandFailedEvent) {
|
||||
promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds())
|
||||
|
||||
promDbCmdErr.WithLabelValues(ev.ConnectionID, ev.CommandName).Add(1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -22,11 +22,15 @@ func Initialize(ctx context.Context, uri string) (*mongo.Collection, error) {
|
||||
|
||||
dbOpt := monitoredClientOptions().ApplyURI(uri)
|
||||
|
||||
dbClient, err := mongo.Connect(globals.MongoTimeout(ctx))
|
||||
dbClient, err := mongo.Connect(globals.MongoTimeout(ctx), dbOpt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("connecting to %q: %w", dbOpt.GetURI(), err)
|
||||
}
|
||||
|
||||
if err := dbClient.Ping(globals.MongoTimeout(ctx), nil); err != nil {
|
||||
return nil, fmt.Errorf("first ping to database: %w", err)
|
||||
}
|
||||
|
||||
col := dbClient.Database(uriParsed.Path).Collection("logs")
|
||||
|
||||
if err := InitializeIndexes(globals.MongoTimeout(ctx), col); err != nil {
|
||||
|
@@ -32,10 +32,10 @@ var App = &cli.App{
|
||||
//TODO: &cli.BoolFlag{Name: "normalize-log-level", Usage: "Normalize log.level values to Syslog defined keywords"},
|
||||
//TODO: &cli.BoolFlag{Name: "parse-json"},
|
||||
//
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "pod-namespace", EnvVars: []string{"KUBE_POD_NAMESPACE"}, Usage: "whitelist filter for filenames"},
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "namespace", EnvVars: []string{"KUBE_NAMESPACE"}, Usage: "whitelist filter for filenames"},
|
||||
&cli.StringSliceFlag{Category: "selectors", Name: "pod-prefix", EnvVars: []string{"KUBE_NODE_NAME"}, Usage: "blacklist filter for filenames"},
|
||||
//
|
||||
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGO_URI"}, Usage: "mongodb://foo:bar@host:27017/database", Required: true},
|
||||
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGODB_URI"}, Usage: "mongodb://foo:bar@host:27017/database", Required: true},
|
||||
},
|
||||
Before: func(ctx *cli.Context) error {
|
||||
globals.BufferLimitBytes = ctx.Int("max-record-size")
|
||||
@@ -49,7 +49,7 @@ var App = &cli.App{
|
||||
},
|
||||
|
||||
Action: func(ctx *cli.Context) error {
|
||||
whitelistNamespaces, blacklistPodPrefixes := sliceToMap(ctx.StringSlice("pod-namespace")), ctx.StringSlice("pod-prefix")
|
||||
whitelistNamespaces, blacklistPodPrefixes := sliceToMap(ctx.StringSlice("namespace")), ctx.StringSlice("pod-prefix")
|
||||
var wg sync.WaitGroup
|
||||
|
||||
log.Printf("%s %s starting", ctx.App.Name, ctx.App.Version)
|
||||
|
Reference in New Issue
Block a user