From owner-svn-src-head@freebsd.org Sat Jul 29 08:35:08 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 74AAADBE135; Sat, 29 Jul 2017 08:35:08 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E50963E8B; Sat, 29 Jul 2017 08:35:08 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6T8Z7Ui053378; Sat, 29 Jul 2017 08:35:07 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6T8Z7s2053377; Sat, 29 Jul 2017 08:35:07 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201707290835.v6T8Z7s2053377@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Sat, 29 Jul 2017 08:35:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321678 - head/usr.sbin/prometheus_sysctl_exporter X-SVN-Group: head X-SVN-Commit-Author: ed X-SVN-Commit-Paths: head/usr.sbin/prometheus_sysctl_exporter X-SVN-Commit-Revision: 321678 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jul 2017 08:35:08 -0000 Author: ed Date: Sat Jul 29 08:35:07 2017 New Revision: 321678 URL: https://svnweb.freebsd.org/changeset/base/321678 Log: Be a bit more liberal about sysctl naming. On the systems on which I tested this exporter, I never ran into metrics that were named in such a way that they couldn't be exported to Prometheus metrics directly. Now it turns out that on systems with NUMA, the sysctl tree contains metrics named dev.${driver}.${index}.%domain. For these metrics, the % in the name is problematic, as Prometheus doesn't allow this symbol to be used. Remove the assertions that were originally put in place to prevent the exporter from generating malformed output and add code to deal with it accordingly. For metric names, convert any unsupported character to an underscore. For label values, perform string escaping. PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221035 Reported by: lifanov@ Modified: head/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c Modified: head/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c ============================================================================== --- head/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c Sat Jul 29 08:24:51 2017 (r321677) +++ head/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c Sat Jul 29 08:35:07 2017 (r321678) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Nuxi, https://nuxi.nl/ + * Copyright (c) 2016-2017 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -384,11 +385,12 @@ oidname_print(const struct oidname *on, const struct o label = on->labels; for (i = 0; i < on->oid.len; ++i) { if (*label == '\0') { - assert(name[strspn(name, - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789_")] == '\0'); - fprintf(fp, "_%s", name); + fputc('_', fp); + while (*name != '\0') { + /* Map unsupported characters to underscores. */ + fputc(isalnum(*name) ? *name : '_', fp); + ++name; + } } name += strlen(name) + 1; label += strlen(label) + 1; @@ -404,15 +406,18 @@ oidname_print(const struct oidname *on, const struct o separator = '{'; for (i = 0; i < on->oid.len; ++i) { if (*label != '\0') { - assert(name[strspn(name, - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789_-")] == '\0'); assert(label[strspn(label, "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789_")] == '\0'); - fprintf(fp, "%c%s=\"%s\"", separator, label, name); + fprintf(fp, "%c%s=\"", separator, label); + while (*name != '\0') { + /* Escape backslashes and double quotes. */ + if (*name == '\\' || *name == '"') + fputc('\\', fp); + fputc(*name++, fp); + } + fputc('"', fp); separator = ','; } name += strlen(name) + 1;