Skip to content

Commit

Permalink
Addition of pcp2opentelemetry tool
Browse files Browse the repository at this point in the history
Supports translation of pcp metrics into open telemetry format.
Supports opentelemetry protocol http json format.

Updated relevent qa tests, as well as created a new one (1977) to test
the tools http functionality.

Added man page and makefile.
  • Loading branch information
lmchilton committed Apr 30, 2024
1 parent fce25dc commit dfab591
Show file tree
Hide file tree
Showing 7 changed files with 1,630 additions and 2 deletions.
19 changes: 18 additions & 1 deletion qa/1131
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# PCP QA Test No. 1131
# Exercise pcp2json and pcp2openmetrics.
# Exercise pcp2json, pcp2openmetrics, and pcp2opentelemetry.
#
# Copyright (c) 2017 Red Hat.
#
Expand Down Expand Up @@ -52,6 +52,21 @@ _filter_pcp2openmetrics()
| LC_COLLATE=POSIX sort
}

_filter_pcp2opentelemetry()
{
tee -a $here/$seq.full \
| col -b \
| sed \
-e '/\"asDouble\":/ s/[0-9][0-9]*/NCPU/' \
-e 's/\"'$machineid'\"/MACHINEID/' \
-e 's/\"'$hostname'\"/HOSTNAME/' \
-e 's/\"'$domainid'\"/DOMAINID/' \
-e 's/\"agent\": .*/\"agent\": \"'$OSTYPE'\"/' \
-e 's/\"userid\": .*/\"userid\": USERID/' \
-e 's/\"userid\": .*/\"userid\": GROUPID/' \
-e '/ using stream socket$/d'
}

# real QA test starts here
echo "---"
pcp2json -a $A -H -I -z "" | _archive_filter
Expand All @@ -64,6 +79,8 @@ pcp2json -a $A -H -I -z -X -b GB -P 2 -F $tmp.outfile ""
echo "---"
pcp2openmetrics -s1 -H -z hinv.ncpu | _filter_pcp2openmetrics
echo "---"
pcp2opentelemetry -s1 -H -z hinv.ncpu | _filter_pcp2opentelemetry
echo "---"


cat $tmp.outfile | _archive_filter
Expand Down
57 changes: 56 additions & 1 deletion qa/1131.out
Original file line number Diff line number Diff line change
Expand Up @@ -2269,10 +2269,65 @@ QA output created by 1131
---


# HELP hinv_ncpu number of CPUs in the system
# HELP hinv_ncpu b'number of CPUs in the system'
# PCP5 hinv_ncpu 60.0.32 u32 PM_INDOM_NULL discrete
# TYPE hinv_ncpu gauge
2
hinv_ncpu{domainname="DOMAINID",groupid="GROUPID",hostname="HOST",machineid="MACHINEID",userid="USERID",agent="linux"} NCPU
---
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"os.type": "linux",
"service.name": "pcp",
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.24.0"
}
]
},
"scopeMetrics": [
{
"metrics": [
{
"description": "number of CPUs in the system",
"gauge": {
"dataPoints": [
{
"asDouble": NCPU,
"attributes": [
{
"agent": "linux-gnu"
"domainname": DOMAINID,
"groupid": 4209557,
"hostname": HOSTNAME,
"machineid": MACHINEID,
"semantics": "discrete",
"type": "u32",
"userid": GROUPID
}
],
"startTimeUnixNano": 1714523105.211067
}
]
},
"name": "hinv.ncpu",
"unit": "none"
}
],
"scope": {
"name": "pcp.hinv",
"version": 1
}
}
]
}
]
}

