-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ResponseOps][Alerting] Alerting v2: Create basic services #248306
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
Merged
cnasikas
merged 12 commits into
elastic:alerting_v2
from
cnasikas:alerting_v2_basic_services
Jan 12, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
19de94e
Create basic services
cnasikas 13cd836
Instatiate the services in the plugin
cnasikas 64e54e5
Changes from node scripts/lint_ts_projects --fix
kibanamachine 587c159
Switch to factories
cnasikas 93d1dc0
Merge branch 'alerting_v2_basic_services' of github.com:cnasikas/kiba…
cnasikas ad0b2ae
Remove factories and use inversify
cnasikas d8ed208
Rename di folder
cnasikas f9e0c24
Merge branch 'alerting_v2' into alerting_v2_basic_services
cnasikas e417b14
Better types
cnasikas 802a9ac
Use generics for the Storage service
cnasikas 401e440
Better logging in storage service
cnasikas 280fb89
Better debug in query service
cnasikas 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
...form/plugins/shared/alerting_v2/server/lib/services/logger_service/logger_service.test.ts
This file contains hidden or 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 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { Logger } from '@kbn/core/server'; | ||
| import { loggerMock } from '@kbn/logging-mocks'; | ||
| import { LoggerService } from './logger_service'; | ||
|
|
||
| describe('LoggerService', () => { | ||
| let mockLogger: jest.Mocked<Logger>; | ||
| let loggerService: LoggerService; | ||
|
|
||
| beforeEach(() => { | ||
| mockLogger = loggerMock.create(); | ||
| loggerService = new LoggerService(mockLogger); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('debug', () => { | ||
| it('should call logger.debug with the message', () => { | ||
| const message = 'Test debug message'; | ||
|
|
||
| loggerService.debug({ message }); | ||
|
|
||
| expect(mockLogger.debug).toHaveBeenCalledTimes(1); | ||
| expect(mockLogger.debug).toHaveBeenCalledWith(message); | ||
| }); | ||
| }); | ||
|
|
||
| describe('error', () => { | ||
| it('should call logger.error with error message and EcsError when only error is provided', () => { | ||
| const error = new Error('Test error'); | ||
|
|
||
| loggerService.error({ error }); | ||
|
|
||
| expect(mockLogger.error).toHaveBeenCalledTimes(1); | ||
| expect(mockLogger.error).toHaveBeenCalledWith(error.message, { | ||
| error: { | ||
| code: 'UNKNOWN_ERROR', | ||
| message: error.message, | ||
| stack_trace: error.stack, | ||
| type: 'Error', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should use the code and the type if provided', () => { | ||
| const error = new Error('Test error'); | ||
| const code = 'CUSTOM_ERROR_CODE'; | ||
| const type = 'CustomErrorType'; | ||
|
|
||
| loggerService.error({ error, code, type }); | ||
|
|
||
| expect(mockLogger.error).toHaveBeenCalledWith(error.message, { | ||
| error: { | ||
| code, | ||
| message: error.message, | ||
| stack_trace: error.stack, | ||
| type, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
62 changes: 62 additions & 0 deletions
62
.../platform/plugins/shared/alerting_v2/server/lib/services/logger_service/logger_service.ts
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
| import type { Logger, LogMessageSource } from '@kbn/logging'; | ||
| import { Logger as BaseLogger } from '@kbn/core-di'; | ||
| import type { EcsError } from '@elastic/ecs'; | ||
|
|
||
| interface DebugParams { | ||
| message: LogMessageSource; | ||
| } | ||
|
|
||
| interface InfoParams { | ||
| message: LogMessageSource; | ||
| } | ||
|
|
||
| interface WarnParams { | ||
| message: LogMessageSource; | ||
| } | ||
|
|
||
| interface ErrorParams { | ||
| error: Error; | ||
| code?: string; | ||
| type?: string; | ||
| } | ||
|
|
||
| @injectable() | ||
| export class LoggerService { | ||
| constructor(@inject(BaseLogger) private readonly logger: Logger) {} | ||
|
|
||
| public debug({ message }: DebugParams): void { | ||
| this.logger.debug(message); | ||
| } | ||
|
|
||
| public error({ error, code, type }: ErrorParams): void { | ||
| const ecsError = this.buildError({ error, code, type }); | ||
| this.logger.error(error.message, { | ||
| error: ecsError, | ||
| }); | ||
| } | ||
|
|
||
| public info({ message }: InfoParams): void { | ||
| this.logger.info(message); | ||
| } | ||
|
|
||
| public warn({ message }: WarnParams): void { | ||
| this.logger.warn(message); | ||
| } | ||
|
|
||
| private buildError({ error, code, type }: ErrorParams): EcsError { | ||
| return { | ||
| code: code ?? 'UNKNOWN_ERROR', | ||
| message: error.message, | ||
| stack_trace: error.stack, | ||
| type: type ?? 'Error', | ||
| }; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.