Unified Storage: Adds metric to count indexed docs by kind (#96056)

Adds metric to count indexed docs by kind
This commit is contained in:
owensmallwood 2024-11-07 13:12:13 -06:00 committed by GitHub
parent 1fdc48faba
commit d023cb5931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -205,6 +205,9 @@ func (i *Index) InitForTenant(ctx context.Context, namespace string) (int, error
return totalObjectsFetched, err
}
// Record the number of objects indexed for the kind
IndexServerMetrics.IndexedKinds.WithLabelValues(rt.Key.Resource).Add(float64(len(list.Items)))
totalObjectsFetched += len(list.Items)
logger.Debug("indexing batch", "kind", rt.Key.Resource, "count", len(list.Items), "namespace", namespace)
@ -277,6 +280,9 @@ func (i *Index) Index(ctx context.Context, data *Data) error {
return err
}
//record the kind of resource that was indexed
IndexServerMetrics.IndexedKinds.WithLabelValues(res.Kind).Inc()
// record latency from when event was created to when it was indexed
latencySeconds := float64(time.Now().UnixMicro()-data.Value.ResourceVersion) / 1e6
if latencySeconds > 5 {

View File

@ -23,6 +23,7 @@ type IndexMetrics struct {
IndexLatency *prometheus.HistogramVec
IndexSize prometheus.Gauge
IndexedDocs prometheus.Gauge
IndexedKinds *prometheus.CounterVec
IndexCreationTime *prometheus.HistogramVec
}
@ -52,6 +53,11 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
Name: "indexed_docs",
Help: "Number of indexed documents by resource",
}),
IndexedKinds: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "index_server",
Name: "indexed_kinds",
Help: "Number of indexed documents by kind",
}, []string{"kind"}),
IndexCreationTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "index_server",
Name: "index_creation_time_seconds",
@ -70,6 +76,7 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
s.IndexLatency.Collect(ch)
s.IndexCreationTime.Collect(ch)
s.IndexedKinds.Collect(ch)
// collect index size
totalSize, err := getTotalIndexSize(s.IndexDir)
@ -85,22 +92,16 @@ func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
func (s *IndexMetrics) Describe(ch chan<- *prometheus.Desc) {
s.IndexLatency.Describe(ch)
s.IndexSize.Describe(ch)
s.IndexedDocs.Describe(ch)
s.IndexedKinds.Describe(ch)
s.IndexCreationTime.Describe(ch)
}
// getTotalDocCount returns the total number of documents in the index
func getTotalDocCount(index *Index) float64 {
var totalCount float64
totalCount = 0
if index == nil {
return totalCount
}
for _, shard := range index.shards {
count, _ := shard.index.DocCount()
totalCount += float64(count)
}
return totalCount
count, _ := index.Count()
return float64(count)
}
// getTotalIndexSize returns the total size of the index directory when using a file-based index