From nobody Fri Sep 04 18:49:25 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hc59L2Z2qz6r5V6 for ; Fri, 04 Sep 2026 18:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hc59L0y4Qz3CBM for ; Fri, 04 Sep 2026 18:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788547766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0NY5GPPcyHAPIYj1IWzNks6p03GBytw3Eteskd7qxto=; b=plucwQn7pewvsVBroN14E3q7bATE+anU8AmsBoGSkGSrWuXUOZZQEyo9SIv0xX6rlvizfX aJABDx7gEDKfTRegwiqV2EgfGvQK9AZCwUvhCkldZbSjjtGrgPEinFkLu5vg85X9UHMT34 LahpWPE8mXqcZPHjB+C8rFrS4eA9NRsvM/EWObI2ObOmMsMOOZXGfxCN2J7KOZgQdD+kG7 3ZQhBSf/SE++T3/qBT21xEb1LN+J2Cb55/aoC3VgND+cLCJu2VfqSJqB9Slb8S9JpRBfWV r0VHVbJQhd+ylOq6KeGkfTlgha9TtlfRM4KYQamHhUACjo/1ek1HHExXYDqtFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788547766; a=rsa-sha256; cv=none; b=UK4yBgl0h3k1E02Iulf3F9Xybl9X8ODRT/OGGrCauOAuMx6XY0Ci7S4ywb5QJaWM8ijDzs 08B2Cpk7UmLvugr/aEEv/mxuKH0+nmoEnoCMnqnpmy0njomyd47GF1XQImkIJU2O39qBqm ScIK8z5oLtSZn3xXajHSp4POiT4gFYQB+7a3JZvdkrFgPgZnaCg5iVeJHHH6F+tVIjN4RZ iv5T6+NJMDwJUrJnsPUAAsmfTB0wvbNMdSLvljodB7zHzKGHiMVJD40zyC4pFoImL/fINF VnC5yCuFSsGEq3VH+CRVl3FBpReKoXpA+ZL2jizivnpr0apRQJGPtpKy2RMDWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788547766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0NY5GPPcyHAPIYj1IWzNks6p03GBytw3Eteskd7qxto=; b=v+3HJsViE9KznkVwn0SxEosW2mtgXv7K6OBhqQ0Ahg9ydUHZc4eNu2WHrYJefkn6Glh/zH CezE52XPjz/DybKxhZwncfTbgqD6smUYhJJQCpUjhMGlZlIJCMLsPYU8vbRMZcXlS5vS52 KNHoUNWPxRbEDem1+Nv0OKNXb24Dv6k0/ZVqvFRiXriB+9kmi3aXTFxAIJtMOBnsxFuvyM aVPNuGMJWqA/vc0FXAMCtJWCEOWLqqdY5E9IQwdGRNodHC5T2PFHdAKtedWLXkPxAbkgNI Hm3WgBBOcgs4eoBJB96heRc4JPr0HiEYAZDdUA7LWYg3HEJkUCgDQmLmtKnXaw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hc59K683Gz1BJp for ; Fri, 04 Sep 2026 18:49:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2210c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 04 Sep 2026 18:49:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 1cfebc97445c - stable/14 - prometheus_sysctl_exporter: don't abort on bad labels List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1cfebc97445cdc72e1a01236c92732042205146e Auto-Submitted: auto-generated Date: Fri, 04 Sep 2026 18:49:25 +0000 Message-Id: <6a9b12b5.2210c.3f5c9256@gitrepo.freebsd.org> The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=1cfebc97445cdc72e1a01236c92732042205146e commit 1cfebc97445cdc72e1a01236c92732042205146e Author: Kyle Evans AuthorDate: 2026-08-07 01:54:04 +0000 Commit: Kyle Evans CommitDate: 2026-09-04 15:39:52 +0000 prometheus_sysctl_exporter: don't abort on bad labels We can probaby consider these kernel bugs, in which case asserting is not the most helpful thing we can do. Let's emit the necessary details to stderr and exit non-zero to aid debugging these without completely blocking the ability to export all of the well-formed metrics. Reviewed by: rew (cherry picked from commit 4f42ec2f38ee4a4eba8f3298e7968f0523f87aa0) --- .../prometheus_sysctl_exporter.8 | 7 ++- .../prometheus_sysctl_exporter.c | 54 ++++++++++++++++------ 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8 b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8 index da09f43c1cf9..57e29cdd5b86 100644 --- a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8 +++ b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8 @@ -20,7 +20,7 @@ .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.Dd October 7, 2021 +.Dd August 6, 2026 .Dt PROMETHEUS_SYSCTL_EXPORTER 8 .Os .Sh NAME @@ -95,6 +95,11 @@ is to be a regular expression as described in The provided regular expression is tested against the Prometheus metric name. .El +.Sh EXIT STATUS +The +.Nm +utility exits 0 on success, and >0 if an error is encountered while processing +metric labels. .Sh SEE ALSO .Xr cron 8 , .Xr inetd 8 , diff --git a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c index 09c8051786d3..3887183d457b 100644 --- a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c +++ b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c @@ -372,8 +372,14 @@ oid_get_name(const struct oid *o, struct oidname *on) on->oid = *o; } -/* Populates the name and labels of an OID to a buffer. */ -static void +/* + * Populates the name and labels of an OID to a buffer. If an invalid label is + * encountered, we'll skip the metric entirely to avoid outputting ambiguous + * metrics and emit the relevant details to stderr for correction. + * + * Returns true if the metric is valid, false otherwise. + */ +static bool oid_get_metric(const struct oidname *on, const struct oidformat *of, char *metric, size_t mlen) { @@ -410,10 +416,15 @@ oid_get_metric(const struct oidname *on, const struct oidformat *of, separator = '{'; for (i = 0; i < on->oid.len; ++i) { if (*label != '\0') { - assert(label[strspn(label, + if (label[strspn(label, "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789_")] == '\0'); + "0123456789_")] != '\0') { + warnx("bad label for metric '%s': %s", + metric, label); + return (false); + } + snprintf(buf, sizeof(buf), "%c%s=\"", separator, label); strlcat(metric, buf, mlen); while (*name != '\0') { @@ -431,6 +442,8 @@ oid_get_metric(const struct oidname *on, const struct oidformat *of, } if (separator != '{') strlcat(metric, "}", mlen); + + return (true); } /* Returns whether the OID name has any labels associated to it. */ @@ -487,7 +500,14 @@ oiddescription_print(const struct oiddescription *od, FILE *fp) fprintf(fp, "%s", od->description); } -static void +/* + * Print the given oid, subject to include/exclude rules. Returns true if the + * oid was skipped or printed, false if an error was encountered. + * + * For the purposes of the exporter, we don't consider it an error to be unable + * to fetch format/value information. + */ +static bool oid_print(const struct oid *o, struct oidname *on, bool print_description, bool exclude, bool include, FILE *fp) { @@ -498,16 +518,17 @@ oid_print(const struct oid *o, struct oidname *on, bool print_description, bool has_desc; if (!oid_get_format(o, &of) || !oid_get_value(o, &of, &ov)) - return; + return (true); oid_get_name(o, on); - oid_get_metric(on, &of, metric, sizeof(metric)); + if (!oid_get_metric(on, &of, metric, sizeof(metric))) + return (false); if (exclude && regexec(&exc_regex, metric, 0, NULL, 0) == 0) - return; + return (true); if (include && regexec(&inc_regex, metric, 0, NULL, 0) != 0) - return; + return (true); has_desc = oid_get_description(o, &od); /* @@ -515,7 +536,7 @@ oid_print(const struct oid *o, struct oidname *on, bool print_description, * redundant ZFS sysctls whose names alias with the non-legacy versions. */ if (has_desc && strnstr(od.description, "(LEGACY)", BUFSIZ) != NULL) - return; + return (true); /* * Print the line with the description. Prometheus expects a * single unique description for every metric, which cannot be @@ -535,6 +556,7 @@ oid_print(const struct oid *o, struct oidname *on, bool print_description, fputc(' ', fp); oidvalue_print(&ov, fp); fputc('\n', fp); + return (true); } /* Gzip compresses a buffer of memory. */ @@ -574,7 +596,7 @@ main(int argc, char *argv[]) char *http_buf; FILE *fp; size_t http_buflen; - int ch, error; + int ch, error, failed = 0; bool exclude, include, gzip_mode, http_mode, print_descriptions; char errbuf[BUFSIZ]; @@ -632,7 +654,9 @@ main(int argc, char *argv[]) /* Print all OIDs. */ oid_get_root(&o); do { - oid_print(&o, &on, print_descriptions, exclude, include, fp); + if (!oid_print(&o, &on, print_descriptions, exclude, + include, fp)) + failed++; } while (oid_get_next(&o, &o)); } else { int i; @@ -652,7 +676,9 @@ main(int argc, char *argv[]) } o = root; do { - oid_print(&o, &on, print_descriptions, exclude, include, fp); + if (!oid_print(&o, &on, print_descriptions, + exclude, include, fp)) + failed++; } while (oid_get_next(&o, &o) && oid_is_beneath(&o, &root)); } @@ -703,5 +729,5 @@ main(int argc, char *argv[]) } } } - return (0); + return (failed != 0 ? 1 : 0); }