Skip to content

Commit 29573c0

Browse files
Fix metrics cache (#394)
Signed-off-by: Anders Swanson <[email protected]>
1 parent 5ec8adf commit 29573c0

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

collector/cache.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewMetricsCache(metrics map[string]*Metric) *MetricsCache {
1313

1414
for _, metric := range metrics {
1515
c[metric] = &MetricCacheRecord{
16-
PrometheusMetrics: map[string]prometheus.Metric{},
16+
PrometheusMetrics: nil,
1717
LastScraped: nil,
1818
}
1919
}
@@ -36,7 +36,11 @@ func (c *MetricsCache) SendAll(ch chan<- prometheus.Metric, m *Metric) {
3636
}
3737
}
3838

39+
func (c *MetricsCache) Reset(m *Metric) {
40+
c.cache[m].PrometheusMetrics = nil
41+
}
42+
3943
func (c *MetricsCache) CacheAndSend(ch chan<- prometheus.Metric, m *Metric, metric prometheus.Metric) {
40-
c.cache[m].PrometheusMetrics[metric.Desc().String()] = metric
44+
c.cache[m].PrometheusMetrics = append(c.cache[m].PrometheusMetrics, metric)
4145
ch <- metric
4246
}

collector/collector.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ func (e *Exporter) scrapeGenericValues(d *Database, ch chan<- prometheus.Metric,
428428

429429
// Build metric desc
430430
suffix := metricNameSuffix(row, metric, m.FieldToAppend)
431+
fqname := prometheus.BuildFQName(namespace, m.Context, suffix)
431432
desc := prometheus.NewDesc(
432-
prometheus.BuildFQName(namespace, m.Context, suffix),
433+
fqname,
433434
metricHelp,
434435
m.GetLabels(),
435436
constLabels,
@@ -467,6 +468,7 @@ func (e *Exporter) scrapeGenericValues(d *Database, ch chan<- prometheus.Metric,
467468
return nil
468469
}
469470
e.logger.Debug("Calling function GeneratePrometheusMetrics()")
471+
d.MetricsCache.Reset(m)
470472
err := e.generatePrometheusMetrics(d, genericParser, m.Request, getQueryTimeout(e.logger, m, d))
471473
e.logger.Debug("ScrapeGenericValues() - metricsCount: " + strconv.Itoa(metricsCount))
472474
if err != nil {

collector/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type MetricsCache struct {
4949
type MetricCacheRecord struct {
5050
// PrometheusMetrics stores cached prometheus metric values.
5151
// Used when custom scrape intervals are used, and the metric must be returned to the collector, but not scraped.
52-
PrometheusMetrics map[string]prometheus.Metric
52+
PrometheusMetrics []prometheus.Metric
5353
// LastScraped is the collector tick time when the metric was last computed.
5454
LastScraped *time.Time
5555
}

site/docs/releases/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ List of upcoming and historic changes to the exporter.
1212
Our current priorities to support metrics for advanced database features and use cases, like Exadata, GoldenGate, and views included in the Oracle Diagnostics Pack.
1313

1414
- Move `oracledb_dbtype` metric to the default metrics. You may now disable or override this metric like any other database metric.
15-
- Document required database permissions for the exporter
15+
- Document required database permissions for the exporter.
16+
- Fix an issue where some metrics would not be cached when using a per-metric scrape interval with a global scrape interval.
1617

1718
Thank you to the following people for their suggestions and contributions:
1819
- [@MansuyDavid](https://github.com/MansuyDavid)

0 commit comments

Comments
 (0)