Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: expose metrics when as a library #39218

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions br/pkg/lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Lightning struct {

promFactory promutil.Factory
promRegistry promutil.Registry
metrics *metric.Metrics

cancelLock sync.Mutex
curTask *config.Config
Expand Down Expand Up @@ -388,6 +389,7 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, o *opti
defer func() {
metrics.UnregisterFrom(o.promRegistry)
}()
l.metrics = metrics

ctx := metric.NewContext(taskCtx, metrics)
ctx = log.NewContext(ctx, o.logger)
Expand Down Expand Up @@ -544,6 +546,11 @@ func (l *Lightning) Status() (finished int64, total int64) {
return
}

// Metrics returns the metrics of lightning.
func (l *Lightning) Metrics() *metric.Metrics {
return l.metrics
}

func writeJSONError(w http.ResponseWriter, code int, prefix string, err error) {
type errorResponse struct {
Error string `json:"error"`
Expand Down