Skip to content

Commit e90204a

Browse files
committed
pmlogger, libpcp: fix handling of dynamic instance domain labels
Resolves Red Hat bug RHEL-67227 Resolves #2115 Resolves performancecopilot/grafana-pcp#203
1 parent 8f04d92 commit e90204a

File tree

6 files changed

+141
-3
lines changed

6 files changed

+141
-3
lines changed

qa/1368.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ Metric Labels in the Log ...
3434
[0] name(2,3) : value(7,3) [instances]
3535
InDom 29.2[900] labels (11 bytes): {"bin":900}
3636
[0] name(2,3) : value(7,3) [instances]
37+
InDom 29.2[100] labels (11 bytes): {"bin":100}
38+
[0] name(2,3) : value(7,3) [instances]
39+
InDom 29.2[200] labels (11 bytes): {"bin":200}
40+
[0] name(2,3) : value(7,3) [instances]
41+
InDom 29.2[300] labels (11 bytes): {"bin":300}
42+
[0] name(2,3) : value(7,3) [instances]
43+
InDom 29.2[400] labels (11 bytes): {"bin":400}
44+
[0] name(2,3) : value(7,3) [instances]
45+
InDom 29.2[500] labels (11 bytes): {"bin":500}
46+
[0] name(2,3) : value(7,3) [instances]
47+
InDom 29.2[600] labels (11 bytes): {"bin":600}
48+
[0] name(2,3) : value(7,3) [instances]
49+
InDom 29.2[700] labels (11 bytes): {"bin":700}
50+
[0] name(2,3) : value(7,3) [instances]
51+
InDom 29.2[800] labels (11 bytes): {"bin":800}
52+
[0] name(2,3) : value(7,3) [instances]
53+
InDom 29.2[900] labels (11 bytes): {"bin":900}
54+
[0] name(2,3) : value(7,3) [instances]
3755

3856
=== Dump help text
3957

qa/1747

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
# PCP QA Test No. 1747
3+
# Exercise pmlogger labels handling for dynamic instance domains.
4+
#
5+
# Copyright (c) 2025 Red Hat. All Rights Reserved.
6+
#
7+
8+
seq=`basename $0`
9+
echo "QA output created by $seq"
10+
11+
# get standard environment, filters and checks
12+
. ./common.product
13+
. ./common.filter
14+
. ./common.check
15+
16+
[ -d $PCP_PMDAS_DIR/simple ] || _notrun "simple PMDA directory is not installed"
17+
18+
_cleanup()
19+
{
20+
cd $here
21+
if $need_restore
22+
then
23+
need_restore=false
24+
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
25+
_restore_config $PCP_ETC_DIR/pcp/labels
26+
_restore_config $PCP_PMDAS_DIR/simple/simple.conf
27+
_sighup_pmcd
28+
fi
29+
$sudo rm -rf $tmp $tmp.*
30+
}
31+
32+
userid=`id -u`
33+
groupid=`id -g`
34+
hostname=`hostname`
35+
machineid=`_machine_id`
36+
domainname=`_domain_name`
37+
rm -f $seq_full
38+
39+
status=0 # success is the default!
40+
need_restore=true
41+
trap "_cleanup; exit \$status" 0 1 2 3 15
42+
43+
_filter_labels()
44+
{
45+
sed \
46+
-e "s/.domainname.:.${domainname}./\"domainname\":\"DOMAIN\"/g" \
47+
-e "s/.machineid.:.${machineid}./\"machineid\":\"MACHINE\"/g" \
48+
-e "s/.hostname.:.${hostname}./\"hostname\":\"HOSTNAME\"/g" \
49+
-e "s/.groupid.:$groupid/\"groupid\":GID/g" \
50+
-e "s/.userid.:$userid/\"userid\":UID/g" \
51+
#end
52+
}
53+
54+
# real QA test starts here
55+
_save_config $PCP_ETC_DIR/pcp/labels
56+
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
57+
_sighup_pmcd || _exit 1
58+
59+
_save_config "$PCP_PMDAS_DIR/simple/simple.conf"
60+
conf="sec"
61+
echo $conf > "$tmp.simple.conf"
62+
$sudo cp "$tmp.simple.conf" "$PCP_PMDAS_DIR/simple/simple.conf"
63+
64+
cat > $tmp.config <<EOF
65+
log mandatory on default { simple }
66+
EOF
67+
68+
pmlogger -c $tmp.config -l $tmp.log -t 1sec -T 8sec $tmp.archive &
69+
pid=$!
70+
71+
# delay for pmlogger startup
72+
pmsleep 0.5
73+
74+
# inject changes to instances and labels
75+
for insts in "sec,min" "sec,min,hour"
76+
do
77+
pmsleep 1.5
78+
echo $insts > "$tmp.simple.conf"
79+
$sudo cp "$tmp.simple.conf" "$PCP_PMDAS_DIR/simple/simple.conf"
80+
done
81+
82+
# ensure pmlogger has completed (from use of the -T option)
83+
wait $pid
84+
cat $tmp.log | tee $seq_full | _filter_pmlogger_log
85+
86+
# reading from the archive end, expect labels for three instances
87+
pmdumplog -ae $tmp.archive >> $seq_full
88+
#pminfo -fl simple.now >> $seq_full
89+
pminfo -l -O 6sec -a $tmp.archive simple.now | _filter_labels
90+
91+
# success, all done
92+
exit

