Page MenuHomeDevCentral

Notifications: summarize Docker Images rebuilds
ClosedPublic

Authored by dereckson on Mar 27 2016, 15:35.
Referenced Files
Unknown Object (File)
Tue, Nov 12, 19:04
Unknown Object (File)
Tue, Nov 12, 16:27
Unknown Object (File)
Thu, Nov 7, 18:25
Unknown Object (File)
Thu, Nov 7, 17:39
Unknown Object (File)
Thu, Nov 7, 15:30
Unknown Object (File)
Thu, Nov 7, 14:53
Unknown Object (File)
Sun, Oct 27, 23:27
Unknown Object (File)
Sun, Oct 27, 08:33
Subscribers

Details

Summary

If a new base Docker image is pushed several times in a row,
that will trigger a new build for every dependant image.
We then have a flood of notifications on the channel.

This change bypasses the instant notifications, and instead,
publishes a summary every 30 minutes.

Fixes T790.

Test Plan

The code is currently live on Wearg.

Proc tests

  • notifications::docker_format_builds "a 4 b 5 c 6 d 7" gives a (4x), b (5x), c (6x), d (7x)
  • The projects we currently have have been added to the registry registry set notifications.projects [list Wolfplex Keruald Nasqueron] Then, notifications::get_projects gives correctly this list.

Integration test

  • put a notification payload to $rawContent
  • notifications::docker_build_summary DockerHub Nasqueron docker $rawContent push "image pushed" "somelink" 3x
  • notifications::channel_notify_periodics 0 0 0 0 0 prints on the channel New images pushed to Docker Hub: svendowideit/testhook (3x)
  • registry get notifications.periodics.docker.Nasqueron returns correctly an empty string at this stage

To test the bind time

The eggdrop binds TCL procedure stores the amount of time a proc
has been triggered. At 15:30 UTC, the counter increased correctly.

15:25:33 <Dereckson> .tcl binds time
15:25:33 <Wearg> Tcl: {time -|- {30 *} 1 ::notifications::channel_notify_periodics}
15:32:49 <Dereckson> .tcl binds time
15:32:49 <Wearg> Tcl: {time -|- {30 *} 2 ::notifications::channel_notify_periodics}

Diff Detail

Repository
rVIPER ViperServ scripts
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dereckson retitled this revision from to Summarize Docker Images rebuilds on #nasqueron-ops.
dereckson updated this object.
dereckson edited the test plan for this revision. (Show Details)
dereckson added a reviewer: dereckson.
dereckson added a subscriber: Sandlayth.
dereckson edited the test plan for this revision. (Show Details)
dereckson retitled this revision from Summarize Docker Images rebuilds on #nasqueron-ops to Notifications: summarize Docker Images rebuilds.Mar 27 2016, 15:44
dereckson edited edge metadata.

Doesn't work currently. We need to debug that.

dereckson added inline comments.
Wearg/Notifications.tcl
3

Works, called 1642 times on Wearg.

10

Our bind doesn't have statistics. We need to know if the proc is called.

dereckson planned changes to this revision.EditedAug 16 2016, 20:53

The error occurs at the JSON parser level, invoked by json::json2dict $payload in get_image_from_docker_payload proc.

Stacktrace:

unexpected token "1471380573" at position 2; expecting STRING
    while executing
"unexpected $tokenCursor $token "STRING""
    (procedure "parseObjectMember" line 26)
    invoked from within
"parseObjectMember $tokens $nrTokens tokenCursor objectDict"
    (procedure "parseObjectMembers" line 6)
    invoked from within
"parseObjectMembers $tokens $nrTokens tokenCursor result"
    (procedure "parseObject" line 15)
    invoked from within
"parseObject $tokens $nrTokens tokenCursor"
    ("{" arm line 2)
    invoked from within
