Skip to content

Commit

Permalink
add shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskerv committed Jun 20, 2023
1 parent 62a568f commit 38bf85f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions fluent-bit-kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
var (
pluginInstances []*kinesis.OutputPlugin
enr *enricher.Enricher
metricsServer *metricserver.MetricServer
)

func addPluginInstance(ctx unsafe.Pointer) error {
Expand Down Expand Up @@ -262,6 +263,8 @@ func newKinesisOutput(ctx unsafe.Pointer, pluginID int) (*kinesis.OutputPlugin,
return nil, err
}

metricsServer = ms

cfgs = append(cfgs, eks.WithMetricServer(ms))

go func() {
Expand Down Expand Up @@ -397,6 +400,9 @@ func unpackRecords(kinesisOutput *kinesis.OutputPlugin, data unsafe.Pointer, len

//export FLBPluginExit
func FLBPluginExit() int {
if metricsServer != nil {
metricsServer.Shutdown()
}

return output.FLB_OK
}
Expand Down
19 changes: 17 additions & 2 deletions metricserver/metricserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package metricserver

import (
"context"
"fmt"
"net/http"

Expand All @@ -18,6 +19,8 @@ const (
type MetricServerConfiguration func(*MetricServer) error

type MetricServer struct {
s http.Server

port int

meterProvider *sdk.MeterProvider
Expand Down Expand Up @@ -55,9 +58,21 @@ func WithPort(Port int) MetricServerConfiguration {
}

func (m *MetricServer) Start() {
http.Handle("/metrics", promhttp.Handler())
router := http.NewServeMux()

router.Handle("/metrics", promhttp.Handler())

m.s.Handler = router
m.s.Addr = fmt.Sprintf(":%v", m.port)

logrus.Infof("Started metric server on port %v", m.port)
logrus.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", m.port), nil))
logrus.Fatal(m.s.ListenAndServe())
}

func (m *MetricServer) Shutdown() {
logrus.Info("shutting down metrics server")
m.s.Shutdown(context.Background())
logrus.Info("shutdown metrics server complete")
}

func (m *MetricServer) GetMeter(scope string) metric.Meter {
Expand Down

0 comments on commit 38bf85f

Please sign in to comment.