Skip to content

Commit

Permalink
lightning: expose metrics when as a library (#39218)
Browse files Browse the repository at this point in the history
ref #38455
  • Loading branch information
lance6716 authored Nov 18, 2022
1 parent 9c48480 commit 777cb5f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,12 @@ func (l *Lightning) Status() (finished int64, total int64) {
return
}

// Metrics returns the metrics of lightning.
// it's inited during `run`, so might return nil.
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

0 comments on commit 777cb5f

Please sign in to comment.