#724 Add more tracing messages to countme scripts
Merged 3 years ago by nphilipp. Opened 3 years ago by asaleh.
fedora-infra/ asaleh/ansible add_messages_to_mirrors_countme  into  main

@@ -23,6 +23,7 @@ 

    - sudo

    - awstats

    - web-data-analysis

+   - fedora-messaging-utils

    - role: keytab/service

      owner_user: apache

      owner_group: apache

@@ -19,6 +19,9 @@ 

  # along with Fedora Project Infrastructure Ansible Repository.  If

  # not, see <http://www.gnu.org/licenses/>.

  

+ RUN_ID="$(uuidgen -r)"

+ simple_message_to_bus combinehttplogs.start run_id="$RUN_ID"

+ 

  # Some constants / standard paths

  LOGDIR=/var/log/hosts

  NFSDIR=/mnt/fedora_stats/combined-http
@@ -79,7 +82,9 @@ 

  

  for FILE in ${FILES}; do

      TEMP=$(echo ${FILE} | sed 's/\.xz$//')

+     simple_message_to_bus combinehttplogs.logmerge.proxy.start run_id="$RUN_ID" log="$PROXYLOG" file="$FILE" target="$TARGET" temp="$TEMP"

      perl ${LOGMERGE} ${PROXYLOG}/${FILE} > ${TARGET}/${TEMP}

+     simple_message_to_bus combinehttplogs.logmerge.proxy.finish run_id="$RUN_ID" log="$PROXYLOG" file="$FILE" target="$TARGET" temp="$TEMP" result="$?"

  done

  

  ##
@@ -88,7 +93,9 @@ 

  

  for FILE in ${FILES}; do

      TEMP=$(echo ${FILE} | sed 's/\.xz$//')

+     simple_message_to_bus combinehttplogs.logmerge.download.start run_id="$RUN_ID" proxylog="$DL_LOG" file="$FILE" target="$TARGET" temp="$TEMP"

      perl ${LOGMERGE} ${DL_LOG}/${FILE} > ${TARGET}/${TEMP}

+     simple_message_to_bus combinehttplogs.logmerge.download.finish run_id="$RUN_ID" proxylog="$DL_LOG" file="$FILE" target="$TARGET" temp="$TEMP"  result="$?"

  done

  

  ##
@@ -99,7 +106,9 @@ 

  

  for FILE in ${FILES}; do

      TEMP=$(echo ${FILE} | sed 's/\.xz$//')

+     simple_message_to_bus combinehttplogs.logmerge.people.start run_id="$RUN_ID" proxylog="$PEOPLE" file="$FILE" target="$TARGET" temp="$TEMP"

      perl ${LOGMERGE} ${PEOPLE}/${FILE} > ${TARGET}/${TEMP}

+     simple_message_to_bus combinehttplogs.logmerge.people.finish run_id="$RUN_ID" proxylog="$PEOPLE" file="$FILE" target="$TARGET" temp="$TEMP" result="$?"

  done

  

  # Now we link up the files into latest directory
@@ -116,3 +125,4 @@ 

      done

      popd &> /dev/null

  fi

+ simple_message_to_bus combinehttplogs.finish run_id="$RUN_ID"

@@ -0,0 +1,30 @@ 

+ #!/bin/sh

+ MSGTOPIC_PREFIX="${MSGTOPIC_PREFIX:-logging.stats}"

+ topic="${MSGTOPIC_PREFIX}.$1"

+ shift

+ sent_at="$(TZ=UTC date -Iseconds)"

+ id="$(uuidgen -r)"

+ body="{"

+ sep=""

+ 

+ for body_piece; do

+     key_type="${body_piece%%=*}"

+     key="${key_type%%:*}"

+     type="${key_type#${key}}"

+     type="${type#:}"

+     value="${body_piece#*=}"

+ 

+     if [ "$type" != "int" ]; then

+         # quote strings

+         value="${value//\\/\\\\}"

+         value="${value//\"/\\\"}"

+         value="\"${value}\""

+     fi

+     body="${body}${sep}\"${key}\": ${value}"

+     sep=", "

+ done

+ body="${body}}"

+ 

+ fedora-messaging publish - << EOF >/dev/null

+ {"body": ${body}, "headers": {"fedora_messaging_schema": "base.message", "fedora_messaging_severity": 20, "sent-at": "${sent_at}"}, "id": "${id}", "queue": "queue", "topic": "${topic}"}

+ EOF

@@ -0,0 +1,2 @@ 

+ - name: install messaging script for our improvized tracing

+   copy: src=simple_message_to_bus dest=/usr/local/bin/ mode=0755

@@ -25,6 +25,8 @@ 

  # we are 5 days behind.

  

  # We have dropped this down to 3 days on 2019-10-01

+ RUN_ID="$(uuidgen -r)"

+ simple_message_to_bus condense-mirrorlogs.start run_id="$RUN_ID"

  

  let NUMDAYS=3

  let OLDDAYS=$(( $NUMDAYS+1 ))
@@ -71,7 +73,9 @@ 

  elif [[ -f ${WORKFILE} ]]; then 

      echo "The workfile for ${YEAR}/${MONTH}/${DAY} already existed."

  else

