config: ignore duplicated entries#173
Conversation
|
There are 2 commits here. The first one is a refactor and it shouldn't change any behavior of Here is what I did:
Note: a small catch on this is that I have to store the config file path and line number for each Any comment would be appreciated. |
|
Do I understand it correctly that, whenever a glob in logrotate's configuration matches a log file and sets something (or even sets nothing), then the log file can never be matched again to override the previous settings? I would expect it to work the other way around (such that later matches override the previous ones). That would be more compatible with how logrotate handles multiple configuration files:
... or with the principle that local definitions override global ones. |
|
Sorry, I don't understand. I thought For example, I have a log at Then will output: and It seems that |
|
On Wednesday, February 21, 2018 7:31:37 AM CET John Lin wrote:
Sorry, I don't understand. I thought `logrotate` doesn't allow 2 config
files specify duplicate log files.
Yes, that is the feature you are going to implement. However, logrotate
currently allows to specify multiple config files where _global_ options
from config files read earlier can be overridden by config files read later.
You want to implement a similar (optional) feature for per-log options.
What I am saying is that the handling of overrides should be consistent
with what is already implemented. Hence, options for log files matched
later should override options for log files matched earlier and not vice
versa.
Does it make sense now?
|
|
If I understand correctly, you want the following behavior: For the log files You want both
In my current implementation, the above |
|
Then I would write those entries in the reverse order and still achieve the desired result: Try the following two examples in a shell: What will be the result? |
|
@kdudka I see your point. I will modify my patch to achieve this behavior. Thanks. |
|
Was just about to write out my understanding of it, but it looks like it's agreed. However, thinking about this made me consider how included files will behave. So if there are two conf files in |
|
@wyohm I do not think that file inclusion should change anything. You should get the same result as if you inlined all the included config files. Or am I missing something? |
|
@kdudka That answers it, thanks. I'm not thinking that it will change behavior. Just that it highlights behavior which may not be desirable. For instance, if I want to understand the behavior of |
|
Let's make the semantic meaning of In @wyohm's original comment, this directive means "this log config will do a glob search and take what are not handled in the earlier log configs". In @kdudka's comment, this directive means "this log config will do a glob search and take all the glob results, but can be taken off by the later log configs". Do I understand this correctly? |
|
@wyohm You have a similar problem even now without the |
|
@johnlinp Yes, that was the meaning of my original comment. Though I now prefer the behavior @kdudka has proposed. What I proposed may be simpler to implement and possibly understand conf files (log files can be processed as soon as they are matched), but what @kdudka proposes allows for more flexibility since multiple matches can add behavior. |
|
@johnlinp Yes. I think that the options should be applied to all matched log files. And, if |
|
@kdudka Agreed, that issue (includes setting globals) currently exists. It's just that I only started thinking about it when considering the behavior of |
|
Hmm.. I wasn't expect that later log config can add options to the previously matched logs. I think that completely overriden would be better. I think it's too complex for a system administrator to understand or debug since he/she has to accumulate all the effects in all matched log configs. If the behavior is completely override, it's easier to understand because the system administrator only needs to find out which the last matched log config is. For example, for the 2 log files If the behavior is adding options, to figure out the options for
If the behavior is completely overriding options, to figure out the options for
In conclusion, I think the add would increase too much complexity and I suggest the completely override behavior. Thanks. |
|
Let's keep it simple. Currently it works like this:
We only need to (optionally) change one detail:
Of course, you will be able to completely override previously parsed By added complexity you mean complexity of the implementation? As for complexity of the configuration interface, I see it exactly opposite. Let's assume we have |
|
By increasing complexity, I mean the complexity of the configuration interface. (Although I guess the complexity of the implementation would increase too) Another question: What option should |
|
On Tuesday, February 27, 2018 4:49:58 PM CET John Lin wrote:
By increasing complexity, I mean the complexity of the configuration
interface. (Although I guess the complexity of the implementation would
increase too)
Another question:
```
/*.log {
daily
globoverride
}
/a-*.log {
weekly
}
/a-b-*.log {
monthly
}
```
What option should `/a-b-c.log`have? Is it `weekly` because the second log
config override the first one and the third one cannot override the second
one? Or, is it `monthly` because the second one inherits `globoverride`
from the first one so it can be overriden by the third one?
Sounds pretty clear to me. The options are applied as the config file is
parsed:
1. daily and globoverride on all files matching /*.log
2. weekly on all files matching /a-*.log
3. monthly on all files matching /a-b-*.log
Consequently:
- /a-b-*.log files will rotate monthly
- /a-*.log files (not matching the above pattern) will rotate weekly
- /*.log files (not matching any of the above patterns) will rotate daily
|
|
@kdudka I see. I will start working on it. Thanks! |
|
I would like to implement
This algorithm make sure every log file will only appear at most once in the global linked list Any advice will be appreciated. Thanks. |
|
Thanks for the analysis! I will need to look at the current code closer myself. Unfortunately I am too busy this week. Please give me some time to process this. Anyway, |
|
By the way, I think the indentation in the code is a mess. The inconsistent of indentation makes it harder to develop. I would like to ask:
Thank you. |
|
Hello, There's way more lines starting with a tab than with a space, so I'd say tabs:
|
|
@Saruspete Sorry for the late reply. Thanks for the statistics. I will use tab to reorganize the indent. |
|
Sorry for being silent on this PR. I have not found a sufficient block of time to have a deeper look at this. As for (re)indentation and coding style changes beyond what is strictly necessary to implement this, those need to be discussed (and eventually pushed) independently of this PR. The up to now practice was to resemble the indentation and coding style of the surrounding code. It seems to cause problems in long term and it might now be the right time to unify the indentation and/or coding style to some extent. However, such changes need to be discussed via appropriate channels, which a pull request named "config: ignore duplicated entries" is not. |
|
@kdudka Okay. I will create an independent issue for the indentation problem. |
|
The issue was created at #188. |
|
Hi, I'd just like to ask about the state of this. We need to do major changes to our logrotate config due to the DSGVO and have to overwrite many of the default stuff that opensuse ships. It would make things very easy if we could just add confs to overwrite the handling of certain log files without needing to change the shipped defaults. The current logrotate-master branch still seems to have the old behaviour. |
|
@Frank-Steiner Since the code indentation in current code base was kind of messy, I was waiting for #188 to close. If you need this feature, I can try to develop in current code base. |
|
Yes, I understand that you'd like to know how to write the code before you start, so whatever you decide is fine with me. As soon as there's a patch I'll be happy to test it! Thanks! |
|
Sorry for taking too long to review this PR. I have to prioritize bug fixes over enhancements. This PR changes fundamental parts of logrotate's code, so it needs to be reviewed carefully to make sure we are not introducing any bugs or compatibility issues in the future release of logrotate. |
|
Hello, I'd really like to see this PR merged. Could you see to prioritize it please ? |
|
@Saruspete Sure. I am developing a new patch for the algorithm described in #173 (comment). |
|
Nice @johnlinp thanks for your work ! :) Having reread the thread, here's what I understood :
In the unix world, we are already used to prefix / suffix our configuration files to enforce alphanumeric ordering (and The suffix is useful so that packages updates don't generate wild ".rpmnew" files (that would be interpreted too), they just replace the packaged one, and reads the user suffixed afterwards. With that in mind, the rules specified by user (the suffixed ones) are often discovered after the original (packaged) ones. If we'd want to say "I want this new rule to override the existing / package provided one", acting more like a "OverrideExisting". Wouldn't that cover more real-world cases ? |
|
I have not looked closely at the implementation yet but let's not over-complicate things. The configuration rules need to be intuitive and as simple as possible. What about the following rules?
Am I missing anything? |
|
@kdudka I found that the algorithm described in my previous comment cannot be easily done because the function For example, the field
When I want to override However, current definition of |
|
I feel like I am repeating myself but why do we need all the complexity? Cannot we just go through all config files and apply options incrementally as we read them? |
|
@kdudka Since a log config may override multiple log configs, it can produce multiple |
|
@johnlinp I had finally time to look at the code. I see what you are talking about -- your questions are pretty valid. However, there is one more question that needs to be discussed before we proceed with the implementation: What should we do with As it works now, each configuration section is associated with a set of globs and the actual set of files produced by expansion of the globs. If a prerotate/postrotate script runs with If we only update the set of files and keep the original set of globs while overriding a previous configuration, some files might be processed by multiple prerotate/postrotate scripts when Would it make sense to pass line-separated list of files (instead of globs) to prerotate/postrotate scripts when both |
|
Good idea, moved: #38 (comment) |
|
Accoding to the discussion in #38, I'm closing thie PR since I won't spend more time on it :( |
Closes: #38