-
Notifications
You must be signed in to change notification settings - Fork 188
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
Updated logrotate frequency to allow for an override #1814
Conversation
…ional file/file groups (via wildcard).
2a29d1c
to
9c011d4
Compare
1a3654f
to
e50f527
Compare
this.filename = filename; | ||
this.extension = extension; | ||
this.dateformat = dateformat; | ||
this.frequencyOverride = frequencyOverride; | ||
} | ||
|
||
public String getFilename() { | ||
return filename; | ||
} | ||
|
||
public Optional<String> getExtension() { |
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.
Each of the getters in a POJO like this should have the same return type as the private member variables they expose. In this case, I'd recommend having extension
, dateformat
, and frequencyOverride
be Optional<>
s (in both their member variable types and their getter types).
Our Jackson YAML deserialization should automatically take care of setting a missing field to an empty Optional<>
in the resulting Java object.
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.
Updated to deserialize to Guava Optional
s in our POJOs
@@ -88,7 +88,8 @@ public String getCompressExt() { | |||
new LogrotateAdditionalFile( | |||
taskDefinition.getTaskDirectoryPath().resolve(additionalFile.getFilename()).toString(), | |||
additionalFile.getExtension().or(Strings.emptyToNull(Files.getFileExtension(additionalFile.getFilename()))), | |||
dateformat | |||
dateformat, | |||
additionalFile.getLogrotateFrequencyOverride() |
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'll want to be consistent on the indent here before we merge up to master.
} | ||
|
||
@JsonCreator | ||
public SingularityExecutorLogrotateAdditionalFile(@JsonProperty("filename") String filename, | ||
@JsonProperty("extension") Optional<String> extension, | ||
@JsonProperty("dateformat") Optional<String> dateformat) { | ||
@JsonProperty("extension") String extension, |
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.
Curious why you removed the optionals from the arguments. Both cases should work for that particular usage but there are a few things to keep in mind:
- Jackson can handle the optionals just fine when reading from json and a missing key will be an absent optional
- Not relevant for this case, but always be on the lookout for other uses of a constructor that would cause something like this to be a breaking change. For this particular case, these POJOs are just used to model something read from json. But for other cases, releasing a new version with a changed constructor would break other users
@@ -36,6 +36,7 @@ notifempty | |||
|
|||
{{#if extrasFiles}} | |||
{{#each extrasFiles}}{{{filename}}} { | |||
{{#if logrotateFrequencyOverride }}{{{logrotateFrequencyOverride}}}{{/if}} |
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 should double check if this will 'just work'. Not all versions of logrotate support hourly
by default (Many are normally run on a daily cron, not hourly). If you look in SingularityExecutorTaskLogManager.writeLogrotateFile
you'll notice that we additionally write an hourly cron for the specific logrotate conf file that needs it. We will likely need an additional check in that method to see if an additional file has an hourly rotate and possibly a separate cron file if so (the current cron uses the -f
option to support hourly and force a logrotate run for those versions that do not support it)
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.
Additional note, enough OSs likely support hourly logrotate now that we could do away with this extra check if we verify that it still works as intended
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 have discussed this at length and determined that it's ok to put the logrotate config files at /etc/logrotate.d/hourly
. The Mesos slave running our SingularityExecutor
needs to support hourly cron jobs at this directory. We have already internally updated our puppet deploy to enforce this config on mesos slaves.
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 have decided to support older logrotate versions and added code to Singularity to force a rotation hourly using the -f
flag and a cron schedule. This implementation writes config files to two directories:
/etc/logrotate.d
/etc/logrotate.d/hourly
9cd9ed1
to
152eb8c
Compare
…tories and templates.
*/ | ||
public List<LogrotateAdditionalFile> getExtrasFilesHourly() { | ||
return getAllExtraFiles().stream() | ||
.filter(p -> p.getLogrotateFrequencyOverride().equals(SingularityExecutorLogrotateFrequency.HOURLY)).collect(Collectors.toList()); |
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.
nit on formatting, put the collect call on a new line to make it more readable
} | ||
|
||
return transformed; | ||
} | ||
|
||
|
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.
nit, extra new line
additionalFile.getExtension().or(Strings.emptyToNull(Files.getFileExtension(additionalFile.getFilename()))), | ||
dateformat | ||
)); | ||
if (additionalFile.getLogrotateFrequencyOverride().isPresent() && |
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.
method name is getAll, did you meant to filter to hourly here still?
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.
Two last nit-picky things before we get this on hs_stable
} | ||
} | ||
|
||
private Optional<SingularityExecutorLogrotateFrequency> getAdditionalHourlyFile() { | ||
// Get the cron schedule for an additional file with an HOURLY schedule, if there is any | ||
java.util.Optional<SingularityExecutorLogrotateAdditionalFile> additionalHourlyFile = configuration.getLogrotateAdditionalFiles() |
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.
nit, while util.Optional is the newer/nicer. It's probably easier for us to stick with guava optional until we do a consolidated swap across the whole repo.
.collect(Collectors.toList()); | ||
} | ||
|
||
public boolean getIsGlobalLogrotateHourly() { |
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.
For booleans, the standard is to use the is
prefix by itself (isGlobalLogrotateHourly
). A number of libraries like reflections (and the the handlebars templater in this case) go by that standard.
🚢 |
1 similar comment
🚢 |
🚢 |
🚢 |
To use this feature add additional file/file groups (via wildcard) and times to AdditionalLogrotateFile.