File: 1890

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (139 lines) | stat: -rwxr-xr-x 3,861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# PCP QA Test No. 1890
# Test duplicate instname labels in /metrics webapi when a context
# level label such as "hostname" is explicitly specified.
# Test invalid OpenTelemetry metric names also.
#
# Copyright (c) 2025 Red Hat.  All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.opentelemetry

_check_series   # ensure pmproxy makes a REST API available
_pmdaopentelemetry_check || _notrun "opentelemetry pmda not installed"
which curl >/dev/null 2>&1 || _notrun curl not installed

status=1        # failure is the default!

# only stop pmproxy if it was not running before the QA test starts
if [ -n "`_get_pids_by_name pmproxy`" ]
then
    pmproxy_was_running=true
else
    pmproxy_was_running=false
    if ! _service pmproxy start >>$seq_full 2>&1; then _exit 1; fi
fi
echo "pmproxy_was_running=$pmproxy_was_running" >>$seq_full

_cleanup()
{
    cd $here
    if $need_restore
    then
        $sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
        _restore_config $PCP_ETC_DIR/pcp/labels
        $pmproxy_was_running || _service pmproxy stop >>$seq_full 2>&1
        need_restore=false
    fi
    _pmdaopentelemetry_cleanup
    $sudo rm -rf $tmp $tmp.*
}

_filter_opentelemetry_labels()
{
    sed \
    -e "s;$PCP_PMDAS_DIR;PCP_PMDAS_DIR;g" \
    -e 's;machineid="[a-z0-9]*";machineid=MACHINEID;g' \
    -e 's;url="[^"]*";url=URL;g' \
    -e 's;hostname="[a-zA-Z0-9_\.\-]*";hostname=HOSTNAME;g' \
    -e 's;hostname:[a-zA-Z0-9_\.\-]*";hostname:HOSTNAME";g' \
    -e 's;domainname="[a-zA-Z0-9_\.\-]*";domainname=DOMAINNAME;g' \
    -e 's;144\.[0-9]*\.[0-9]*;NUMERIC_PMID;g' \
    -e 's;144\.[0-9]*;NUMERIC_INDOM;g' \
    # end
}

_reorder_labels()
{
    awk '
    /^[^#].*{.*=.*}/ {
        match($0, /^([^{]+){([^}]+)}(.*)$/, a)
        metric = a[1]
        labels_str = a[2]
        rest = a[3]
        
        delete labels
        n = split(labels_str, pairs, ",")
        for (i = 1; i <= n; i++) {
            match(pairs[i], /^([^=]+)=(.+)$/, kv)
            key = kv[1]
            value = kv[2]
            labels[key] = value
        }
        
        order = "url agent hostname domainname machineid source my_sum_attribute"
        split(order, order_arr, " ")
        
        output = metric "{"
        first = 1
        for (i = 1; i <= length(order_arr); i++) {
            key = order_arr[i]
            if (key in labels) {
                if (!first) output = output ","
                output = output key "=" labels[key]
                first = 0
            }
        }
        output = output "}" rest
        print output
        next
    }
    {print}
    '
}

need_restore=true
_prepare_pmda opentelemetry
trap "_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

# real QA test starts here
_pmdaopentelemetry_save_config
_save_config $PCP_ETC_DIR/pcp/labels
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*

# set up a scripted config
MYHOST=`hostname`

file_path=$here/opentelemetry/samples/duplicate.txt
urlbase=`basename "$file_path" .txt | tr .- _`
echo 'file:///'$file_path > $tmp.tmp
$sudo cp $tmp.tmp $PCP_PMDAS_DIR/opentelemetry/config.d/$urlbase.url

_pmdaopentelemetry_install
if ! _pmdaopentelemetry_wait_for_metric opentelemetry.control.calls
then
    status=1
    exit
fi

echo; echo === /metrics webapi listing. The instname label should appear only once.
curl -Gs 'http://localhost:44322/metrics?names=opentelemetry.duplicate.somemetric' \
| _filter_opentelemetry_labels | _reorder_labels

echo; echo === verify metric name validity using pminfo
pminfo -v opentelemetry

# squash errors for a clean uninstall
$sudo rm $PCP_PMDAS_DIR/opentelemetry/config.d/duplicate.url
# capture opentelemetry log for posterity
cat $PCP_LOG_DIR/pmcd/opentelemetry.log >> $seq_full

_pmdaopentelemetry_remove

# success, all done
status=0
exit