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

Code before:
     * @param {Monitor} monitor Monitor object to monitor
     * @param {Promise<LooseObject<any>[]>} tags Tags of the monitor
     */
    constructor(monitor, tags) {
        this.monitorLabelValues = {
            monitor_name: monitor.name,
            monitor_type: monitor.type,
            monitor_url: monitor.url,
            monitor_hostname: monitor.hostname,
            monitor_port: monitor.port
        };
        Object.values(tags)
            // only label names that were known at first metric creation.
            .filter(tag => Prometheus.monitorLabelNames.includes(tag.name))
            .forEach(tag => {
                this.monitorLabelValues[tag.name] = tag.value;
            });
    }

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

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

        if (heartbeat) {

Review comment (bug):
Function does not use async.
Also the type-signature would be wrong ^^

```suggestion
    update(heartbeat, tlsInfo) {
```

Code after:
     * @param {Monitor} monitor Monitor object to monitor
     * @param {Promise<LooseObject<any>[]>} tags Tags of the monitor
     */
    constructor(monitor, tags) {
        this.monitorLabelValues = {
            monitor_name: monitor.name,
            monitor_type: monitor.type,
            monitor_url: monitor.url,
            monitor_hostname: monitor.hostname,
            monitor_port: monitor.port
        };
        Object.values(tags)
            // only label names that were known at first metric creation.
            .filter(tag => Prometheus.monitorLabelNames.includes(tag.name))
            .forEach(tag => {
                this.monitorLabelValues[tag.name] = tag.value;
            });
    }

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

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

        if (heartbeat) {