Megatest

Check-in [c4fac28c5c]
Login
Overview
Comment:ensured telemetry logging does not happen if no mention in megatest.config
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.65-telemetry
Files: files | file ages | folders
SHA1: c4fac28c5c3bb5fc20ece1b31c336b35c74abf64
User & Date: bjbarcla on 2019-02-13 19:03:23
Other Links: branch diff | manifest | tags
Context
2019-02-13
19:08
cleanup telemetry-daemon check-in: c31defc65c user: bjbarcla tags: v1.65-telemetry
19:03
ensured telemetry logging does not happen if no mention in megatest.config check-in: c4fac28c5c user: bjbarcla tags: v1.65-telemetry
18:34
add command to telemetry packet check-in: 98f55eb235 user: bjbarcla tags: v1.65-telemetry
Changes

Modified common.scm from [58f629c39e] to [91f2f49c15].

3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082


3083
3084
3085
3086





3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104

3105

3106

3107
3108
             (serverport (configf:lookup-number *configdat* "telemetry" "port"))
             (user (or (get-environment-variable "USER") "unknown"))
             (host (or (get-environment-variable "HOST") "unknown")))
        (set! *common:telemetry-log-state*
              (handle-exceptions
               exn
               (begin
                 (debug:print-info 0 *default-log-port* "common-telemetry-log get udp port failure")
                 'broken)
               (if (and serverhost serverport user host)
                   (let* ((s (udp-open-socket)))
                     ;;(udp-bind! s #f 0)
                     (udp-connect! s serverhost serverport)
                     (set! *common:telemetry-log-socket* s)
                     'open)
                   'not-needed))))))
  
(define (common:telemetry-log event #!key (payload '()))
  (if (eq? *common:telemetry-log-state* 'startup)
      (common:telemetry-log-open))


  (handle-exceptions
   exn
   (begin
     (debug:print-info 0 *default-log-port* "common-telemetry-log failure"))





   (if (and *common:telemetry-log-socket* event)
       (let* ((user (or (get-environment-variable "USER") "unknown"))
              (host (or (get-environment-variable "HOST") "unknown"))
              (start (conc "[megatest "event"]"))
              (toppath (or *toppath* "/dev/null"))
              (payload-serialized
               (base64:base64-encode
                (z3:encode-buffer
                 (with-output-to-string (lambda () (pp payload))))))
              (msg     (conc user":"host":"start":"(current-process-id)":"(car (argv))":"
                             toppath":"payload-serialized)))
         (udp-send *common:telemetry-log-socket* msg)))))

(define (common:telemetry-log-close)
  (when (and (eq? *common:telemetry-log-state* 'open) *common:telemetry-log-socket*)
    (handle-exceptions
     exn
     (begin

       (debug:print-info 0 *default-log-port* "common-telemetry-log closure failure"))

     (begin

       (udp-close-socket *common:telemetry-log-socket*)
       (set! *common:telemetry-log-socket* #f)))))







|












>
>
|
|
|
|
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|

|



>
|
>

>


3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
             (serverport (configf:lookup-number *configdat* "telemetry" "port"))
             (user (or (get-environment-variable "USER") "unknown"))
             (host (or (get-environment-variable "HOST") "unknown")))
        (set! *common:telemetry-log-state*
              (handle-exceptions
               exn
               (begin
                 (debug:print-info 0 *default-log-port* "common-telemetry-log open udp port failure")
                 'broken)
               (if (and serverhost serverport user host)
                   (let* ((s (udp-open-socket)))
                     ;;(udp-bind! s #f 0)
                     (udp-connect! s serverhost serverport)
                     (set! *common:telemetry-log-socket* s)
                     'open)
                   'not-needed))))))
  
(define (common:telemetry-log event #!key (payload '()))
  (if (eq? *common:telemetry-log-state* 'startup)
      (common:telemetry-log-open))

  (if (eq? 'open *common:telemetry-log-state*)
      (handle-exceptions
       exn
       (begin
         (debug:print-info 0 *default-log-port* "common-telemetry-log comms failure ; disabled (no server?)")
         ;;(define *common:telemetry-log-state* 'broken-or-no-server-preclose)
         ;;(common:telemetry-log-close)
         (define *common:telemetry-log-state* 'broken-or-no-server)
         (set! *common:telemetry-log-socket* #f)
         )
       (if (and *common:telemetry-log-socket* event)
           (let* ((user (or (get-environment-variable "USER") "unknown"))
                  (host (or (get-environment-variable "HOST") "unknown"))
                  (start (conc "[megatest "event"]"))
                  (toppath (or *toppath* "/dev/null"))
                  (payload-serialized
                   (base64:base64-encode
                    (z3:encode-buffer
                     (with-output-to-string (lambda () (pp payload))))))
                  (msg     (conc user":"host":"start":"(current-process-id)":"(car (argv))":"
                                 toppath":"payload-serialized)))
             (udp-send *common:telemetry-log-socket* msg))))))
  
(define (common:telemetry-log-close)
  (when (or (member *common:telemetry-log-state* '(broken-or-no-server-preclose open)) *common:telemetry-log-socket*)
    (handle-exceptions
     exn
     (begin
       (define *common:telemetry-log-state* 'closed-fail)
       (debug:print-info 0 *default-log-port* "common-telemetry-log closure failure")
       )
     (begin
       (define *common:telemetry-log-state* 'closed)
       (udp-close-socket *common:telemetry-log-socket*)
       (set! *common:telemetry-log-socket* #f)))))