Skip to content

Commit

Permalink
ws-worker: support job log level in lightning plan (#867)
Browse files Browse the repository at this point in the history
* support job log level in lightning plan

* add integration test

* add changeset

* bump lexicon too

* version: [email protected]

* package lock

* bump cli

* package lock, always package lock

* bundle lexicon

---------

Co-authored-by: Joe Clark <[email protected]>
  • Loading branch information
midigofrank and josephjclark authored Feb 19, 2025
1 parent 10e5721 commit 7cbc8cc
Show file tree
Hide file tree
Showing 22 changed files with 522 additions and 41 deletions.
7 changes: 7 additions & 0 deletions integration-tests/execute/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/integration-tests-execute

## 1.0.16

### Patch Changes

- @openfn/compiler@1.0.1
- @openfn/runtime@1.6.2

## 1.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/execute/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-execute",
"private": true,
"version": "1.0.15",
"version": "1.0.16",
"description": "Job execution tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @openfn/integration-tests-worker

## 1.0.76

### Patch Changes

- Updated dependencies [1857b46]
- @openfn/engine-multi@1.5.0
- @openfn/ws-worker@1.10.0
- @openfn/lightning-mock@2.0.31

## 1.0.75

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-worker",
"private": true,
"version": "1.0.75",
"version": "1.0.76",
"description": "Lightning WOrker integration tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
43 changes: 43 additions & 0 deletions integration-tests/worker/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,5 +974,48 @@ test.serial('Redact logs which exceed the payload limit', (t) => {
});
});

test.serial(
"Don't send job logs to stdout when job_log_level is set to none",
(t) => {
return new Promise(async (done) => {
await worker.destroy();
({ worker, engineLogger } = await createDummyWorker());

const message = 'log that will never exist';

const run = {
id: crypto.randomUUID(),
jobs: [
{
adaptor: '@openfn/[email protected]',
body: `fn((s) => { console.log("${message}"); return s;})`,
},
],
options: {
job_log_level: 'none',
},
};

lightning.once('run:complete', () => {
const jsonLogs = engineLogger._history;
// The engine logger shouldn't print out any job logs
const jobLog = jsonLogs.find((l) => l.name === 'JOB');
t.falsy(jobLog);
const jobLog2 = jsonLogs.find((l) => l.message[0] === message);
t.falsy(jobLog2);

// But it SHOULD log engine stuff
const runtimeLog = jsonLogs.find(
(l) => l.name === 'engine' && l.message[0].match(/complete workflow/i)
);
t.truthy(runtimeLog);
done();
});

lightning.enqueueRun(run);
});
}
);

// REMEMBER the default worker was destroyed at this point!
// If you want to use a worker, you'll have to create your own
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/cli

## 1.11.2

### Patch Changes

- Updated dependencies

## 1.11.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.11.1",
"version": "1.11.2",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/compiler

## 1.0.1

### Patch Changes

- Updated dependencies [1857b46]
- @openfn/lexicon@1.2.0

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/compiler",
"version": "1.0.0",
"version": "1.0.1",
"description": "Compiler and language tooling for openfn jobs.",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
13 changes: 13 additions & 0 deletions packages/engine-multi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# engine-multi

## 1.5.0

### Minor Changes

- 1857b46: Allow configuration of job log level

### Patch Changes

- Updated dependencies [1857b46]
- @openfn/lexicon@1.2.0
- @openfn/compiler@1.0.1
- @openfn/runtime@1.6.2

## 1.4.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/engine-multi",
"version": "1.4.9",
"version": "1.5.0",
"description": "Multi-process runtime engine",
"main": "dist/index.js",
"type": "module",
Expand Down
7 changes: 4 additions & 3 deletions packages/engine-multi/src/worker/thread/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import process from 'node:process';
import stringify from 'fast-safe-stringify';
import createLogger, { SanitizePolicies } from '@openfn/logger';
import type { JSONLog } from '@openfn/logger';
import type { JSONLog, LogLevel } from '@openfn/logger';

