-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add feature to automatically remove audit logs based on retention period #11084
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c819d76
add docs
maytasm 34128f7
add impl
maytasm ca2d632
fix checkstyle
maytasm 8176c64
fix test
maytasm b298b18
add test
maytasm 5578630
fix checkstyle
maytasm 971b660
fix checkstyle
maytasm 355ef52
Merge branch 'master' into IMPLY-6571
maytasm 362097e
fix test
maytasm 55271c9
Address comments
maytasm 90d8095
Address comments
maytasm bbc6746
fix spelling
maytasm 4182ff9
fix docs
maytasm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../main/java/org/apache/druid/guice/annotations/CoordinatorMetadataStoreManagementDuty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.guice.annotations; | ||
|
|
||
| import com.google.inject.BindingAnnotation; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| */ | ||
| @BindingAnnotation | ||
| @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface CoordinatorMetadataStoreManagementDuty | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
server/src/main/java/org/apache/druid/server/coordinator/duty/KillAuditLog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.server.coordinator.duty; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.inject.Inject; | ||
| import org.apache.druid.audit.AuditManager; | ||
| import org.apache.druid.java.util.common.logger.Logger; | ||
| import org.apache.druid.java.util.emitter.service.ServiceEmitter; | ||
| import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; | ||
| import org.apache.druid.server.coordinator.DruidCoordinatorConfig; | ||
| import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams; | ||
|
|
||
| public class KillAuditLog implements CoordinatorDuty | ||
| { | ||
| private static final Logger log = new Logger(KillAuditLog.class); | ||
|
|
||
| private final long period; | ||
| private final long retainDuration; | ||
| private long lastKillTime = 0; | ||
|
|
||
| private final AuditManager auditManager; | ||
|
|
||
| @Inject | ||
| public KillAuditLog( | ||
| AuditManager auditManager, | ||
| DruidCoordinatorConfig config | ||
| ) | ||
| { | ||
| this.period = config.getCoordinatorAuditKillPeriod().getMillis(); | ||
| Preconditions.checkArgument( | ||
| this.period >= config.getCoordinatorMetadataStoreManagementPeriod().getMillis(), | ||
| "coordinator audit kill period must be >= druid.coordinator.period.metadataStoreManagementPeriod" | ||
| ); | ||
| this.retainDuration = config.getCoordinatorAuditKillDurationToRetain().getMillis(); | ||
| Preconditions.checkArgument(this.retainDuration >= 0, "coordinator audit kill retainDuration must be >= 0"); | ||
| log.debug( | ||
| "Audit Kill Task scheduling enabled with period [%s], retainDuration [%s]", | ||
| this.period, | ||
| this.retainDuration | ||
| ); | ||
| this.auditManager = auditManager; | ||
| } | ||
|
|
||
| @Override | ||
| public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) | ||
| { | ||
| if ((lastKillTime + period) < System.currentTimeMillis()) { | ||
| lastKillTime = System.currentTimeMillis(); | ||
|
|
||
| long timestamp = System.currentTimeMillis() - retainDuration; | ||
| int auditRemoved = auditManager.removeAuditLogsOlderThan(timestamp); | ||
| ServiceEmitter emitter = params.getEmitter(); | ||
| emitter.emit( | ||
| new ServiceMetricEvent.Builder().build( | ||
| "metadata/kill/audit/count", | ||
| auditRemoved | ||
| ) | ||
| ); | ||
| log.info("Finished running KillAuditLog duty. Removed %,d audit logs", auditRemoved); | ||
| } | ||
| return params; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These defaults don't seem to match the documented defaults above
Uh oh!
There was an error while loading. Please reload this page.
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.
Fixed the docs.
druid.coordinator.kill.audit.periodis not required. And the default value is P1Ddruid.coordinator.kill.audit.durationToRetainis required. The default value which is -1 which causes the precondition check to fail. User should set it to a positive value. Instead of putting in the docs that the default value is -1 and that Coordinator will fail if value is negative, for simplicity, I just documented that default value is None and user must set this value.