Skip to content
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

Specify custom directory for storing evaluation logs #863

Merged
merged 5 commits into from
May 21, 2021

Conversation

shati-patel
Copy link
Contributor

@shati-patel shati-patel commented May 14, 2021

Will fix #820.

Checklist

Comment on lines 97 to 105
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.`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@shati-patel shati-patel May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an attempt in b7897b0, which seems to do the right thing, but any tips on syntax/fixes are very welcome 😄

@adityasharad
Copy link
Contributor

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.

@shati-patel shati-patel changed the title [WIP] Specify custom directory for storing evaluation logs Specify custom directory for storing evaluation logs May 21, 2021
@shati-patel shati-patel force-pushed the shati-patel/store-logs branch 2 times, most recently from 892a125 to cd39ede Compare May 21, 2021 15:01
@shati-patel shati-patel marked this pull request as ready for review May 21, 2021 15:03
Comment on lines 127 to 135
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);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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... 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I wonder if that method isn't completely synchronous. You can try addinga a waitABit call in between and see what happens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the sync/async might be it. I was also baffled by why the existing test worked.

extensions/ql-vscode/src/logging.ts Outdated Show resolved Hide resolved
let isCustomLogDirectory = false;
if (this.config.customLogDirectory) {
try {
fs.mkdirSync(this.config.customLogDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method needs to be async

Suggested change
fs.mkdirSync(this.config.customLogDirectory);
await fs.mkdir(this.config.customLogDirectory);

extensions/ql-vscode/src/queryserver-client.ts Outdated Show resolved Hide resolved
Comment on lines 127 to 135
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);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 127 to 135
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);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

extensions/ql-vscode/src/queryserver-client.ts Outdated Show resolved Hide resolved
@shati-patel shati-patel force-pushed the shati-patel/store-logs branch from 8d711c6 to 8e4930c Compare May 21, 2021 19:55
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last change and then :shipit:.

extensions/ql-vscode/src/queryserver-client.ts Outdated Show resolved Hide resolved
@shati-patel shati-patel force-pushed the shati-patel/store-logs branch from 1637a22 to 43fba35 Compare May 21, 2021 20:34
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User-specified directory in which to store evaluation logs
3 participants