Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pmlogger, libpcp: fix handling of dynamic instance domain labels #2127

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions qa/1368.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ Metric Labels in the Log ...
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[900] labels (11 bytes): {"bin":900}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[100] labels (11 bytes): {"bin":100}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[200] labels (11 bytes): {"bin":200}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[300] labels (11 bytes): {"bin":300}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[400] labels (11 bytes): {"bin":400}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[500] labels (11 bytes): {"bin":500}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[600] labels (11 bytes): {"bin":600}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[700] labels (11 bytes): {"bin":700}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[800] labels (11 bytes): {"bin":800}
[0] name(2,3) : value(7,3) [instances]
InDom 29.2[900] labels (11 bytes): {"bin":900}
[0] name(2,3) : value(7,3) [instances]

=== Dump help text

Expand Down
92 changes: 92 additions & 0 deletions qa/1747
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh
# PCP QA Test No. 1747
# Exercise pmlogger labels handling for dynamic instance domains.
#
# Copyright (c) 2025 Red Hat. All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

[ -d $PCP_PMDAS_DIR/simple ] || _notrun "simple PMDA directory is not installed"

_cleanup()
{
cd $here
if $need_restore
then
need_restore=false
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
_restore_config $PCP_ETC_DIR/pcp/labels
_restore_config $PCP_PMDAS_DIR/simple/simple.conf
_sighup_pmcd
fi
$sudo rm -rf $tmp $tmp.*
}

userid=`id -u`
groupid=`id -g`
hostname=`hostname`
machineid=`_machine_id`
domainname=`_domain_name`
rm -f $seq_full

status=0 # success is the default!
need_restore=true
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter_labels()
{
sed \
-e "s/.domainname.:.${domainname}./\"domainname\":\"DOMAIN\"/g" \
-e "s/.machineid.:.${machineid}./\"machineid\":\"MACHINE\"/g" \
-e "s/.hostname.:.${hostname}./\"hostname\":\"HOSTNAME\"/g" \
-e "s/.groupid.:$groupid/\"groupid\":GID/g" \
-e "s/.userid.:$userid/\"userid\":UID/g" \
#end
}

# real QA test starts here
_save_config $PCP_ETC_DIR/pcp/labels
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
_sighup_pmcd || _exit 1

_save_config "$PCP_PMDAS_DIR/simple/simple.conf"
conf="sec"
echo $conf > "$tmp.simple.conf"
$sudo cp "$tmp.simple.conf" "$PCP_PMDAS_DIR/simple/simple.conf"

cat > $tmp.config <<EOF
log mandatory on default { simple }
EOF

pmlogger -c $tmp.config -l $tmp.log -t 1sec -T 8sec $tmp.archive &
pid=$!

# delay for pmlogger startup
pmsleep 0.5

# inject changes to instances and labels
for insts in "sec,min" "sec,min,hour"
do
pmsleep 1.5
echo $insts > "$tmp.simple.conf"
$sudo cp "$tmp.simple.conf" "$PCP_PMDAS_DIR/simple/simple.conf"
done

# ensure pmlogger has completed (from use of the -T option)
wait $pid
cat $tmp.log | tee $seq_full | _filter_pmlogger_log

# reading from the archive end, expect labels for three instances
pmdumplog -ae $tmp.archive >> $seq_full
#pminfo -fl simple.now >> $seq_full
pminfo -l -O 6sec -a $tmp.archive simple.now | _filter_labels

# success, all done
exit
16 changes: 16 additions & 0 deletions qa/1747.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
QA output created by 1747
Log for pmlogger on HOST started DATE

[DATE] pmlogger(PID) Info: Start
Config parsed
Starting logger for host "HOST"
Archive basename: ARCHIVE
[DATE] pmlogger(PID) Info: pmlogger: End of run time, exiting

Log finished DATE

simple.now
labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","unitsystem":"SI","userid":UID}
inst [0 or "sec"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"sec","unitsystem":"SI","userid":UID}
inst [1 or "min"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"min","unitsystem":"SI","userid":UID}
inst [2 or "hour"] labels {"domainname":"DOMAIN","groupid":GID,"hostname":"HOSTNAME","indom_name":"time","machineid":"MACHINE","role":"testing","units":"hour","unitsystem":"SI","userid":UID}
1 change: 1 addition & 0 deletions qa/group
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,7 @@ pmcd.pdu
1727 pmproxy libpcp_web pmda.openmetrics local
1740 pmda.proc local
1745 pmlogger libpcp pmval local pmda.sample pmda.simple pmlogdump
1747 pmlogger labels local
1748 atop local
1753 fetch valgrind local
1763 pmlogctl local
Expand Down
7 changes: 6 additions & 1 deletion src/libpcp/src/logmeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,24 @@ samelabelset(const pmLabelSet *set1, const pmLabelSet *set2)
if (n2 == set2->nlabels)
return 0; /* not the same */
}

/* All of the labels in set1 are in set2 with the same values. */
return 1; /* the same */
}

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

if (idp->type & PM_LABEL_INSTANCES)
return;

for (i = 0; i < idp->nsets; ++i) {
for (j = 0; j < idp_next->nsets; ++j) {
if (samelabelset(&idp->labelsets[i], &idp_next->labelsets[j])) {
Expand Down
10 changes: 8 additions & 2 deletions src/pmlogger/src/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,14 @@ manageLabels(pmDesc *desc, const __pmTimestamp *tsp, int only_instances)
else
ident = PM_IN_NULL;

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

if ((sts = putlabels(type, ident, tsp)) < 0)
Expand Down
Loading