File: common.opentelemetry

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 (129 lines) | stat: -rw-r--r-- 3,445 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
#
# Common shell routines for testing the OpenTelemetry PMDA.
#
# Copyright (c) 2025 Red Hat.
#

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

$python -c "import requests" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python requests module not installed"

CONFIG_DIR=$PCP_PMDAS_DIR/opentelemetry/config.d

_pmdaopentelemetry_check()
{
    [ -f $PCP_PMDAS_DIR/opentelemetry/pmdaopentelemetry.python ] || return 1
    [ -f $here/opentelemetry/opentelemetry_endpoint.python ] || return 1
    return 0
}

_have_python266()
{
    __v=`python -V 2>&1 | awk '{print $NF}'`
    [ "$__v" = "2.6.6" ] && return 0
    return 1
}

_pmdaopentelemetry_remove()
{
    echo
    echo "=== remove opentelemetry agent ===" | tee -a $here/$seq.full
    cd $PCP_PMDAS_DIR/opentelemetry
    $sudo ./Remove >$tmp.out 2>&1
    cat $tmp.out >>$here/$seq.full
    _filter_pmda_remove <$tmp.out \
    | $PCP_AWK_PROG '
BEGIN           { state = 0 }
/ Xferd / || / XXffeerrdd / { state = 1; next }
state == 1 && /^\[/     { state = 0 }
state == 0      { print }' \
    | sed \
        -e '/ Info: /d' \
    # end
}

_pmdaopentelemetry_install()
{
    # start from known starting points
    cd $PCP_PMDAS_DIR/opentelemetry
    $sudo ./Remove >/dev/null 2>&1
    _service pmcd stop 2>&1 | _filter_pcp_stop

    echo
    echo "=== opentelemetry agent installation ==="
    $sudo ./Install </dev/null >$tmp.out 2>&1
    cat $tmp.out >>$here/$seq.full
}

_pmdaopentelemetry_save_config()
{
    $sudo rm -rf $CONFIG_DIR.$seq
    $sudo mv $CONFIG_DIR $CONFIG_DIR.$seq
    $sudo mkdir -p $CONFIG_DIR
    $sudo chmod 777 $CONFIG_DIR
    for __f in $PCP_VAR_DIR/config/pmda/164.*.py; do
        [ -f "$__f" ] && $sudo mv -f $__f $__f.$seq
    done
    # turn off all pmloggers when running open telemetry tests
    _stop_auto_restart pmlogger
    _service pmlogger stop 2>&1 | _filter_pcp_stop
}

_pmdaopentelemetry_restore_config()
{
    if [ -d $CONFIG_DIR.$seq ]; then
        $sudo rm -rf $CONFIG_DIR
        $sudo mv $CONFIG_DIR.$seq $CONFIG_DIR
        $sudo chmod 755 $CONFIG_DIR
    fi
    $sudo rm -f $PCP_VAR_DIR/config/pmda/164.*.py
    for __f in $PCP_VAR_DIR/config/pmda/164.*.py.$seq; do
        [ -f "$__f" ] && $sudo mv -f $__f `echo $__f | sed -e "s/\.$seq//"`
    done
}

_pmdaopentelemetry_cleanup()
{
    echo "=== opentelemetry PMDA log ===" >>$here/$seq.full
    if [ -f $PCP_LOG_DIR/pmcd/opentelemetry.log ]
    then
        cat $PCP_LOG_DIR/pmcd/opentelemetry.log >>$here/$seq.full
    else
        echo "Error: PMDA log file is missing" >>$here/$seq.full
    fi

    _pmdaopentelemetry_restore_config
    # note: _restore_auto_restart pmcd done in _cleanup_pmda()
    _cleanup_pmda opentelemetry
    # restart all pmloggers after running opentelemetry tests
    _restore_auto_restart pmlogger
    _service pmlogger restart 2>&1 | _filter_pcp_restart
    _wait_for_pmlogger
}

# wait for the PMDA to dynamically create a named metric (or subtree)
_pmdaopentelemetry_wait_for_metric()
{
    __metric="$1"
    [ -z "$__metric" ] && __metric=opentelemetry.control.calls

    # wait for the requested metric to appear in the pmns
    __i=0
    while [ $__i -lt 30 ]
    do
        if pminfo $__metric >/dev/null 2>&1
        then
            # all good
            return 0
        fi
        sleep 1
        __i=`expr $__i + 1`
    done

    # timeout, fail
    echo _pmdaopentelemetry_wait_for_metric FAILED for metric $__metric
    return 1
}