One of the more interesting Prometheus features is its support for partitioning collected samples across one or more dimensions (labels, in Prometheus terminology). If we opt to use this feature, instead of having a single metric instance, we can work with a vector of metric values.
In the following example, we have just launched an A/B test for a new website layout and we are interested in tracking the number of user registrations for each of the page layouts that we are actively trialing:
regCountVec := promauto.NewCounterVec( prometheus.CounterOpts{ Name: "app_registrations_total", Help: "Total number of registrations by A/B test layout.", }, []string{"layout"}, ) regCountVec.WithLabelValues("a").Inc()
This time, ...