Files
canvas-lms/script/docker_webpack_monitoring.js
jake.oeding ad55f0b5d5 add script that alerts when webpack completes
this functionality existed for 'local' canvas
instances, but this now adds it for dockerized
setups

flag=none
qa risk: low

test plan:
-run the script: `node docker_webpack_monitoring.js`
-start webpack logs: `docker compose logs -f webpack`
-trigger webpack by altering some front-end code
-monitor the logs manually
>confirm you get a MacOS notification shortly after
 webpack ceases processing

Change-Id: I4877d411c271058b7544bbe8c2dd0e888396ba0d
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/321140
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jacob DeWar <jacob.dewar@instructure.com>
QA-Review: Jacob DeWar <jacob.dewar@instructure.com>
Product-Review: Jake Oeding <jake.oeding@instructure.com>
2023-06-26 16:48:27 +00:00

56 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
/*
* Copyright (C) 2023 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-disable no-constant-condition */
/* eslint-disable no-await-in-loop */
const promisify = require('util').promisify
const exec = promisify(require('child_process').exec)
const BASELINE_CPU_UTILIZATION = 5.0
/**
* Utilize common command line utilities plus `docker stats` command to monitor Webpack
*
* The `docker stats` command gives us info about the current running containers. The third
* column provides us with CPU utilization percentage. When webpack is running, this value
* spikes. When webpack finishes processing, it typically falls to a value less than a few percent.
*
* This function monitors the utilization and sends a native MacOS alert when webpack finishes
*/
async function monitorWebpack() {
let webpackFinished = false
while (1) {
const {stdout} = await exec("docker stats --no-stream | grep webpack | awk '{print $3}'")
const currentUtilization = parseFloat(stdout.replace('%', ''))
if (currentUtilization <= BASELINE_CPU_UTILIZATION && !webpackFinished) {
webpackFinished = true
exec(
'osascript -e \'display notification "Canvas Webpack build finished" with title "Build Finished"\''
)
}
if (currentUtilization > BASELINE_CPU_UTILIZATION && webpackFinished) {
webpackFinished = false
}
}
}
monitorWebpack()