Skip to content

Multiple custom metrics files overwrite one another #179

Closed
@Sycri

Description

@Sycri

If multiple files for custom metrics are specified using environment variable CUSTOM_METRICS, then upon loading metrics in

if _, err := toml.DecodeFile(_customMetrics, &additionalMetrics); err != nil {
the variable additionalMetrics is reused from
additionalMetrics Metrics
and overwritten when reading from the second file for custom metrics.

The problem seems to be caused by the fact that metrics are read from that same variable additionalMetrics and due to it being type Metrics which itself is a struct that contains a slice of struct Metric, it is all being reused and therefore overwritten when the second file for custom metrics is read.

Example:
File docker-compose.yaml

services:
  oracledb_exporter:
    image: container-registry.oracle.com/database/observability-exporter:1.5.3
    command: --log.disable=1 --log.level=debug
    volumes:
      - ./custom-metrics.toml:/custom-metrics.toml
      - ./custom-metrics-2.toml:/custom-metrics-2.toml
    environment:
      - TZ=
      - CUSTOM_METRICS=/custom-metrics.toml,/custom-metrics-2.toml
      - DATABASE_MAXIDLECONNS=1
      - DATABASE_MAXOPENCONNS=1
      - DB_USERNAME=
      - DB_PASSWORD=
      - DB_CONNECT_STRING=
      - QUERY_TIMEOUT=10
    ports:
      - "9161:9161"

File custom-metrics.toml

[[metric]]
context = "test_1"
ignoreZeroResult = true
metricsdesc = { value = "Test 1" }
labels = [ "test1_desc" ]
request = "select 'TEST 1' as test1_desc, 11 as value from dual"

File custom-metrics-2.toml

[[metric]]
context = "test_2"
ignoreZeroResult = true
metricsdesc = { value = "Test 2" }
labels = [ "test2_desc" ]
request = "select 'TEST 2' as test2_desc, 22 as value from dual"

Results:
Image

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions