github.com/noironetworks/cilium-net@v1.6.12/contrib/scripts/check-logging-subsys-field.sh (about)

     1  #!/bin/bash
     2  
     3  # check-logging-subsys-field.sh checks whether all logging entry instancs
     4  # created from DefaultLogger contain the LogSubsys field. This is required for
     5  # proper labeling of error/warning Prometheus metric and helpful for debugging.
     6  # If any entry which writes any message doesn't contaion the 'subsys' field,
     7  # Prometheus metric logging hook (`pkg/metrics/logging_hook.go`) is going to
     8  # fail.
     9  
    10  # Directories:
    11  # - pkg/debugdetection
    12  # - test/
    13  # - vendor/
    14  # are excluded, because instances of DefaultLogger in those modules have their
    15  # specific usage which doesn't break the Prometheus logging hook.
    16  
    17  set -eu
    18  
    19  if grep -IPRns '(?!.*LogSubsys)log[ ]*= logging\.DefaultLogger.*' \
    20          --exclude-dir=test \
    21          --exclude-dir=pkg/debugdetection \
    22          --exclude-dir=vendor \
    23          --include=*.go .; then
    24      echo "Logging entry instances have to contain the LogSubsys field. Example of"
    25      echo "properly configured entry instance:"
    26      echo
    27      echo -e "\timport ("
    28      echo -e "\t\t\"github.com/cilium/cilium/pkg/logging\""
    29      echo -e "\t\t\"github.com/cilium/cilium/pkg/logging/logfields\""
    30      echo -e "\t)"
    31      echo
    32      echo -e "\tvar log = logging.DefaultLogger.WithField(logfields.LogSubsys, \"my-subsystem\")"
    33      echo
    34      exit 1
    35  fi