Skip to content

Commit f9f28dd

Browse files
committed
Remove MetaRewritePolicy 'add' mode.
1 parent dcee4b9 commit f9f28dd

File tree

3 files changed

+12
-102
lines changed

3 files changed

+12
-102
lines changed

src/core/server/logging/README.mdx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ The `meta` rewrite policy can read and modify any data contained in the
317317

318318
Meta policies must specify one of three modes, which indicate which action
319319
to perform on the configured properties:
320-
- `add` creates a new property at the provided `path`, skipping properties which already exist.
321-
- `update` updates an existing property at the provided `path` without creating new properties.
320+
- `update` updates an existing property at the provided `path`.
322321
- `remove` removes an existing property at the provided `path`.
323322

324323
The `properties` are listed as a `path` and `value` pair, where `path` is
@@ -348,25 +347,23 @@ reference. Each rewrite appender is applied sequentially (one after the other).
348347
```yaml
349348
logging:
350349
appenders:
351-
remove-stuff:
350+
remove-request-headers:
352351
type: rewrite
353-
appenders: [add-stuff] # redirect to the next rewrite appender
352+
appenders: [censor-response-headers] # redirect to the next rewrite appender
354353
policy:
355354
type: meta
356355
mode: remove
357356
properties:
358-
- path: "http.request.headers.authorization"
359-
- path: "http.request.headers.cookie"
360-
- path: "http.request.headers.set-cookie"
361-
add-stuff:
357+
- path: "http.request.headers" # remove all request headers
358+
censor-response-headers:
362359
type: rewrite
363360
appenders: [console] # output to console
364361
policy:
365362
type: meta
366-
mode: add
363+
mode: update
367364
properties:
368-
- path: "hello"
369-
value: "world" # creates { hello: 'world' } at the LogMeta root
365+
- path: "http.response.headers.set-cookie"
366+
value: "[REDACTED]"
370367
```
371368

372369
#### Complete Example

src/core/server/logging/appenders/rewrite/policies/meta/meta_policy.test.ts

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -24,80 +24,6 @@ describe('MetaRewritePolicy', () => {
2424
meta,
2525
});
2626

27-
describe('mode: add', () => {
28-
it('adds new properties to LogMeta', () => {
29-
const policy = createPolicy('add', [{ path: 'foo', value: 'bar' }]);
30-
const log = createLogRecord();
31-
expect(policy.rewrite(log).meta).toMatchInlineSnapshot(`
32-
Object {
33-
"foo": "bar",
34-
}
35-
`);
36-
});
37-
38-
it('adds nested properties to LogMeta', () => {
39-
const policy = createPolicy('add', [
40-
{ path: 'a.b', value: 'foo' },
41-
{ path: 'a.c[1]', value: 'bar' },
42-
]);
43-
const log = createLogRecord();
44-
expect(policy.rewrite(log).meta).toMatchInlineSnapshot(`
45-
Object {
46-
"a": Object {
47-
"b": "foo",
48-
"c": Array [
49-
undefined,
50-
"bar",
51-
],
52-
},
53-
}
54-
`);
55-
});
56-
57-
it('handles string, number, boolean, null', () => {
58-
const policy = createPolicy('add', [
59-
{ path: 'boolean', value: false },
60-
{ path: 'null', value: null },
61-
{ path: 'number', value: 123 },
62-
{ path: 'string', value: 'hi' },
63-
]);
64-
const log = createLogRecord();
65-
expect(policy.rewrite(log).meta).toMatchInlineSnapshot(`
66-
Object {
67-
"boolean": false,
68-
"null": null,
69-
"number": 123,
70-
"string": "hi",
71-
}
72-
`);
73-
});
74-
75-
it('does not overwrite properties which already exist', () => {
76-
const policy = createPolicy('add', [
77-
{ path: 'a.b', value: 'foo' },
78-
{ path: 'a.c', value: 'bar' },
79-
]);
80-
const log = createLogRecord({ a: { b: 'existing meta' } });
81-
const { meta } = policy.rewrite(log);
82-
expect(meta!.a.b).toBe('existing meta');
83-
expect(meta!.a.c).toBe('bar');
84-
});
85-
86-
it('does not touch anything outside of LogMeta', () => {
87-
const policy = createPolicy('add', [{ path: 'message', value: 'bar' }]);
88-
const message = Symbol();
89-
expect(policy.rewrite(({ message } as unknown) as LogRecord).message).toBe(message);
90-
expect(policy.rewrite(({ message } as unknown) as LogRecord)).toMatchInlineSnapshot(`
91-
Object {
92-
"message": Symbol(),
93-
"meta": Object {
94-
"message": "bar",
95-
},
96-
}
97-
`);
98-
});
99-
});
100-
10127
describe('mode: update', () => {
10228
it('updates existing properties in LogMeta', () => {
10329
const log = createLogRecord({ a: 'before' });

src/core/server/logging/appenders/rewrite/policies/meta/meta_policy.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ export interface MetaRewritePolicyConfig {
2323

2424
/**
2525
* The 'mode' specifies what action to perform on the specified properties.
26-
* - 'add' creates a new property at the provided 'path', skipping properties which already exist.
27-
* - 'update' updates an existing property at the provided 'path' without creating new properties.
26+
* - 'update' updates an existing property at the provided 'path'.
2827
* - 'remove' removes an existing property at the provided 'path'.
2928
*/
30-
mode: 'add' | 'remove' | 'update';
29+
mode: 'remove' | 'update';
3130

3231
/**
33-
* The properties to add, remove, or update.
32+
* The properties to modify.
3433
*
3534
* @remarks
3635
* Each provided 'path' is relative to the record's {@link LogMeta}.
@@ -41,7 +40,7 @@ export interface MetaRewritePolicyConfig {
4140

4241
export const metaRewritePolicyConfigSchema = schema.object({
4342
type: schema.literal('meta'),
44-
mode: schema.oneOf([schema.literal('add'), schema.literal('update'), schema.literal('remove')], {
43+
mode: schema.oneOf([schema.literal('update'), schema.literal('remove')], {
4544
defaultValue: 'update',
4645
}),
4746
properties: schema.arrayOf(
@@ -63,8 +62,6 @@ export class MetaRewritePolicy implements RewritePolicy {
6362

6463
rewrite(record: LogRecord): LogRecord {
6564
switch (this.config.mode) {
66-
case 'add':
67-
return this.add(record);
6865
case 'update':
6966
return this.update(record);
7067
case 'remove':
@@ -74,16 +71,6 @@ export class MetaRewritePolicy implements RewritePolicy {
7471
}
7572
}
7673

77-
private add(record: LogRecord) {
78-
for (const { path, value } of this.config.properties) {
79-
if (has(record, `meta.${path}`)) {
80-
continue; // don't overwrite properties which already exist
81-
}
82-
set(record, `meta.${path}`, value);
83-
}
84-
return record;
85-
}
86-
8774
private update(record: LogRecord) {
8875
for (const { path, value } of this.config.properties) {
8976
if (!has(record, `meta.${path}`)) {

0 commit comments

Comments
 (0)