Skip to content

Commit

Permalink
Expose metrics through new ServeMetrics hook (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Nov 21, 2023
1 parent 8408b6e commit b40ee31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Req
return
}

// NOTE: deprecated in favor of the ServeMetrics hook. Consider removing in v1.0.
if strings.HasPrefix(r.URL.Path, "/metrics") && p.metrics != nil {
p.metrics.Handler().ServeHTTP(w, r)
return
Expand Down
9 changes: 5 additions & 4 deletions server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (l *logger) Fatal(msg string, fields ...logr.Field) {
l.p.API.LogError(msg, l.fieldsToArgs(fields)...)
}

// Satisfying the interface here but we need a fix upstream for this to be any useful.
func (l *logger) Sugar(_ ...logr.Field) logr.Sugar {
return logr.Sugar{}
}

func (l *logger) Flush() error {
return nil
}
Expand All @@ -143,7 +148,3 @@ func (l *logger) IsLevelEnabled(_ logr.Level) bool {
func (l *logger) With(_ ...logr.Field) *mlog.Logger {
return nil
}

func (l *logger) Sugar(_ ...mlog.Field) mlog.Sugar {
return mlog.Sugar{}
}
5 changes: 5 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"database/sql"
"fmt"
"net/http"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -369,3 +370,7 @@ func (p *Plugin) updateCallPostEnded(postID string, participants []string) (floa

return dur, nil
}

func (p *Plugin) ServeMetrics(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
p.metrics.Handler().ServeHTTP(w, r)
}

0 comments on commit b40ee31

Please sign in to comment.