---
{
"@pcp": {
Expand Down
81 changes: 81 additions & 0 deletions qa/1977
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh
# PCP QA Test No. 1827
# Exercise pcp2opentelemetry HTTP POST functionality.
#
# Copyright (c) 2024 Red Hat. All Rights Reserved.
#


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

. ./common.python

which pcp2opentelemetry >/dev/null 2>&1 || _notrun "pcp2opentelemetry not installed"


_cleanup()
{
cd $here
$sudo rm -rf $tmp $tmp.*
}

status=0 # success is the default!
cpus=`pmprobe -v hinv.ncpu | awk '{print $3}'`
hostname=`hostname`
machineid=`_machine_id`
domainid=`_domain_name`
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15


_filter_pcp2opentelemetry_http()
{
tee -a $here/$seq.full \
| col -b \
| sed \
-e '/\"asDouble\":/ s/[0-9][0-9]*/NCPU/' \
-e 's/\"'$machineid'\"/MACHINEID/' \
-e 's/\"'$hostname'\"/HOSTNAME/' \
-e 's/\"'$domainid'\"/DOMAINID/' \
-e 's/\"agent\": .*/\"agent\": \"'$OSTYPE'\"/' \
-e 's/\"userid\": .*/\"userid\": USERID/' \
-e 's/\"userid\": .*/\"userid\": GROUPID/' \
-e 's/- - \[[^]]*\]/- -[DATE]/g' \
-e 's/.*- -/[IP ADDRESS]/g' \
-e "s/^\(Host: localhost\):$port/\1:PORT/g" \
-e 's/^\(Content-Length:\) [1-9][0-9]*/\1 SIZE/g' \
-e 's/^\(User-Agent: python-requests\).*/\1 VERSION/g' \
-e 's/^\(Date:\).*/\1 DATE/g' \
-e 's/\(\"context\":\) [0-9][0-9]*/\1 CTXID/g' \
-e '/^Accept-Encoding: /d' \
-e 's/\(\hostname=\): \""$hostname"\"/\1:HOST/g' \
-e '/^Connection: keep-alive/d' \
-e '/ using stream socket$/d'
}


# real QA test starts here
port=`_find_free_port`
$PCP_PYTHON_PROG $here/src/pythonserver.py $port >$tmp.python.out 2>&1 &
pid=$!
sleep 2 # let server start up


echo "pcp2opentelemetry invocation" | tee -a $here/$seq.full
pcp2opentelemetry -s1 -u http://localhost:$port/receive hinv.ncpu >$tmp.json.out 2>$tmp.openjson.err


echo "pcp2opentelemetry HTTP POST (sorted):"
_filter_pcp2opentelemetry_http <$tmp.python.out


cp $tmp.python.out ~/chilton.txt


($signal $pid ) >>$seq.full 2>&1 &


# success, all done
exit

74 changes: 74 additions & 0 deletions qa/1977.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
QA output created by 1977
pcp2opentelemetry invocation
pcp2opentelemetry HTTP POST (sorted):
INFO:root:Starting httpd...

INFO:root:POST request,
Path: /receive
Headers:
Host: localhost:PORT
User-Agent: python-requests VERSION
Accept: */*
Content-Type: application/json
Content-Length: SIZE



Body:
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"os.type": "linux",
"service.name": "pcp",
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.24.0"
},
{
"server.address": "http://localhost:54337/receive"
}
]
},
"scopeMetrics": [
{
"metrics": [
{
"description": "number of CPUs in the system",
"gauge": {
"dataPoints": [
{
"asDouble": NCPU,
"attributes": [
{
"agent": "linux-gnu"
"domainname": DOMAINID,
"groupid": 4209557,
"hostname": HOSTNAME,
"machineid": MACHINEID,
"semantics": "discrete",
"type": "u32",
"userid": GROUPID
}
],
"startTimeUnixNano": 1714519586.062307
}
]
},
"name": "hinv.ncpu",
"unit": "none"
}
],
"scope": {
"name": "pcp.hinv",
"version": 1
}
}
]
}
]
}

[IP ADDRESS][DATE] "POST /receive HTTP/1.1" 200 -
46 changes: 46 additions & 0 deletions src/pcp2opentelemetry/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright (c) 2024 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#

TOPDIR = ../..
include $(TOPDIR)/src/include/builddefs

TARGET = pcp2opentelemetry
MAN_SECTION = 1
MAN_PAGES = $(TARGET).$(MAN_SECTION)
MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION)
BASHDIR = $(PCP_BASHSHARE_DIR)/completions

default: $(TARGET).py $(MAN_PAGES)

default:

include $(BUILDRULES)

install: default
ifeq "$(HAVE_PYTHON)" "true"
$(INSTALL) -m 755 $(TARGET).py $(PCP_BIN_DIR)/$(TARGET)
$(INSTALL) -S $(BASHDIR)/pcp $(BASHDIR)/$(TARGET)
@$(INSTALL_MAN)
endif

default_pcp: default

install_pcp: install

check:: $(TARGET).py
$(PYLINT) $^

check :: $(MAN_PAGES)
$(MANLINT) $^

Loading

0 comments on commit dfab591

Please sign in to comment.