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
LogConfigurator resolveConfig also reads .rpmnew or .bak files #7457
Conversation
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class LogConfiguratorTest { |
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.
can you extend ElasticsearchTestCase
?
This only allows for loading of |
I've added a fixup commit which includes your suggested changes. Not sure about json, I don't really mind to add support for json files, but I guess then it should also be documented? Actually in the documentation it mentions that just "logging.yml" is loaded so the implementation here doesn't quite match the behaviour, but I didn't want to break backward compatibility. |
loadConfig(file, settingsBuilder); | ||
break; | ||
} | ||
} |
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.
with the current code a logging.whatever.yaml
file would be loaded. I wonder if this is our intention or a side-effect of the current behaviour. Honestly I would be in favour of simplifying this further and even have something like if (file.getFileName().toString().equals("logging.yaml") || file.getFileName().toString().equals("logging.yml") )
unless we want to extend this to json and properties files, which I think would be off-topic in this PR.
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.
we need to support whatever extensions Settings supports and that includes json & java properties formats. I wouldn't worry about restricting it to these three (yml, json, properties) with regards to bwc.
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.
Hi @mfussenegger sorry it took a while to give you some more feedback, thanks a lot for updating your PR. I think it's really close and I would eventually address loading of |
Hi @javanna thanks for the feedback. I've added another fixup with the changes you mentioned. |
Hey @mfussenegger I apologize but I just realized that in fact we currently support both |
This logic should also be applied to eg |
Going to open a separate issue for other config files, let's focus exclusively on logging on this PR. @mfussenegger after some thinking I find your initial approach better than what I suggested, since we support multiple logging configuration files that get merged. Thus we can leave it at logging.*.suffix where suffix is either yaml, yml, json or properties. This solution would be more flexible and backwards compatible and at the same time fix the original problem. Thanks a lot for your help and sorry for changing direction :) |
K, I'll look into the json/properties support and update the PR accordingly. But might take a bit until I get back to this. |
@mfussenegger thanks again! |
I've updated the PR so that Also rebased it with current master and already squashed the first few commits. |
@@ -118,8 +119,14 @@ public static void resolveConfig(Environment env, final ImmutableSettings.Builde | |||
Files.walkFileTree(env.configFile().toPath(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { | |||
@Override | |||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | |||
if (file.getFileName().toString().startsWith("logging.")) { | |||
loadConfig(file, settingsBuilder); | |||
String fileName = file.getFileName().toString().toLowerCase(Locale.ENGLISH); |
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 wonder about the added toLowerCase
...I understand why you did it, but I'm not sure we should change this here. This way we would not only load less files (as we skip non allowed suffixes), but also more files at the same time (think of potentially any LOGGING* or Logging* file that was ignored up until now). It's a minor thing but I would open another issue for discussion on making the filename case-insensitive and discuss it separately.
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.
So you would also disallow logging.YAML ?
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 think we already do since we don't lowercase the suffix. That's fine with me. I think it's consistent with what we usually do with conf files. Let's try and add some docs for this to make it clear.
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.
Without the changes in this PR it would match as anything starting with logging.
matches.
So maybe the allowed suffixes should be
(".YML", ".YAML", ".JSON", ".PROPERTIES", ".yml", ".yaml", ".json", ".properties");
?
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 see what you mean, that we somehow break bw comp but I would leave only the lowercase variants to make this consistent with other places where we load files e.g. we would never load elasticsearch.YML
. I think this change is acceptable and in the scope of the PR since we are in fact limiting the files that are getting loaded as logging configuration.
public class LogConfiguratorTest extends ElasticsearchTestCase { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); |
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.
Not sure you got my previous comment on this, it might have gotten lost with the rebase. I think we can avoid using the TemporaryFolder
rule but just rely on the facilities provided by the randomized testing library. We can just create a new directory within the globalTempDir() that is already available (via the newTempDir()
static method), and then create the file within this temp dir that gets cleaned after each test by default. Also, this should make it possible to merge this new class with the existing LogginConfigurationTests
. Makes sense?
Thanks @mfussenegger it's very close, I left one minor comment on making the filename case-insensitive and one more around testing. Let me know if you have any question. |
Added another fixup. |
…r suffix Make sure that files such as logging.yml.rpmnew or logging.yml.bak are not loaded as logging configuration. Only files that start with the "logging." prefix and end with ".yaml", ".yml", ".json" and ".properties" suffix get loaded. Closes elastic#7457
…r suffix Make sure that files such as logging.yml.rpmnew or logging.yml.bak are not loaded as logging configuration. Only files that start with the "logging." prefix and end with ".yaml", ".yml", ".json" and ".properties" suffix get loaded. Closes elastic#7457
…r suffix Make sure that files such as logging.yml.rpmnew or logging.yml.bak are not loaded as logging configuration. Only files that start with the "logging." prefix and end with ".yaml", ".yml", ".json" and ".properties" suffix get loaded. Closes elastic#7457
Thanks a lot @mfussenegger I just merged this. |
@javanna should this fix go to 1.3.6? |
@jpountz why not. will backport it shortly. |
…r suffix Make sure that files such as logging.yml.rpmnew or logging.yml.bak are not loaded as logging configuration. Only files that start with the "logging." prefix and end with ".yaml", ".yml", ".json" and ".properties" suffix get loaded. Closes elastic#7457
Currently the LogConfigurator will attempt to read any file that starts with "logging." in the env.configFile() path.
A common practise is to suffix files with .bak or in case of package managers they often add a suffix if the file has been modified upstream.
Elasticsearch will read those values anyway and that might lead to very confusing logging behaviour.
I am not sure how to best approach this, either have a whitelist or a backlist of suffixes that are allowed/disallowed ?