Repository: louislam/uptime-kuma
File: server/prometheus.js (JavaScript)

Code before:
                mappedTags[sanitizedTag] = [];
            }

            let tagValue = Prometheus.sanitizeForPrometheus(tag.value || "");
            if (tagValue !== "") {
                mappedTags[sanitizedTag].push(tagValue);
            }

            mappedTags[sanitizedTag] = mappedTags[sanitizedTag].sort();
        });

        // Order the tags alphabetically
        return Object.keys(mappedTags)
            .sort(this.sortTags)
            .reduce((obj, key) => {
                obj[key] = mappedTags[key];
                return obj;
            }, {});
    }

    /**
     * Update the metrics page
     * @typedef {import("./uptime-calculator").UptimeDataResult} UptimeDataResult
     * @param {object} heartbeat Heartbeat details
     * @param {object} tlsInfo TLS details
     * @param {{data24h: UptimeDataResult, data30d: UptimeDataResult, data1y:UptimeDataResult}} uptime
     * @returns {void}
     */
    update(heartbeat, tlsInfo, uptime) {
        if (typeof tlsInfo !== "undefined") {
            try {
                let isValid;
                if (tlsInfo.valid === true) {
                    isValid = 1;
                } else {
                    isValid = 0;
                }
                monitorCertIsValid.set(this.monitorLabelValues, isValid);
            } catch (e) {
                log.error("prometheus", "Caught error", e);
            }

            try {
                if (tlsInfo.certInfo != null) {
                    monitorCertDaysRemaining.set(this.monitorLabelValues, tlsInfo.certInfo.daysRemaining);
                }
            } catch (e) {
                log.error("prometheus", "Caught error", e);
            }
        }


Review comment (suggestion):
```suggestion
     * @param {{data24h: UptimeDataResult, data30d: UptimeDataResult, data1y:UptimeDataResult} | null} uptime the uptime and average response rate over a variety of fixed windows
```

Code after:
                mappedTags[sanitizedTag] = [];
            }

            let tagValue = Prometheus.sanitizeForPrometheus(tag.value || "");
            if (tagValue !== "") {
                mappedTags[sanitizedTag].push(tagValue);
            }

            mappedTags[sanitizedTag] = mappedTags[sanitizedTag].sort();
        });

        // Order the tags alphabetically
        return Object.keys(mappedTags)
            .sort(this.sortTags)
            .reduce((obj, key) => {
                obj[key] = mappedTags[key];
                return obj;
            }, {});
    }

    /**
     * Update the metrics page
     * @typedef {import("./uptime-calculator").UptimeDataResult} UptimeDataResult
     * @param {object} heartbeat Heartbeat details
     * @param {object} tlsInfo TLS details
     * @param {{data24h: UptimeDataResult, data30d: UptimeDataResult, data1y:UptimeDataResult} | null} uptime the uptime and average response rate over a variety of fixed windows
     * @returns {void}
     */
    update(heartbeat, tlsInfo, uptime) {
        if (typeof tlsInfo !== "undefined") {
            try {
                let isValid;
                if (tlsInfo.valid === true) {
                    isValid = 1;
                } else {
                    isValid = 0;
                }
                monitorCertIsValid.set(this.monitorLabelValues, isValid);
            } catch (e) {
                log.error("prometheus", "Caught error", e);
            }

            try {
                if (tlsInfo.certInfo != null) {
                    monitorCertDaysRemaining.set(this.monitorLabelValues, tlsInfo.certInfo.daysRemaining);
                }
            } catch (e) {
                log.error("prometheus", "Caught error", e);
            }
        }