pepr 0.43.0 → 0.44.0-nightly.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.
package/dist/lib.js CHANGED
@@ -242,6 +242,36 @@ var metricsCollector = new MetricsCollector("pepr");
242
242
  var import_fast_json_patch = __toESM(require("fast-json-patch"));
243
243
  var import_ramda4 = require("ramda");
244
244
 
245
+ // src/lib/telemetry/timeUtils.ts
246
+ var getNow = () => performance.now();
247
+
248
+ // src/lib/telemetry/webhookTimeouts.ts
249
+ var MeasureWebhookTimeout = class {
250
+ #startTime = null;
251
+ #webhookType;
252
+ timeout = 0;
253
+ constructor(webhookType) {
254
+ this.#webhookType = webhookType;
255
+ metricsCollector.addCounter(`${webhookType}_timeouts`, `Number of ${webhookType} webhook timeouts`);
256
+ }
257
+ start(timeout = 10) {
258
+ this.#startTime = getNow();
259
+ this.timeout = timeout;
260
+ logger_default.info(`Starting timer at ${this.#startTime}`);
261
+ }
262
+ stop() {
263
+ if (this.#startTime === null) {
264
+ throw new Error("Timer was not started before calling stop.");
265
+ }
266
+ const elapsedTime = getNow() - this.#startTime;
267
+ logger_default.info(`Webhook ${this.#startTime} took ${elapsedTime}ms`);
268
+ this.#startTime = null;
269
+ if (elapsedTime > this.timeout) {
270
+ metricsCollector.incCounter(`${this.#webhookType}_timeouts`);
271
+ }
272
+ }
273
+ };
274
+
245
275
  // src/lib/filter/adjudicators/adjudicators.ts
246
276
  var import_ramda = require("ramda");
247
277
  var declaredOperation = (0, import_ramda.pipe)(
@@ -748,6 +778,8 @@ async function processRequest(bindable, wrapped, response) {
748
778
  return { wrapped, response };
749
779
  }
750
780
  async function mutateProcessor(config, capabilities, req, reqMetadata) {
781
+ const webhookTimer = new MeasureWebhookTimeout("mutate" /* MUTATE */);
782
+ webhookTimer.start(config.webhookTimeout);
751
783
  let response = {
752
784
  uid: req.uid,
753
785
  warnings: [],
@@ -798,6 +830,12 @@ async function mutateProcessor(config, capabilities, req, reqMetadata) {
798
830
  }
799
831
  const transformed = reencodeData(wrapped, decoded.skipped);
800
832
  const patches = import_fast_json_patch.default.compare(req.object, transformed);
833
+ updateResponsePatchAndWarnings(patches, response);
834
+ logger_default.debug({ ...reqMetadata, patches }, `Patches generated`);
835
+ webhookTimer.stop();
836
+ return response;
837
+ }
838
+ function updateResponsePatchAndWarnings(patches, response) {
801
839
  if (patches.length > 0) {
802
840
  response.patchType = "JSONPatch";
803
841
  response.patch = base64Encode(JSON.stringify(patches));
@@ -805,8 +843,6 @@ async function mutateProcessor(config, capabilities, req, reqMetadata) {
805
843
  if (response.warnings && response.warnings.length < 1) {
806
844
  delete response.warnings;
807
845
  }
808
- logger_default.debug({ ...reqMetadata, patches }, `Patches generated`);
809
- return response;
810
846
  }
811
847
 
812
848
  // src/lib/validate-request.ts
@@ -918,10 +954,11 @@ async function processRequest2(binding, actionMetadata, peprValidateRequest) {
918
954
  }
919
955
  }
920
956
  async function validateProcessor(config, capabilities, req, reqMetadata) {
957
+ const webhookTimer = new MeasureWebhookTimeout("validate" /* VALIDATE */);
958
+ webhookTimer.start(config.webhookTimeout);
921
959
  const wrapped = new PeprValidateRequest(req);
922
960
  const response = [];
923
- const isSecret = req.kind.version === "v1" && req.kind.kind === "Secret";
924
- if (isSecret) {
961
+ if (req.kind.version === "v1" && req.kind.kind === "Secret") {
925
962
  convertFromBase64Map(wrapped.Raw);
926
963
  }
927
964
  logger_default.info(reqMetadata, `Processing validation request`);
@@ -945,6 +982,7 @@ async function validateProcessor(config, capabilities, req, reqMetadata) {
945
982
  response.push(resp);
946
983
  }
947
984
  }
985
+ webhookTimer.stop();
948
986
  return response;
949
987
  }
950
988