qa/1747.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
QA output created by 1747
2+
Log for pmlogger on HOST started DATE
3+
4+
[DATE] pmlogger(PID) Info: Start
5+
Config parsed
6+
Starting logger for host "HOST"
7+
Archive basename: ARCHIVE
8+
[DATE] pmlogger(PID) Info: pmlogger: End of run time, exiting
9+
10+
Log finished DATE
11+
12+
simple.now
13+
labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","unitsystem":"SI","userid":UID}
14+
inst [0 or "sec"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"sec","unitsystem":"SI","userid":UID}
15+
inst [1 or "min"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"min","unitsystem":"SI","userid":UID}
16+
inst [2 or "hour"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"hour","unitsystem":"SI","userid":UID}

qa/group

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ pmcd.pdu
21302130
1727 pmproxy libpcp_web pmda.openmetrics local
21312131
1740 pmda.proc local
21322132
1745 pmlogger libpcp pmval local pmda.sample pmda.simple pmlogdump
2133+
1747 pmlogger labels local
21332134
1748 atop local
21342135
1753 fetch valgrind local
21352136
1763 pmlogctl local

src/libpcp/src/logmeta.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,24 @@ samelabelset(const pmLabelSet *set1, const pmLabelSet *set2)
409409
if (n2 == set2->nlabels)
410410
return 0; /* not the same */
411411
}
412-
412+
413413
/* All of the labels in set1 are in set2 with the same values. */
414414
return 1; /* the same */
415415
}
416416

417417
/*
418418
* Discard any label sets within idp which are also within idp_next.
419+
* Instance labels are a special case which cannot be reduced due to
420+
* the potentially dynamic nature of the associated instance domain.
419421
*/
420422
static void
421423
discard_dup_labelsets(__pmLogLabelSet *idp, const __pmLogLabelSet *idp_next)
422424
{
423425
int i, j;
424426

427+
if (idp->type & PM_LABEL_INSTANCES)
428+
return;
429+
425430
for (i = 0; i < idp->nsets; ++i) {
426431
for (j = 0; j < idp_next->nsets; ++j) {
427432
if (samelabelset(&idp->labelsets[i], &idp_next->labelsets[j])) {

src/pmlogger/src/callback.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,14 @@ manageLabels(pmDesc *desc, const __pmTimestamp *tsp, int only_instances)
388388
else
389389
ident = PM_IN_NULL;
390390

391-
/* Lookup returns >= 0 when the key exists */
392-
if (__pmLogLookupLabel(&archctl, type, ident, &label, tsp) >= 0)
391+
/*
392+
* Lookup returns >= 0 when the key exists
393+
*
394+
* In the instance-domain-is-changing scenario we can skip this
395+
* as we must always log label metadata in that special case.
396+
*/
397+
if (!only_instances &&
398+
__pmLogLookupLabel(&archctl, type, ident, &label, tsp) >= 0)
393399
continue;
394400

395401
if ((sts = putlabels(type, ident, tsp)) < 0)

0 commit comments

Comments
 (0)