percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.16k stars 425 forks source link

debugResult logs on StdErr #770

Open HenrikLindholm86 opened 8 months ago

HenrikLindholm86 commented 8 months ago

Describe the bug The debugResult function in debug.go is logging everything on StdErr instead of StdOut

DebugResult function where it logs on stdErr at the end

func debugResult(log *logrus.Logger, m interface{}) {
    if !log.IsLevelEnabled(logrus.DebugLevel) {
        return
    }

    debugStr, err := json.MarshalIndent(m, "", "  ")
    if err != nil {
        log.Errorf("cannot marshal struct for debug: %s", err)
        return
    }

    // don't use logrus because:
    // 1. It will escape new lines and " making it harder to read and to use
    // 2. It will add timestamp
    // 3. This way is easier to copy/paste to put the info in a ticket
    fmt.Fprintln(os.Stderr, string(debugStr))
}

To Reproduce Start the mongodb_exporter with log level debug arguments we use when starting --discovering-mode --compatible-mode --collect-all --log.level=debug

Expected behavior Output from debugResult should not be logged as error.

Logs Short snippet of the error logs

ERROR 2023-12-28T09:26:21.695767244Z time="2023-12-28T09:26:21Z" level=debug msg="getDiagnosticData result" ERROR 2023-12-28T09:26:21.701590367Z { ERROR 2023-12-28T09:26:21.701639965Z "end": "2023-12-28T09:26:21.002Z", ERROR 2023-12-28T09:26:21.701646738Z "local.oplog.rs.stats": { ERROR 2023-12-28T09:26:21.701651498Z "avgObjSize": 258, ERROR 2023-12-28T09:26:21.701654887Z "capped": true, ERROR 2023-12-28T09:26:21.701658424Z "count": 3971664, ERROR 2023-12-28T09:26:21.701662125Z "end": "2023-12-28T09:26:21.001Z", ERROR 2023-12-28T09:26:21.701666504Z "freeStorageSize": 17514496, ERROR 2023-12-28T09:26:21.701670379Z "indexBuilds": [], ERROR 2023-12-28T09:26:21.701674233Z "indexDetails": {}, ERROR 2023-12-28T09:26:21.701677888Z "indexSizes": {}, ERROR 2023-12-28T09:26:21.701681546Z "max": 0, ERROR 2023-12-28T09:26:21.701685056Z "maxSize": 1038090240, ERROR 2023-12-28T09:26:21.701688572Z "nindexes": 0, ERROR 2023-12-28T09:26:21.701692286Z "ns": "local.oplog.rs", ERROR 2023-12-28T09:26:21.701696076Z "numOrphanDocs": 0, ERROR 2023-12-28T09:26:21.701699915Z "ok": 1, ERROR 2023-12-28T09:26:21.701703615Z "scaleFactor": 1, ERROR 2023-12-28T09:26:21.701707311Z "size": 1026440689, ERROR 2023-12-28T09:26:21.701710843Z "start": "2023-12-28T09:26:21.001Z", ERROR 2023-12-28T09:26:21.701714213Z "storageSize": 197496832, ERROR 2023-12-28T09:26:21.701717622Z "totalIndexSize": 0, ERROR 2023-12-28T09:26:21.701721117Z "totalSize": 197496832, ERROR 2023-12-28T09:26:21.701724374Z "wiredTiger": { ERROR 2023-12-28T09:26:21.701727809Z "LSM": { ERROR 2023-12-28T09:26:21.701731704Z "bloom filter false positives": 0, ERROR 2023-12-28T09:26:21.701735149Z "bloom filter hits": 0, ERROR 2023-12-28T09:26:21.701738687Z "bloom filter misses": 0, ERROR 2023-12-28T09:26:21.701743431Z "bloom filter pages evicted from cache": 0, ERROR 2023-12-28T09:26:21.701746844Z "bloom filter pages read into cache": 0, ERROR 2023-12-28T09:26:21.701755641Z "bloom filters in the LSM tree": 0, ERROR 2023-12-28T09:26:21.701759143Z "chunks in the LSM tree": 0, ERROR 2023-12-28T09:26:21.701778657Z "highest merge generation in the LSM tree": 0, ERROR 2023-12-28T09:26:21.701783163Z "queries that could have benefited from a Bloom filter that did not exist": 0, ERROR 2023-12-28T09:26:21.701786658Z "sleep for LSM checkpoint throttle": 0, ERROR 2023-12-28T09:26:21.701790175Z "sleep for LSM merge throttle": 0, ERROR 2023-12-28T09:26:21.701793741Z "total size of bloom filters": 0 ERROR 2023-12-28T09:26:21.701797100Z }, ERROR 2023-12-28T09:26:21.701800637Z "block-manager": { ... etc

Environment