github.com/vseinstrumentiru/lego@v1.0.2/internal/lego/transport/event/metrics/lables.go (about)

     1  package metrics
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ThreeDotsLabs/watermill/message"
     7  	"github.com/prometheus/client_golang/prometheus"
     8  )
     9  
    10  const (
    11  	labelKeyHandlerName    = "handler_name"
    12  	labelKeyPublisherName  = "publisher_name"
    13  	labelKeySubscriberName = "subscriber_name"
    14  	labelSuccess           = "success"
    15  	// labelAcked             = "acked"
    16  
    17  	labelValueNoHandler = "<no handler>"
    18  )
    19  
    20  var (
    21  	labelGetters = map[string]func(context.Context) string{
    22  		labelKeyHandlerName:    message.HandlerNameFromCtx,
    23  		labelKeyPublisherName:  message.PublisherNameFromCtx,
    24  		labelKeySubscriberName: message.SubscriberNameFromCtx,
    25  	}
    26  )
    27  
    28  func labelsFromCtx(ctx context.Context, labels ...string) prometheus.Labels {
    29  	ctxLabels := map[string]string{}
    30  
    31  	for _, l := range labels {
    32  		k := l
    33  		ctxLabels[l] = ""
    34  
    35  		getter, ok := labelGetters[k]
    36  		if !ok {
    37  			continue
    38  		}
    39  
    40  		v := getter(ctx)
    41  		if v != "" {
    42  			ctxLabels[l] = v
    43  		}
    44  	}
    45  
    46  	return ctxLabels
    47  }