-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Deleting sample when sampling configuration is deleted or changed #136123
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
Changes from 6 commits
a1bed05
2d37869
e9c5479
7aead54
484ab42
3d1da2d
61e2fc0
ebd48d0
fe6588d
0edb9db
f1f8d34
5561ac9
87afb95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -42,9 +42,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.lang.ref.SoftReference; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.HashSet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Objects; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.concurrent.ConcurrentHashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.concurrent.atomic.AtomicInteger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.concurrent.atomic.LongAdder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -264,7 +266,68 @@ public boolean atLeastOneSampleConfigured() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||
public void clusterChanged(ClusterChangedEvent event) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: React to sampling config changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (RANDOM_SAMPLING_FEATURE_FLAG == false) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (samples.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// We want to remove any samples if their sampling configuration has been deleted or modified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (event.metadataChanged()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* First, we collect the union of all project ids in the current state and the previous one. We include the project ids from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* previous state in case an entire project has been deleted -- in that case we would want to delete all of its samples. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<ProjectId> allProjectIds = new HashSet<>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
event.state().metadata().projects().values().stream().map(ProjectMetadata::id).toList() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
allProjectIds.addAll(event.previousState().metadata().projects().values().stream().map(ProjectMetadata::id).toList()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
for (ProjectId projectId : allProjectIds) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (event.customMetadataChanged(projectId, SamplingMetadata.TYPE)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're retrieving the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That won't really save us anything other than a two hash map lookups will it? And it's possible that someone could optimize customMetadataChanged in the future and then we'd miss out on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd save the project lookup and the customs lookup, both twice. I agree that that's not much. I'll leave it up to you 👍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||
SamplingMetadata oldSamplingConfig = event.previousState().metadata().hasProject(projectId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
? event.previousState().projectState(projectId).metadata().custom(SamplingMetadata.TYPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
: null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
SamplingMetadata newSamplingConfig = event.state().metadata().hasProject(projectId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
? event.state().projectState(projectId).metadata().custom(SamplingMetadata.TYPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
: null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<String, SamplingConfiguration> newSampleConfigsMap = newSamplingConfig == null | ||||||||||||||||||||||||||||||||||||||||||||||||||||
? Map.of() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
: newSamplingConfig.getIndexToSamplingConfigMap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<String> currentlyConfiguredIndexNames = newSampleConfigsMap.keySet(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<String> previouslyConfiguredIndexNames = oldSamplingConfig == null | ||||||||||||||||||||||||||||||||||||||||||||||||||||
? Set.of() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
: oldSamplingConfig.getIndexToSamplingConfigMap().keySet(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<String> removedIndexNames = new HashSet<>(previouslyConfiguredIndexNames); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
removedIndexNames.removeAll(currentlyConfiguredIndexNames); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SamplingMetadata oldSamplingConfig = event.previousState().metadata().hasProject(projectId) | |
? event.previousState().projectState(projectId).metadata().custom(SamplingMetadata.TYPE) | |
: null; | |
SamplingMetadata newSamplingConfig = event.state().metadata().hasProject(projectId) | |
? event.state().projectState(projectId).metadata().custom(SamplingMetadata.TYPE) | |
: null; | |
Map<String, SamplingConfiguration> newSampleConfigsMap = newSamplingConfig == null | |
? Map.of() | |
: newSamplingConfig.getIndexToSamplingConfigMap(); | |
Set<String> currentlyConfiguredIndexNames = newSampleConfigsMap.keySet(); | |
Set<String> previouslyConfiguredIndexNames = oldSamplingConfig == null | |
? Set.of() | |
: oldSamplingConfig.getIndexToSamplingConfigMap().keySet(); | |
Set<String> removedIndexNames = new HashSet<>(previouslyConfiguredIndexNames); | |
removedIndexNames.removeAll(currentlyConfiguredIndexNames); | |
Map<String, SamplingConfiguration> oldSampleConfigsMap = Optional.ofNullable(event.previousState().metadata().getProject(projectId)) | |
.map(p -> p.custom(SamplingMetadata.TYPE)) | |
.map(SamplingMetadata::getIndexToSamplingConfigMap) | |
.orElse(Map.of()); | |
Map<String, SamplingConfiguration> newSampleConfigsMap = Optional.ofNullable(event.state().metadata().getProject(projectId)) | |
.map(p -> p.custom(SamplingMetadata.TYPE)) | |
.map(SamplingMetadata::getIndexToSamplingConfigMap) | |
.orElse(Map.of()); | |
Set<String> removedIndexNames = new HashSet<>(oldSampleConfigsMap.keySet()); | |
removedIndexNames.removeAll(newSampleConfigsMap.keySet()); |
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 like that too. Unfortunately though getProject() throws an exception rather than returning null if the project doesn't exist.
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.
Oh but using projects().get(projectId) works fine. I'll switch to that.
Uh oh!
There was an error while loading. Please reload this page.