From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 533843857C6D for ; Fri, 1 Oct 2021 14:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 533843857C6D Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102--gFXdt0rPI6xAxJVrS_d4Q-1; Fri, 01 Oct 2021 10:06:14 -0400 X-MC-Unique: -gFXdt0rPI6xAxJVrS_d4Q-1 Received: by mail-ed1-f71.google.com with SMTP id c8-20020a50d648000000b003daa53c7518so10204623edj.21 for ; Fri, 01 Oct 2021 07:06:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=cZKkubY0OrJ7DAAMBQJrp4LydsHGtoHULsRstTeU9Hs=; b=xqD7gVXB1n/WjVZlH6skvkevTx9nHJXejYGQTRzSAXgardsk9XKnYkNvPjvk12sbin O12+L5Y7w/hG3nE4wP7LiqC8P13Hf2GtLBk6alvTWiXCkV/folsHMVzCM56IXQ3XmYlp kDU8E5iDfbMsYVTo+QXO7aYNcAfjfp6X1WXIYht0yEqkeHloY/8vcLh/bGqK+3DL+Axp I5VYEEew16LXUgFlFA9ez+t8h+fGtU0HjCAQDbzJaz/+g3pLAFiMdJElMKnkCca2s5nP 3EUtS/CYSsUP+BHkS0Oa9515tAa0ZIeomRjdTq1WxsFMbuzdiyCGIjD8m7yBnNnNYBnj W2Rw== X-Gm-Message-State: AOAM530y+N/cZvBLZFCzL/b5zJE35ZopRTAUwVlPtm0GGcTB5sZyTWWp 2NmdamqYboj3uZHt71CXG9pIrwlR0JAuQAy+CTT4wF6Aba4eZ9774s2V3DQ6mlUekH4KvIMMwVr UlKnLgLMIQwTFck+qsEbzcCMuRnKVmQhwmJHcxHy93w== X-Received: by 2002:a50:ccc4:: with SMTP id b4mr14656113edj.83.1633097172965; Fri, 01 Oct 2021 07:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNG0a/ckSci3BwuFs5/hy8320zwQsEfeIkp5XKl2ZXZe5CKZJ3r2UjaOAh9sI0bvxfHobD/7W1Hw0U0JWbR3Q= X-Received: by 2002:a50:ccc4:: with SMTP id b4mr14656087edj.83.1633097172674; Fri, 01 Oct 2021 07:06:12 -0700 (PDT) MIME-Version: 1.0 From: Di Chen Date: Fri, 1 Oct 2021 22:05:59 +0800 Message-ID: Subject: [PATCH] debuginfod: PR28242 - extend server http-response metrics To: elfutils-devel@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_BADIPHTTP, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Oct 2021 14:06:24 -0000 >From a574dfaf5d5636cbb7159a0118eb30e2c4aaa301 Mon Sep 17 00:00:00 2001 From: Di Chen Date: Fri, 1 Oct 2021 22:03:41 +0800 Subject: [PATCH] debuginfod: PR28242 - extend server http-response metrics This patch aims to extend http_responses_* metrics with another label "type" by getting the extra artifact-type content added as a new key=value tag. https://sourceware.org/bugzilla/show_bug.cgi?id=28242 Signed-off-by: Di Chen --- debuginfod/debuginfod.cxx | 55 ++++++++++++++++++++------ tests/run-debuginfod-000-permission.sh | 12 +++--- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 2b9a1c41..6a469b21 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -2080,6 +2080,33 @@ add_metric(const string& metric, // and more for higher arity labels if needed +static void +inc_metric(const string& metric, + const string& lname, const string& lvalue, + const string& rname, const string& rvalue) +{ + string key = (metric + "{" + metric_label(lname, lvalue) + ","); + if (rvalue != "debuginfo" && rvalue != "executable" && rvalue != "source") + key = (key + metric_label(rname, "") + "}"); + else + key = (key + metric_label(rname, rvalue) + "}"); + unique_lock lock(metrics_lock); + metrics[key] ++; +} +static void +add_metric(const string& metric, + const string& lname, const string& lvalue, + const string& rname, const string& rvalue, + double value) +{ + string key = (metric + "{" + metric_label(lname, lvalue) + ","); + if (rvalue != "debuginfo" && rvalue != "executable" && rvalue != "source") + key = (key + metric_label(rname, "") + "}"); + else + key = (key + metric_label(rname, rvalue) + "}"); + unique_lock lock(metrics_lock); + metrics[key] += value; +} static struct MHD_Response* handle_metrics (off_t* size) @@ -2165,6 +2192,7 @@ handler_cb (void * /*cls*/, struct timespec ts_start, ts_end; clock_gettime (CLOCK_MONOTONIC, &ts_start); double afteryou = 0.0; + string artifacttype, suffix; try { @@ -2203,7 +2231,7 @@ handler_cb (void * /*cls*/, string buildid = url_copy.substr(slash1+1, slash2-slash1-1); size_t slash3 = url_copy.find('/', slash2+1); - string artifacttype, suffix; + if (slash3 == string::npos) { artifacttype = url_copy.substr(slash2+1); @@ -2275,17 +2303,20 @@ handler_cb (void * /*cls*/, // related prometheus metrics string http_code_str = to_string(http_code); if (http_size >= 0) - add_metric("http_responses_transfer_bytes_sum","code",http_code_str, - http_size); - inc_metric("http_responses_transfer_bytes_count","code",http_code_str); - - add_metric("http_responses_duration_milliseconds_sum","code",http_code_str, - deltas*1000); // prometheus prefers _seconds and floating point - inc_metric("http_responses_duration_milliseconds_count","code",http_code_str); - - add_metric("http_responses_after_you_milliseconds_sum","code",http_code_str, - afteryou*1000); - inc_metric("http_responses_after_you_milliseconds_count","code",http_code_str); + add_metric("http_responses_transfer_bytes_sum", + "code", http_code_str, "type", artifacttype, http_size); + inc_metric("http_responses_transfer_bytes_count", + "code", http_code_str, "type", artifacttype); + + add_metric("http_responses_duration_milliseconds_sum", + "code", http_code_str, "type", artifacttype, deltas*1000); // prometheus prefers _seconds and floating point + inc_metric("http_responses_duration_milliseconds_count", + "code", http_code_str, "type", artifacttype); + + add_metric("http_responses_after_you_milliseconds_sum", + "code", http_code_str, "type", artifacttype, afteryou*1000); + inc_metric("http_responses_after_you_milliseconds_count", + "code", http_code_str, "type", artifacttype); return rc; } diff --git a/tests/run-debuginfod-000-permission.sh b/tests/run-debuginfod-000-permission.sh index 1e92bdb8..afa7e931 100755 --- a/tests/run-debuginfod-000-permission.sh +++ b/tests/run-debuginfod-000-permission.sh @@ -61,22 +61,22 @@ if [ -r $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then err fi -bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` +bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'` testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true -bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` +bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'` if [ "$bytecount_before" != "$bytecount_after" ]; then - echo "http_responses_transfer_bytes_count{code="404"} has changed." + echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} has changed." err fi # set cache_miss_s to 0 and sleep 1 to make the mtime expire. echo 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s sleep 1 -bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` +bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'` testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true -bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` +bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'` if [ "$bytecount_before" == "$bytecount_after" ]; then - echo "http_responses_transfer_bytes_count{code="404"} should be incremented." + echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} should be incremented." err fi -- 2.31.1