-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rolling-file appender to core logging #84735
Merged
pgayvallet
merged 28 commits into
elastic:master
from
pgayvallet:kbn-56291-rolling-file-appender
Dec 10, 2020
Merged
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1ae0289
You need to start somewhere
pgayvallet 864c587
revert comment
pgayvallet 004436e
rename default strategy to numeric
pgayvallet f59bca6
add some tests
pgayvallet b5f098f
fix some tests
pgayvallet d5d3fd1
update documentation
pgayvallet a56c61e
update generated doc
pgayvallet 6b6fc49
change applyBaseConfig to be async
pgayvallet a04d0c7
fix integ tests
pgayvallet 91f1420
add integration tests
pgayvallet 8165f35
some renames
pgayvallet 30ba0d4
more tests
pgayvallet 1077f30
Merge remote-tracking branch 'upstream/master' into kbn-56291-rolling…
pgayvallet 8f4581b
more tests
pgayvallet b226a63
nits on README
pgayvallet 2634c76
some self review
pgayvallet a9e21d5
doc nits
pgayvallet 3e740c6
self review
pgayvallet 02adb81
Merge remote-tracking branch 'upstream/master' into kbn-56291-rolling…
pgayvallet 6694e24
use `escapeRegExp` from lodash
pgayvallet c72c20f
Merge remote-tracking branch 'upstream/master' into kbn-56291-rolling…
pgayvallet 3aa0bc7
address some review comments
pgayvallet 2cf122f
a few more nits
pgayvallet a8d26ef
extract `isDevCliParent` check outside of LoggingSystem.upgrade
pgayvallet e76a089
log errors from context
pgayvallet bf0e390
Merge remote-tracking branch 'upstream/master' into kbn-56291-rolling…
pgayvallet fc190b9
Merge remote-tracking branch 'upstream/master' into kbn-56291-rolling…
pgayvallet bbb96f4
add defaults for policy/strategy
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { PublicMethodsOf } from '@kbn/utility-types'; | ||
import type { Layout } from '@kbn/logging'; | ||
import type { RollingFileContext } from './rolling_file_context'; | ||
import type { RollingFileManager } from './rolling_file_manager'; | ||
import type { TriggeringPolicy } from './policies/policy'; | ||
import type { RollingStrategy } from './strategies/strategy'; | ||
|
||
const createContextMock = (filePath: string) => { | ||
const mock: jest.Mocked<RollingFileContext> = { | ||
currentFileSize: 0, | ||
currentFileTime: 0, | ||
filePath, | ||
refreshFileInfo: jest.fn(), | ||
}; | ||
return mock; | ||
}; | ||
|
||
const createStrategyMock = () => { | ||
const mock: jest.Mocked<RollingStrategy> = { | ||
rollout: jest.fn(), | ||
}; | ||
return mock; | ||
}; | ||
|
||
const createPolicyMock = () => { | ||
const mock: jest.Mocked<TriggeringPolicy> = { | ||
isTriggeringEvent: jest.fn(), | ||
}; | ||
return mock; | ||
}; | ||
|
||
const createLayoutMock = () => { | ||
const mock: jest.Mocked<Layout> = { | ||
format: jest.fn(), | ||
}; | ||
return mock; | ||
}; | ||
|
||
const createFileManagerMock = () => { | ||
const mock: jest.Mocked<PublicMethodsOf<RollingFileManager>> = { | ||
write: jest.fn(), | ||
closeStream: jest.fn(), | ||
}; | ||
return mock; | ||
}; | ||
|
||
export const rollingFileAppenderMocks = { | ||
createContext: createContextMock, | ||
createStrategy: createStrategyMock, | ||
createPolicy: createPolicyMock, | ||
createLayout: createLayoutMock, | ||
createFileManager: createFileManagerMock, | ||
}; |
63 changes: 63 additions & 0 deletions
63
src/core/server/logging/appenders/rolling_file/policies/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { assertNever } from '@kbn/std'; | ||
import { TriggeringPolicy } from './policy'; | ||
import { RollingFileContext } from '../rolling_file_context'; | ||
import { | ||
sizeLimitTriggeringPolicyConfigSchema, | ||
SizeLimitTriggeringPolicyConfig, | ||
SizeLimitTriggeringPolicy, | ||
} from './size_limit'; | ||
import { | ||
TimeIntervalTriggeringPolicyConfig, | ||
TimeIntervalTriggeringPolicy, | ||
timeIntervalTriggeringPolicyConfigSchema, | ||
} from './time_interval'; | ||
|
||
export { TriggeringPolicy } from './policy'; | ||
|
||
/** | ||
* Any of the existing policy's configuration | ||
* | ||
* See {@link SizeLimitTriggeringPolicyConfig} and {@link TimeIntervalTriggeringPolicyConfig} | ||
*/ | ||
export type TriggeringPolicyConfig = | ||
| SizeLimitTriggeringPolicyConfig | ||
| TimeIntervalTriggeringPolicyConfig; | ||
|
||
export const triggeringPolicyConfigSchema = schema.oneOf([ | ||
sizeLimitTriggeringPolicyConfigSchema, | ||
timeIntervalTriggeringPolicyConfigSchema, | ||
]); | ||
|
||
export const createTriggeringPolicy = ( | ||
config: TriggeringPolicyConfig, | ||
context: RollingFileContext | ||
): TriggeringPolicy => { | ||
switch (config.kind) { | ||
case 'size-limit': | ||
return new SizeLimitTriggeringPolicy(config, context); | ||
case 'time-interval': | ||
return new TimeIntervalTriggeringPolicy(config, context); | ||
default: | ||
return assertNever(config); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/core/server/logging/appenders/rolling_file/policies/policy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { LogRecord } from '@kbn/logging'; | ||
|
||
/** | ||
* A policy used to determinate when a rollout should be performed. | ||
*/ | ||
export interface TriggeringPolicy { | ||
/** | ||
* Determines whether a rollover should occur before logging given record. | ||
**/ | ||
isTriggeringEvent(record: LogRecord): boolean; | ||
pgayvallet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's align our naming with one Elaticsearch uses?
size-limit
-->SizeBasedTriggeringPolicy
We have another issue to unify config keys #57551, but probably you can change the newly added keys to comply with ES schema from the very beginning (policy --> policies)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, IDK about doing it directly in this PR instead of globalizing all the required changes in #57551 tbh. We would be introducing inconsistencies in our own logging API, which is imho probably worse.
In example:
All our other 'types' are lowercase, dash separated. Having a mix of both seems wrong
In log4j configuration ,
policies
is a map (they accept multiple policies). we don't ATM (and TIL by looking at log4j's code, it would requires significant work, their code is a patchwork of hacks and side effects to support that...) I feel like usingpolicies
could be misleading as the user may try to use an array instead of an object in the configuration?Also, note that if we want to align the naming, there are other things to change:
kind: size-limit
, in log4j, it'stype
, notkind
. However all our other logging configuration structures are using thekind
naming, so this would introduce yet more divergence in our own logging config API.Not opposed to do it right now if you think it's still better though, just tell me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, #57551 should fix it.
Just curious, what
types
do you mean? I'm fine if we postpone this change till #57551 also it means that we should do that before removing the legacy log rotation @joshdover any objections?