import * as workerEvents from '../events';
import { HANDLED_EXIT_CODE } from '../../events';
Expand All @@ -14,7 +14,8 @@ import serializeError from '../../util/serialize-error';
export const createLoggers = (
workflowId: string,
sanitize: SanitizePolicies = 'none',
publish?: any
publish?: any,
jobLogLevel: LogLevel = 'debug'
) => {
const log = (message: JSONLog) => {
publish(workerEvents.LOG, {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const createLoggers = (

const jobLogger = createLogger('JOB', {
logger: emitter,
level: 'debug',
level: jobLogLevel,
json: true,
sanitize,
});
Expand Down
9 changes: 6 additions & 3 deletions packages/engine-multi/src/worker/thread/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import run from '@openfn/runtime';
import type { NotifyEvents } from '@openfn/runtime';
import type { ExecutionPlan, State } from '@openfn/lexicon';
import type { SanitizePolicies } from '@openfn/logger';
import type { LogLevel, SanitizePolicies } from '@openfn/logger';

import { register, publish } from './runtime';
import { execute, createLoggers } from './helpers';
Expand All @@ -15,6 +15,7 @@ export type RunOptions = {
whitelist?: RegExp[];
sanitize: SanitizePolicies;
statePropsToRemove?: string[];
jobLogLevel?: LogLevel;
};

const eventMap = {
Expand All @@ -26,11 +27,13 @@ const eventMap = {

register({
run: (plan: ExecutionPlan, input: State, runOptions: RunOptions) => {
const { repoDir, whitelist, sanitize, statePropsToRemove } = runOptions;
const { repoDir, whitelist, sanitize, statePropsToRemove, jobLogLevel } =
runOptions;
const { logger, jobLogger, adaptorLogger } = createLoggers(
plan.id!,
sanitize,
publish
publish,
jobLogLevel
);

// Save the debug function so that we can use it
Expand Down
6 changes: 6 additions & 0 deletions packages/lexicon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# lexicon

## 1.2.0

### Minor Changes

- 1857b46: Allow configuration of job log level

## 1.1.0

### Minor Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/lexicon/lightning.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SanitizePolicies } from '@openfn/logger';
import type { LogLevel, SanitizePolicies } from '@openfn/logger';
import { LegacyJob, State } from './core';

export const API_VERSION: number;
Expand Down Expand Up @@ -50,6 +50,7 @@ export type LightningPlanOptions = {

run_memory_limit_mb?: number;
payload_limit_mb?: number;
job_log_level?: LogLevel;
};

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/lexicon/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "@openfn/lexicon",
"version": "1.1.0",
"version": "1.2.0",
"description": "Central repo of names and type definitions",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
"type": "module",
"main": "index.js",
"scripts": {
"pack": "pnpm pack --pack-destination ../../dist"
},
"exports": {
".": {
"import": {
Expand Down
9 changes: 9 additions & 0 deletions packages/lightning-mock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @openfn/lightning-mock

## 2.0.31

### Patch Changes

- Updated dependencies [1857b46]
- @openfn/engine-multi@1.5.0
- @openfn/lexicon@1.2.0
- @openfn/runtime@1.6.2

## 2.0.30

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lightning-mock",
"version": "2.0.30",
"version": "2.0.31",
"private": true,
"description": "A mock Lightning server",
"main": "dist/index.js",
Expand Down
13 changes: 13 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# ws-worker

## 1.10.0

### Minor Changes

- 1857b46: Allow configuration of job log level

### Patch Changes

- Updated dependencies [1857b46]
- @openfn/engine-multi@1.5.0
- @openfn/lexicon@1.2.0
- @openfn/runtime@1.6.2

## 1.9.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.9.2",
"version": "1.10.0",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down
5 changes: 5 additions & 0 deletions packages/ws-worker/src/util/convert-lightning-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
WorkflowOptions,
Lazy,
} from '@openfn/lexicon';
import type { LogLevel } from '@openfn/logger';
import { LightningPlan, LightningEdge } from '@openfn/lexicon/lightning';
import { ExecuteOptions } from '@openfn/engine-multi';
import { getNameAndVersion } from '@openfn/runtime';
Expand Down Expand Up @@ -46,6 +47,7 @@ export type WorkerRunOptions = ExecuteOptions & {
// Defaults to true - must be explicity false to stop dataclips being sent
outputDataclips?: boolean;
payloadLimitMb?: number;
jobLogLevel?: LogLevel;
};

type ConversionOptions = {
Expand Down Expand Up @@ -124,6 +126,9 @@ export default (
if ('output_dataclips' in run.options) {
engineOpts.outputDataclips = run.options.output_dataclips;
}
if ('job_log_level' in run.options) {
engineOpts.jobLogLevel = run.options.job_log_level;
}
}

const plan: Partial<ExecutionPlan> = {
Expand Down
Loading

0 comments on commit 7cbc8cc

Please sign in to comment.