Skip to content
Snippets Groups Projects

praefect: Backport separate endpoint for datastore collector (v14.4)

1 unresolved thread
2 files
+ 57
17
Compare changes
  • Side-by-side
  • Inline
Files
2
  • Our current code path will trigger the RepositoryStoreCollector to query
    the database on startup, even if the prometheus listener is not
    listening. This is because we call DescribeByCollect in the Describe
    method. The Prometheus client will call Describe on Register, which ends
    up triggering the Collect method and hence runs the queries. Instead, we
    can just provide the decriptions separately from the Collect method.
    
    Changelog: fixed
    (cherry picked from commit 90cb7fb7)
@@ -11,21 +11,25 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql"
)
// This is kept for backwards compatibility as some alerting rules depend on this.
// The unavailable repositories is a more accurate description for the metric and
// is exported below so we can migrate to it.
var descReadOnlyRepositories = prometheus.NewDesc(
"gitaly_praefect_read_only_repositories",
"Number of repositories in read-only mode within a virtual storage.",
[]string{"virtual_storage"},
nil,
)
var descUnavailableRepositories = prometheus.NewDesc(
"gitaly_praefect_unavailable_repositories",
"Number of repositories that have no healthy, up to date replicas.",
[]string{"virtual_storage"},
nil,
var (
// This is kept for backwards compatibility as some alerting rules depend on this.
// The unavailable repositories is a more accurate description for the metric and
// is exported below so we can migrate to it.
descReadOnlyRepositories = prometheus.NewDesc(
"gitaly_praefect_read_only_repositories",
"Number of repositories in read-only mode within a virtual storage.",
[]string{"virtual_storage"},
nil,
)
descUnavailableRepositories = prometheus.NewDesc(
"gitaly_praefect_unavailable_repositories",
"Number of repositories that have no healthy, up to date replicas.",
[]string{"virtual_storage"},
nil,
)
descriptions = []*prometheus.Desc{descReadOnlyRepositories, descUnavailableRepositories}
)
// RepositoryStoreCollector collects metrics from the RepositoryStore.
@@ -47,7 +51,9 @@ func NewRepositoryStoreCollector(log logrus.FieldLogger, virtualStorages []strin
}
func (c *RepositoryStoreCollector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(c, ch)
for _, desc := range descriptions {
ch <- desc
}
}
func (c *RepositoryStoreCollector) Collect(ch chan<- prometheus.Metric) {
@@ -61,7 +67,7 @@ func (c *RepositoryStoreCollector) Collect(ch chan<- prometheus.Metric) {
}
for _, vs := range c.virtualStorages {
for _, desc := range []*prometheus.Desc{descReadOnlyRepositories, descUnavailableRepositories} {
for _, desc := range descriptions {
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, float64(unavailableCounts[vs]), vs)
}
}
Loading