Skip to content

Commit

Permalink
logs: refactor %logs agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Nov 22, 2024
1 parent 91e4763 commit a198f05
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 71 deletions.
1 change: 1 addition & 0 deletions desk/app/channels-server.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
|= [=(pole knot) =sign:agent:gall]
^+ cor
?+ pole ~|(bad-agent-wire+pole !!)
[%logs ~] cor
[%pimp ~] cor
[%wake ~] cor
::
Expand Down
7 changes: 1 addition & 6 deletions desk/app/channels.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,7 @@
?+ pole ~|(bad-agent-wire+pole !!)
~ cor
[%pimp ~] cor
::
[%logs ~]
?> ?=(%poke-ack -.sign)
?~ p.sign cor
%- (slog leaf+"Failed to log" u.p.sign)
cor
[%logs ~] cor
::
[%hark ~]
?> ?=(%poke-ack -.sign)
Expand Down
1 change: 1 addition & 0 deletions desk/app/groups.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@
?+ pole ~|(bad-agent-take/pole !!)
~ cor
[%epic ~] (take-epic sign)
[%logs ~] cor
[%helm *] cor
[%activity %submit *] cor
[%groups %role ~] cor
Expand Down
41 changes: 10 additions & 31 deletions desk/app/logs.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
=>
|%
+$ card card:agent:gall
+$ current-state [%0 =logs:l]
+$ current-state [%0 ~]
--
=| current-state
=* state -
Expand Down Expand Up @@ -44,29 +44,13 @@
++ emil |=(caz=(list card) cor(cards (welp (flop caz) cards)))
++ give |=(=gift:agent:gall (emit %give gift))
::
++ tick ^~((div ~s1 (bex 16)))
++ add-log-event
|= [agent=@tas =log-event:l]
^- [id-event:l _logs]
=/ =log:l
(fall (~(get by logs) agent) ~)
=/ =id-event:l
|-
?. (has:on-log:l log now.bowl) now.bowl
$(now.bowl (add now.bowl tick))
:- id-event
%+ ~(put by logs) agent
(put:on-log:l log id-event log-event)
::
++ send-posthog-event
|= [agent=@tas =id-event:l =log-event:l]
|= [origin=path =time =log-event:l]
^+ cor
=/ fard=(fyrd:khan cage)
[q.byk.bowl %posthog noun+!>(`[agent ^-(log-item:l [id-event log-event])])]
[q.byk.bowl %posthog noun+!>(`[origin time log-event])]
::
%^ emit %pass
/posthog/[agent]/(scot %da id-event)
[%arvo ^-(note-arvo [%k %fard fard])]
(emit %pass /posthog [%arvo %k %fard fard])
::
++ poke
|= [=mark =vase]
Expand All @@ -77,21 +61,17 @@
=+ !<(=a-log:l vase)
?- -.a-log
%log
?> ?=([@ @ ~] sap.bowl)
=+ agent=i.t.sap.bowl
=^ id-event logs (add-log-event agent +.a-log)
(send-posthog-event agent id-event +.a-log)
=/ =log-item:l [now.bowl +.a-log]
(send-posthog-event sap.bowl log-item)
==
==
::
++ arvo
|= [=(pole knot) =sign-arvo]
?+ pole ~|(bad-arvo-wire+pole !!)
:: /posthog/agent/id-event
:: /posthog
::
[%posthog agent=@tas id-event=@da ~]
?~ id-event=(slaw %da id-event.pole)
~|(evil-arvo-wire+pole !!)
[%posthog ~]
?> ?=([%khan %arow *] sign-arvo)
=/ =(avow:khan cage) p.sign-arvo
?: ?=(%| -.avow)
Expand All @@ -100,14 +80,13 @@
=/ =cage p.avow
=+ !<(response=(unit client-response:iris) q.cage)
?~ response
((slog leaf+"failed to submit event {<`@da`u.id-event>}" ~) cor)
((slog leaf+"logs: failed to submit event" ~) cor)
?. ?=(%finished -.u.response)
~|(bad-client-response+u.response !!)
=* status-code status-code.response-header.u.response
?: !=(200 status-code)
%- (slog leaf+"failed to submit event {<`@da`u.id-event>} to posthog" ~)
%- (slog leaf+"logs: failed to submit event" ~)
cor
~& posthog-log-ok+`@da`u.id-event
cor
==
--
20 changes: 2 additions & 18 deletions desk/lib/logs.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,11 @@
^- $>(%a json)
?~ t a+~
=/ tame=(list tape)
%- zing
%+ turn t
(cork (cury wash [0 80]) zing)
::XX posthog does not display newlines properly
:: s+(crip (zing `(list tape)`(join "\0a" tame)))
(cury wash [0 80])
a+(turn tame tape:enjs)
::
++ d-co-2 (d-co:co 2)
++ id-event
|= id=^id-event
^- $>(%s json)
=+ date=(yore id)
=+ frac=(head f.t.date)
:: convert urbit fractosecs to millisecs
::
=+ mili=(div (mul frac 1.000) 65.563)
:- %s
%- crip
"{((d-co:co 4) y.date)}-{(d-co-2 m.date)}-{(d-co-2 d.t.date)}".
"T{(d-co-2 h.t.date)}:{(d-co-2 m.t.date)}:{(d-co-2 s.t.date)}".
".{((d-co:co 3) mili)}"
::
++ log-event
|= e=^log-event
^- $>(%o json)
Expand Down
12 changes: 1 addition & 11 deletions desk/sur/logs.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
|%
:: $log-event
::
::XX %tell: agent message
:: %fail: agent failure
::
+$ log-event
$% [%fail desc=term crash=tang]
==
+$ id-event time
::
:: $log-item: event with timestamp
+$ log-item [id=id-event event=log-event]
::
:: $log: time-ordered event log
+$ log ((mop id-event log-event) lth)
++ on-log ((on id-event log-event) lth)
++ mo-log ((mp id-event log-event) lth)
::
:: $logs: log per agent
++ logs (map @tas log)
+$ log-item [=time event=log-event]
::
+$ a-log
$% [%log log-event]
Expand Down
10 changes: 5 additions & 5 deletions desk/ted/posthog.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
::
=, strand=strand:spider
^- thread:spider
:: .arg: a pair of origin agent and log item
:: .arg: a pair of origin and log item
::
|= arg=vase
=/ m (strand ,vase)
^- form:m
=+ !<(arg=(unit (pair @tas log-item:l)) arg)
=+ !<(arg=(unit (pair path log-item:l)) arg)
?> ?=(^ arg)
=* agent p.u.arg
=* origin p.u.arg
=* log-item q.u.arg
;< =bowl:strand bind:m get-bowl:io
=/ log-event-json=$>(%o json) (log-event:enjs:l event.log-item)
Expand All @@ -27,12 +27,12 @@
^- (map @t json)
%- my
:~ 'distinct_id'^s+(scot %p our.bowl)
'agent'^s+agent
'origin'^s+(spat origin)
==
=/ event=json
%- pairs:enjs:format
:~ 'api_key'^s+posthog-key
timestamp/(id-event:enjs:l id.log-item)
timestamp/(time:enjs:format time.log-item)
event/s+'Backend Log'
properties+props
==
Expand Down

0 comments on commit a198f05

Please sign in to comment.