-
Notifications
You must be signed in to change notification settings - Fork 916
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
[OSD Availability] Prevent OSD process crashes when disk is full #6733
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a18203
prevent crash when disk full
Flyingliuhub 61e4de9
change verbose to false
Flyingliuhub b159b5f
add changeset file
Flyingliuhub 157d8a8
update changeset contexts
Flyingliuhub de310cf
Merge branch 'main' into asynlogger
ZilongX 893f6db
change feature flag name
Flyingliuhub fc36bb8
Merge branch 'main' into asynlogger
Flyingliuhub 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- [OSD Availability] Prevent OSD process crashes when disk is full ([#6733](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6733)) |
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,148 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import os from 'os'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import stripAnsi from 'strip-ansi'; | ||
import { getLoggerStream, onFinished } from './log_reporter'; | ||
|
||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
describe('getLoggerStream', () => { | ||
it('should log to stdout when the json config is set to false', async () => { | ||
const lines = []; | ||
const origWrite = process.stdout.write; | ||
process.stdout.write = (buffer) => { | ||
lines.push(stripAnsi(buffer.toString()).trim()); | ||
return true; | ||
}; | ||
|
||
const loggerStream = getLoggerStream({ | ||
config: { | ||
json: false, | ||
dest: 'stdout', | ||
filter: {}, | ||
}, | ||
events: { log: '*' }, | ||
}); | ||
|
||
loggerStream.end({ event: 'log', tags: ['foo'], data: 'test data' }); | ||
|
||
await sleep(500); | ||
|
||
process.stdout.write = origWrite; | ||
expect(lines.length).toBe(1); | ||
expect(lines[0]).toMatch(/^log \[[^\]]*\] \[foo\] test data$/); | ||
}); | ||
|
||
it('should log to stdout when the json config is set to true', async () => { | ||
const lines = []; | ||
const origWrite = process.stdout.write; | ||
process.stdout.write = (buffer) => { | ||
lines.push(JSON.parse(buffer.toString().trim())); | ||
return true; | ||
}; | ||
|
||
const loggerStream = getLoggerStream({ | ||
config: { | ||
json: true, | ||
dest: 'stdout', | ||
filter: {}, | ||
}, | ||
events: { log: '*' }, | ||
}); | ||
|
||
loggerStream.end({ event: 'log', tags: ['foo'], data: 'test data' }); | ||
|
||
await sleep(500); | ||
|
||
process.stdout.write = origWrite; | ||
expect(lines.length).toBe(1); | ||
expect(lines[0]).toMatchObject({ | ||
type: 'log', | ||
tags: ['foo'], | ||
message: 'test data', | ||
}); | ||
}); | ||
|
||
it('should log to custom file when the json config is set to false', async () => { | ||
const dir = os.tmpdir(); | ||
const logfile = `dest-${Date.now()}.log`; | ||
const dest = path.join(dir, logfile); | ||
|
||
const loggerStream = getLoggerStream({ | ||
config: { | ||
json: false, | ||
dest, | ||
filter: {}, | ||
}, | ||
events: { log: '*' }, | ||
}); | ||
|
||
loggerStream.end({ event: 'log', tags: ['foo'], data: 'test data' }); | ||
|
||
await sleep(500); | ||
|
||
const lines = stripAnsi(fs.readFileSync(dest, { encoding: 'utf8' })) | ||
.trim() | ||
.split(os.EOL); | ||
expect(lines.length).toBe(1); | ||
expect(lines[0]).toMatch(/^log \[[^\]]*\] \[foo\] test data$/); | ||
}); | ||
|
||
it('should log to custom file when the json config is set to true and ignoreEnospcError', async () => { | ||
const dir = os.tmpdir(); | ||
const logfile = `dest-${Date.now()}.log`; | ||
const dest = path.join(dir, logfile); | ||
|
||
const loggerStream = getLoggerStream({ | ||
config: { | ||
json: true, | ||
dest, | ||
ignoreEnospcError: true, | ||
filter: {}, | ||
}, | ||
events: { log: '*' }, | ||
}); | ||
|
||
loggerStream.end({ event: 'log', tags: ['foo'], data: 'test data' }); | ||
|
||
await sleep(500); | ||
|
||
const lines = fs | ||
.readFileSync(dest, { encoding: 'utf8' }) | ||
.trim() | ||
.split(os.EOL) | ||
.map((data) => JSON.parse(data)); | ||
expect(lines.length).toBe(1); | ||
expect(lines[0]).toMatchObject({ | ||
type: 'log', | ||
tags: ['foo'], | ||
message: 'test data', | ||
}); | ||
}); | ||
|
||
it('should handle ENOSPC error when disk full', () => { | ||
const error = { code: 'ENOSPC', stack: 'Error stack trace' }; | ||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); | ||
|
||
expect(() => { | ||
onFinished(error); | ||
}).not.toThrow(); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith('Error in logging pipeline:', 'Error stack trace'); | ||
|
||
consoleErrorSpy.mockRestore(); | ||
}); | ||
|
||
it('should throw error for non-ENOSPC error', () => { | ||
const error = { message: 'non-ENOSPC error', code: 'OTHER', stack: 'Error stack trace' }; | ||
|
||
expect(() => { | ||
onFinished(error); | ||
}).toThrowError('non-ENOSPC 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.
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.
will look into later but probably easier to ask:
does pipeline call dest end automatically? or does onfinished get invoked and then we should check if error.code === 'end' and then call dest.end()
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.
Yes, pipeline() automatically handles closing the streams once the pipeline is finished or if an error occurs during processing. This automatic cleanup ensures that resources associated with the streams are properly released when they are no longer needed. This behavior helps prevent memory leaks and ensures efficient resource usage in Node.js applications
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.
dang. could do you mind opening an issue? i feel like this legacy stuff needs to go and we updated to use the non legacy, or at least be updated to utilize the non-legacy to modern Node APIs.
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.
I will open an new issue for it.