+     simple_message_to_bus condense-mirrorlogs.mirrorlist.start run_id="$RUN_ID" workfile="$WORKFILE" logfile="$LOGFILE"

      ${LBIN}/mirrorlist.py -o ${WORKFILE} ${LOGFILE}; 

+     simple_message_to_bus condense-mirrorlogs.mirrorlist.finish run_id="$RUN_ID" workfile="$WORKFILE" logfile="$LOGFILE" result="$?"

  fi

  

  # So the data isn't strictly across month boundries due to the end of
@@ -106,3 +110,4 @@ 

  

  # cleanup the temp data

  rm -rf ${TEMPDIR}

+ simple_message_to_bus condense-mirrorlogs.finish run_id="$RUN_ID"

@@ -1,5 +1,8 @@ 

  #!/bin/bash

  

+ RUN_ID="$(uuidgen -r)"

+ simple_message_to_bus countme-update.start run_id="$RUN_ID"

+ 

  # Where do we keep our local/internal data?

  LOCAL_DATA_DIR=/var/lib/countme

  RAW_DB=$LOCAL_DATA_DIR/raw.db
@@ -31,7 +34,15 @@ 

  # _run [COMMAND...]: Run a command, honoring $VERBOSE and $DRYRUN

  _run() {

      if [ "$VERBOSE" -o "$DRYRUN" ]; then echo "$@"; fi

-     if [ "$DRYRUN" ]; then return 0; else "$@"; fi

+     if [ "$DRYRUN" ]; then 

+       return 0

+     else

+       simple_message_to_bus countme-update.command.start run_id="$RUN_ID" command="$@"

+       "$@"

+       RESULT=$?

+       simple_message_to_bus countme-update.command.finish run_id="$RUN_ID" command="$@" result="$?"

+       return $RESULT

+     fi

  }

  

  # CLI help text
@@ -108,3 +119,6 @@ 

  # Copy new data into place

  _run atomic_copy $TOTALS_DB $PUBLIC_TOTALS_DB

  _run atomic_copy $TOTALS_CSV $PUBLIC_TOTALS_CSV

+ 

+ simple_message_to_bus countme-update.finish run_id="$RUN_ID"

+ 

@@ -140,6 +140,12 @@ 

    tags:

      - web-data

  

+ - name: install messaging script for our improvized tracing

+   copy: src=simple_message_to_bus dest=/usr/local/bin/ mode=0755

+   tags:

+     - web-data

+     - cron

+ 

  - name: install countme script to parse new logs & update totals

    copy: src=countme-update.sh dest=/usr/local/bin/ mode=0755

    tags:

In the process, I made the message-sending function into it's own script: simple_message_to_bus

Metadata Update from @nphilipp:
- Request assigned

3 years ago

s/improvized/improved/ -- that's our hope at least :smiley:

Let's drop unpackaged executables into /usr/local/bin -- or alternatively, we could retain simple_message_to_bus() as a function and source the file

rebased onto 5012253c870d5ef500c602d518c97a12749e61b2

3 years ago

LGTM!

Maybe not quite, we seem to be mixing roles (even though they're only applied to the same host group). I'll give it a more thorough look next week.

rebased onto f9e0ea74b0d059a975408e91ba60d5b579ddcd0b

3 years ago

rebased onto f9e0ea74b0d059a975408e91ba60d5b579ddcd0b

3 years ago

The role we talked about before which sets up the host as a fedora-messaging client is logging and I don't know if that's a suitable role to put the script into. What do you think? The alternative I see is put the scripts into files/common and have a task which can be included/imported from tasks/.

I'd rather have this in logging then.

On second thought, I would rather leave this as is, and we will refactor it once we will want to use it from a different role. Only scripts that currently use this are in web-data-analysis

Ah, one is in awstats, in that case I will figure something out.

rebased onto 94d839d67b77dd5ad310a9932cb79d224f1d2c1c

3 years ago

rebased onto 32b011f705ff0242804b7b27da2ef5d4202ad2a8

3 years ago

rebased onto 32b011f705ff0242804b7b27da2ef5d4202ad2a8

3 years ago

rebased onto a98352c4a0cf6d9e8c3cd7e7197c849f1c153ebc

3 years ago

rebased onto a98352c4a0cf6d9e8c3cd7e7197c849f1c153ebc

3 years ago

rebased onto c71d6ff1d596bd4ededd2de73c51a1a11e0c1a8d

3 years ago

@asaleh The new fedora-messaging-utils role sounds generic, but hardcodes logging.stats as the topic prefix... Instead, we could e.g. set & export MSG_TOPIC_PREFIX=... in the caller and evaluate that env variable in simple-message-to-bus, what do you think?

Whats the status here? should we merge it?

Whats the status here? should we merge it?

The issue I raised in my previous comment isn't resolved.

I think I did account for it: https://pagure.io/fedora-infra/ansible/pull-request/724#_3__3 ... just leaving the logging.stats as a default.

Didn't spot that! Let's merge it.

rebased onto db93606

3 years ago

rebased onto db93606

3 years ago

Pull-Request has been merged by nphilipp

3 years ago