"switch -exact -- $leadingChar {
            "\{" {
                return [parseObject $tokens $nrTokens tokenCursor]
            }
            "\[" {..."
    (procedure "parseValue" line 11)
    invoked from within
"parseValue $tokens $nrTokens tokenCursor"
    (procedure "json::json2dict" line 7)
    invoked from within
"json::json2dict $payload"
    (procedure "get_image_from_docker_payload" line 2)
    invoked from within
"get_image_from_docker_payload $rawContent"
    (procedure "::notifications::docker_build_summary" line 8)
    invoked from within
"$callback {*}$params"
    (procedure "::notifications::on_broker_message" line 13)
    invoked from within
"$callback $queue $message"
    (procedure "on_message" line 6)
    invoked from within
"on_message $queue $message"
    (procedure "get_messages" line 14)
    invoked from within
"get_messages"
    (procedure "::broker::on_tick" line 7)
    invoked from within
"::broker::on_tick"

Payload

1{"service":"DockerHub","project":"Acme","group":"docker","rawContent":{"push_data":{"pushed_at":1471373693,"images":[],"tag":"latest","pusher":"nasqueron"},"callback_url":"https:\/\/registry.hub.docker.com\/u\/nasqueron\/aphlict\/hook\/2dhihe0hcbhij4i4iff4h4gffb3i3e0da\/","repository":{"status":"Active","description":"","is_trusted":true,"full_description":"Aphlict server for Phabricator\n==============================\n\nOne Aphlict server could serve one or several instances of Phabricator.\n\nRun directly on HTTP\n--------------------\n\n1. Pull the image: `docker pull nasqueron\/aphlict`\n2. Run the container: `docker run -dt -p 22280:22280 -p 22281:22281 nasqueron\/aphlict`\n3. Configure your Phabricator instance at http:\/\/phabricator.domain.tld\/config\/edit\/notification.servers\n\nWhen you configure your instance, use the following template:\n\n```lang=json\n[\n {\n \"type\": \"client\",\n \"host\": \"aphlict.yourdomain.tld\",\n \"port\": 22280,\n \"protocol\": \"http\"\n },\n {\n \"type\": \"admin\",\n \"host\": \"aphlict.yourdomain.tld\",\n \"port\": 22281,\n \"protocol\": \"http\"\n }\n]\n```\n\nTLS termination\n---------------\n\nAdd a certificate to your container, replace the protocol\nhttp by https in Phabricator config.\n\nEdit \/opt\/phabricator\/conf\/aphlict\/aphlict.custom.json in your\ncontainer, so ssl.key & ssl.cert certificates have the relevant paths.\n\nNote\n----\n\nYou can get the server log using `docker logs <your container name>`.\n\nTo check the status of the server,\nuse http:\/\/phabricator.domain.tld\/config\/cluster\/notifications\/\n","repo_url":"https:\/\/hub.docker.com\/r\/nasqueron\/aphlict","owner":"nasqueron","is_official":false,"is_private":false,"name":"aphlict","namespace":"nasqueron","star_count":0,"comment_count":0,"date_created":1436477799,"dockerfile":"#\n# Nasqueron - Phabricator image\n#\n\nFROM node\nMAINTAINER S\u00e9bastien Santoro aka Dereckson <dereckson+nasqueron-docker@espace-win.org>\n\nRUN cd \/opt && \\\n git clone https:\/\/github.com\/phacility\/libphutil.git && \\\n git clone https:\/\/github.com\/phacility\/phabricator.git && \\\n cd phabricator\/support\/aphlict\/server\/ && \\\n npm install ws && \\\n groupadd -r app -g 433 && \\\n mkdir \/home\/app && \\\n useradd -u 431 -r -g app -d \/home\/app -s \/sbin\/nologin -c \"Docker image user for server\" app && \\\n touch \/var\/run\/aphlict.pid \/var\/log\/aphlict.log && \\\n chown app:app \/home\/app \/var\/run\/aphlict.pid \/var\/log\/aphlict.log\n\nCOPY aphlict.custom.json \/opt\/phabricator\/conf\/aphlict\/\n\nEXPOSE 22280 22281\n\nWORKDIR \/opt\/phabricator\/support\/aphlict\/server\nUSER app\nCMD [ \"node\", \"--max-old-space-size=256\", \"--\", \"aphlict_server.js\", \"--config=\/opt\/phabricator\/conf\/aphlict\/aphlict.custom.json\" ]\n","repo_name":"nasqueron\/aphlict"}},"type":"push","text":"New image pushed to Docker Hub registry for nasqueron\/aphlict by nasqueron","link":"https:\/\/hub.docker.com\/r\/nasqueron\/aphlict"}

According Bradipo from TCL, parsing is okay (and produces a correct dict) with json 1.3.3.

We use 1.3.2, and there is no recent upgrade of the lib.

https://github.com/tcltk/tcllib/commit/263d1a252823edaf1750b68e549fb45528d09a4f is a good candidate to solve the issue.

According Bradipo from TCL, parsing is okay (and produces a correct dict) with json 1.3.3.

I now understand the error: the stacktrace parses twice JSON, it expects rawContent as a string to parse, not an already parsed dict.

According Bradipo from Freenode tcl channel, parsing is okay (and produces a correct dict) with json 1.3.3.

I now understand the error: if we follow the stack trace, the code parses twice a string to JSON, as it expects rawContent as a string to parse, not an already parsed dict.

This is an issue, discussed at T984, to decide the rawContent format. Initially, it would considered as a string, but notifications center serializes it as a JSON message, and use "mixed" as specification type, meaning it could be any kind of objects.

If rawContent stays as currently implementated an object part of the JSON, we can update the code like below, it works fine with Wearg currently.

diff --git a/Wearg/Notifications.tcl b/Wearg/Notifications.tcl
index db4074d..0036fc9 100644
--- a/Wearg/Notifications.tcl
+++ b/Wearg/Notifications.tcl
@@ -105,8 +105,7 @@ namespace eval notifications {
        }
 
        proc get_image_from_docker_payload {payload} {
-               set payloadDict [json::json2dict $payload]
-               set repository  [dict get $payloadDict repository]
+               set repository [dict get $payload repository]
                dict get $repository repo_name
        }
dereckson marked an inline comment as done.

Per T984.

dereckson edited edge metadata.
dereckson marked an inline comment as done.
This revision is now accepted and ready to land.Aug 24 2016, 03:15
This revision was automatically updated to reflect the committed changes.