-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* You need to start somewhere * revert comment * rename default strategy to numeric * add some tests * fix some tests * update documentation * update generated doc * change applyBaseConfig to be async * fix integ tests * add integration tests * some renames * more tests * more tests * nits on README * some self review * doc nits * self review * use `escapeRegExp` from lodash * address some review comments * a few more nits * extract `isDevCliParent` check outside of LoggingSystem.upgrade * log errors from context * add defaults for policy/strategy
- Loading branch information
1 parent
207fa22
commit 48a2063
Showing
43 changed files
with
2,889 additions
and
57 deletions.
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, | ||
}; |
70 changes: 70 additions & 0 deletions
70
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,70 @@ | ||
/* | ||
* 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 moment from 'moment-timezone'; | ||
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; | ||
|
||
const defaultPolicy: TimeIntervalTriggeringPolicyConfig = { | ||
kind: 'time-interval', | ||
interval: moment.duration(24, 'hour'), | ||
modulate: true, | ||
}; | ||
|
||
export const triggeringPolicyConfigSchema = schema.oneOf( | ||
[sizeLimitTriggeringPolicyConfigSchema, timeIntervalTriggeringPolicyConfigSchema], | ||
{ defaultValue: defaultPolicy } | ||
); | ||
|
||
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); | ||
} | ||
}; |
Oops, something went wrong.