canopycms-cdk 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -396,8 +396,10 @@ export interface CanopyCmsServiceProps {
396
396
  * started and a worker whose loops have stopped. A deploy or a spot
397
397
  * replacement does not trip it. See `workerDownAlarm`.
398
398
  *
399
- * The topic is also notified when a worker boot could not upgrade its
400
- * packages and started on the AMI's. See `workerUnpatchedAlarm`.
399
+ * It is also notified when a live worker's git-sync cycles have all failed
400
+ * for an hour, and on recovery. See `workerSyncFailingAlarm`. And it is
401
+ * notified when a worker boot could not upgrade its packages and started on
402
+ * the AMI's. See `workerUnpatchedAlarm`.
401
403
  */
402
404
  alarmTopic?: sns.ITopic;
403
405
  /**
@@ -518,6 +520,11 @@ export declare class CanopyCmsService extends Construct {
518
520
  readonly workerLogGroup: logs.LogGroup;
519
521
  /** Alarms when the worker logs no git-sync cycle for 30 minutes. Set only with `alarmTopic`. */
520
522
  readonly workerDownAlarm?: cloudwatch.Alarm;
523
+ /**
524
+ * Alarms when the worker's git-sync cycles start but none completes for an hour. Set only with
525
+ * `alarmTopic`.
526
+ */
527
+ readonly workerSyncFailingAlarm?: cloudwatch.Alarm;
521
528
  /** Alarms when a worker boot started without its package upgrade. Set only with `alarmTopic`. */
522
529
  readonly workerUnpatchedAlarm?: cloudwatch.Alarm;
523
530
  /**
@@ -3,7 +3,7 @@ import { Annotations, ArnFormat, Duration, Names, RemovalPolicy, Stack, Token, T
3
3
  import { attachLambdaExecutionPolicies } from './lambda-execution-role.js';
4
4
  import { INSTANCE_FILES_DOWNLOAD_PATH, WORKER_BUNDLE_DOWNLOAD_PATH, workerBundleSource, } from './worker-bundle.js';
5
5
  import { attachEditorBehaviors } from './editor-routing.js';
6
- import { GATEWAY_SPLIT_CONTRACT, WORKER_CAPACITY_ENV, WORKER_CONTRACT_BANNER_PREFIX, WORKER_DRAIN_HOOK_NAME, WORKER_SYNC_LOG_PHRASE, } from './worker-lifecycle.js';
6
+ import { GATEWAY_SPLIT_CONTRACT, WORKER_CAPACITY_ENV, WORKER_CONTRACT_BANNER_PREFIX, WORKER_DRAIN_HOOK_NAME, WORKER_SYNC_DONE_LOG_PHRASE, WORKER_SYNC_LOG_PHRASE, } from './worker-lifecycle.js';
7
7
  import { CANOPY_INSPECT, EFS_MOUNT_PATH, GATEWAY_LOG, GATEWAY_LOG_DIR, GATEWAY_USER, INSPECT_CHECKS, INSPECT_RC, INSTANCE_FILES_DIR, WORKER_INSTALL_DIR, WORKER_LOG, WORKER_LOG_DIR, } from './worker-units.js';
8
8
  /**
9
9
  * Synth-time mirror of `resolveDeploymentName`'s rule in the `canopycms`
@@ -1092,6 +1092,52 @@ export class CanopyCmsService extends Construct {
1092
1092
  const topicAction = new cloudwatchActions.SnsAction(props.alarmTopic);
1093
1093
  this.workerDownAlarm.addAlarmAction(topicAction);
1094
1094
  this.workerDownAlarm.addOkAction(topicAction);
1095
+ const completionsPrefix = 'WorkerGitSyncCompletions-';
1096
+ const syncCompletions = new logs.MetricFilter(this, 'WorkerSyncCompletions', {
1097
+ logGroup: this.workerLogGroup,
1098
+ filterPattern: logs.FilterPattern.literal(`"${WORKER_SYNC_DONE_LOG_PHRASE}"`),
1099
+ metricNamespace: 'CanopyCMS',
1100
+ metricName: `${completionsPrefix}${Names.uniqueResourceName(this, { maxLength: 255 - completionsPrefix.length })}`,
1101
+ metricValue: '1',
1102
+ // Every other event in the group emits 0, the cycle-start line included, so a period
1103
+ // with a start always has a completion count, and the expression below never compares
1104
+ // a missing one: a worker that has never completed a cycle still alarms.
1105
+ defaultValue: 0,
1106
+ });
1107
+ // A period with a cycle start is 1 when no cycle completed in it and 0 when one did; a
1108
+ // period with no start has no data point at all (IF drops it). CloudWatch judges the two
1109
+ // most recent real points, reaching back past such gaps within its evaluation range, and
1110
+ // `ignore` keeps the state when fewer remain. So a worker that is down neither pages here
1111
+ // (the down alarm owns that case, and one outage pages once) nor reads as recovered.
1112
+ // Every 30-minute window holds a start whenever cycles start less than 30 minutes apart,
1113
+ // which is where the down alarm takes over: cycles start the sync interval after the last
1114
+ // one ends, so a slow failing cycle or a longer interval cannot leave a gap between the
1115
+ // two. Two in a row, an hour or more, keeps a short GitHub incident from paging. The
1116
+ // schema gate's hold completes its cycle, and a drain is minutes long.
1117
+ this.workerSyncFailingAlarm = new cloudwatch.Alarm(this, 'WorkerSyncFailingAlarm', {
1118
+ metric: new cloudwatch.MathExpression({
1119
+ expression: 'IF(started, completed == 0)',
1120
+ usingMetrics: {
1121
+ started: syncCycles.metric({ statistic: 'Sum', period: Duration.minutes(30) }),
1122
+ completed: syncCompletions.metric({ statistic: 'Sum', period: Duration.minutes(30) }),
1123
+ },
1124
+ period: Duration.minutes(30),
1125
+ label: 'Periods with git-sync cycles and no completed one',
1126
+ }),
1127
+ threshold: 1,
1128
+ comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
1129
+ evaluationPeriods: 2,
1130
+ datapointsToAlarm: 2,
1131
+ treatMissingData: cloudwatch.TreatMissingData.IGNORE,
1132
+ alarmDescription: `The CMS worker is running, but none of its git syncs has completed for an hour, so ` +
1133
+ `publishing and branch syncing are stalled. Check GitHub's status first: an outage ` +
1134
+ `fails every sync, and this clears on its own when syncs succeed again. Otherwise read ` +
1135
+ `the last git sync error in System health in the editor's admin panel, and the worker ` +
1136
+ `log group ${this.workerLogGroup.logGroupName}. In workerCode parameter mode, a ` +
1137
+ `template deployed ahead of its bundle also fires this until the bundle rolls.`,
1138
+ });
1139
+ this.workerSyncFailingAlarm.addAlarmAction(topicAction);
1140
+ this.workerSyncFailingAlarm.addOkAction(topicAction);
1095
1141
  const unpatchedPrefix = 'WorkerUnpatchedBoots-';
1096
1142
  const unpatchedBoots = new logs.MetricFilter(this, 'WorkerUnpatchedBoots', {
1097
1143
  logGroup: this.workerLogGroup,
@@ -68,3 +68,9 @@ export declare function workerContractShortfall(env: Readonly<Record<string, str
68
68
  * it, so the alarm misfires if the worker's text drifts from this one.
69
69
  */
70
70
  export declare const WORKER_SYNC_LOG_PHRASE = "Syncing git...";
71
+ /**
72
+ * The text of the line `syncGit()` logs when a git-sync cycle has run to its end. The
73
+ * sync-failing alarm alarms when cycles start ({@link WORKER_SYNC_LOG_PHRASE}) and none logs
74
+ * this, so it misfires if the worker's text drifts from this one.
75
+ */
76
+ export declare const WORKER_SYNC_DONE_LOG_PHRASE = "Git sync complete";
@@ -109,3 +109,9 @@ export function workerContractShortfall(env) {
109
109
  * it, so the alarm misfires if the worker's text drifts from this one.
110
110
  */
111
111
  export const WORKER_SYNC_LOG_PHRASE = 'Syncing git...';
112
+ /**
113
+ * The text of the line `syncGit()` logs when a git-sync cycle has run to its end. The
114
+ * sync-failing alarm alarms when cycles start ({@link WORKER_SYNC_LOG_PHRASE}) and none logs
115
+ * this, so it misfires if the worker's text drifts from this one.
116
+ */
117
+ export const WORKER_SYNC_DONE_LOG_PHRASE = 'Git sync complete';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopycms-cdk",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "AWS CDK constructs and EC2 worker for CanopyCMS deployment",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "peerDependencies": {
35
35
  "aws-cdk-lib": "^2.260.0",
36
36
  "constructs": "^10.0.0",
37
- "canopycms": "0.7.0"
37
+ "canopycms": "0.7.1"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "aws-cdk-lib": {
@@ -60,8 +60,8 @@
60
60
  "tsx": "^4.19.0",
61
61
  "typescript": "^5.6.3",
62
62
  "vitest": "^4.1.0",
63
- "canopycms": "0.7.0",
64
- "canopycms-auth-clerk": "0.7.0"
63
+ "canopycms-auth-clerk": "0.7.1",
64
+ "canopycms": "0.7.1"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rm -rf dist && tsc && node ../../scripts/add-js-extensions.mjs dist",
@@ -82660,7 +82660,7 @@ init_error();
82660
82660
  init_worker_status();
82661
82661
 
82662
82662
  // ../canopycms/src/version.ts
82663
- var CANOPYCMS_VERSION = "0.7.0";
82663
+ var CANOPYCMS_VERSION = "0.7.1";
82664
82664
 
82665
82665
  // ../canopycms/src/worker/schema-gate.ts
82666
82666
  import fs14 from "node:fs/promises";
@@ -86130,6 +86130,7 @@ async function syncGit(ctx) {
86130
86130
  await writeWorkerStatus(ctx.taskDir, report).catch(
86131
86131
  (writeErr) => workerLogError("Failed to write worker status:", getErrorMessage(writeErr))
86132
86132
  );
86133
+ workerLog("Git sync complete");
86133
86134
  } catch (err) {
86134
86135
  const report = ctx.ensureStatusReport();
86135
86136
  report.lastGitSyncError = {
@@ -1 +1 @@
1
- 5209ba86388c0a016a8d32d5b3f5d791460816ddad1f1b6d9757eb14196a328d index.js
1
+ 4308cf8234992d27e062ef6a026b74fa0feaa4582aab948c9906d1f9d467f3c9 index.js