Specify custom directory for storing evaluation logs#863
Conversation
| if (fs.existsSync(this.config.customLogDirectory) && fs.statSync(this.config.customLogDirectory).isDirectory()) { | ||
| storagePath = this.config.customLogDirectory; | ||
| isCustomLogDirectory = true; | ||
| } else if (this.config.customLogDirectory) { | ||
| helpers.showAndLogErrorMessage(`${this.config.customLogDirectory} is not a valid directory. Logs will be stored in a temporary workspace directory instead.`); | ||
| } |
There was a problem hiding this comment.
If the custom path doesn't exist, maybe you can create it (with an info message). I think it's only an error if it already exists, but isn't a file.
There was a problem hiding this comment.
I made an attempt in b7897b0, which seems to do the right thing, but any tips on syntax/fixes are very welcome 😄
|
Looks good so far. Next step is to look at the tests for logging: you'll need to update the tests that use loggers to pass in the new boolean flags you introduced, and check their behaviour in each case. |
892a125 to
cd39ede
Compare
| it('should delete an existing folder when setting the log storage path', async () => { | ||
| fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); | ||
| logger.init(tempFolders.storagePath.name); | ||
| logger.setLogStoragePath(tempFolders.storagePath.name, false); | ||
| // should be empty dir | ||
|
|
||
| const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); | ||
| // TODO: Why does this test pass? I'd expect the length to be 0 if it's correctly deleted the existing folder. | ||
| expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); | ||
| }); |
There was a problem hiding this comment.
I couldn't work out why this test passes with "length equal to 1". Can someone explain? I might be misunderstanding what it's doing... 👀
There was a problem hiding this comment.
Is it possible fs.remove is not working because the directory is not empty? Try setting a breakpoint on line 129 and step through to see what happens and what is deleted.
There was a problem hiding this comment.
Also, I wonder if that method isn't completely synchronous. You can try addinga a waitABit call in between and see what happens.
There was a problem hiding this comment.
Oh the sync/async might be it. I was also baffled by why the existing test worked.
| let isCustomLogDirectory = false; | ||
| if (this.config.customLogDirectory) { | ||
| try { | ||
| fs.mkdirSync(this.config.customLogDirectory); |
There was a problem hiding this comment.
This method needs to be async
| fs.mkdirSync(this.config.customLogDirectory); | |
| await fs.mkdir(this.config.customLogDirectory); |
| it('should delete an existing folder when setting the log storage path', async () => { | ||
| fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); | ||
| logger.init(tempFolders.storagePath.name); | ||
| logger.setLogStoragePath(tempFolders.storagePath.name, false); | ||
| // should be empty dir | ||
|
|
||
| const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); | ||
| // TODO: Why does this test pass? I'd expect the length to be 0 if it's correctly deleted the existing folder. | ||
| expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); | ||
| }); |
There was a problem hiding this comment.
Is it possible fs.remove is not working because the directory is not empty? Try setting a breakpoint on line 129 and step through to see what happens and what is deleted.
| it('should delete an existing folder when setting the log storage path', async () => { | ||
| fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); | ||
| logger.init(tempFolders.storagePath.name); | ||
| logger.setLogStoragePath(tempFolders.storagePath.name, false); | ||
| // should be empty dir | ||
|
|
||
| const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); | ||
| // TODO: Why does this test pass? I'd expect the length to be 0 if it's correctly deleted the existing folder. | ||
| expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); | ||
| }); |
There was a problem hiding this comment.
Also, I wonder if that method isn't completely synchronous. You can try addinga a waitABit call in between and see what happens.
| fs.remove(this.additionalLogLocationPath); | ||
| this.isCustomLogDirectory = isCustomLogDirectory; | ||
|
|
||
| if (!this.isCustomLogDirectory) { |
There was a problem hiding this comment.
So, what this means is whenever someone changes the query server logs from the default to a custom location, then the old logs are deleted. And if they switch back, there won't be any logs at all. Maybe that's ok.
8d711c6 to
8e4930c
Compare
aeisenberg
left a comment
There was a problem hiding this comment.
One last change and then
.
(I haven't got the error handling to work asynchronously, so I stuck with `mkdirSync` for now)
1637a22 to
43fba35
Compare
Will fix #820.
Checklist
@github/docs-content-codeqlhas been cc'd in all issues for UI or other user-facing changes made by this pull request.