Skip to content

Commit

Permalink
implement debugger configuration merging
Browse files Browse the repository at this point in the history
  • Loading branch information
shatzi committed Nov 24, 2022
1 parent f36d22d commit 2e57d15
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,31 @@ public int hashCode() {
}
}

private final String id;
private final long orgId;
private final Collection<SnapshotProbe> snapshotProbes;
private final Collection<MetricProbe> metricProbes;
private final Collection<LogProbe> logProbes;
private final FilterList allowList;
private final FilterList denyList;
private final SnapshotProbe.Sampling sampling;

public Configuration(String id, long orgId, Collection<SnapshotProbe> snapshotProbes) {
this(id, orgId, snapshotProbes, null, null, null, null, null);
public Configuration(Collection<SnapshotProbe> snapshotProbes) {
this(snapshotProbes, null, null, null, null, null);
}

public Configuration(
String id,
long orgId,
Collection<SnapshotProbe> snapshotProbes,
Collection<MetricProbe> metricProbes,
Collection<LogProbe> logProbes) {
this(id, orgId, snapshotProbes, metricProbes, logProbes, null, null, null);
this(snapshotProbes, metricProbes, logProbes, null, null, null);
}

public Configuration(
String id,
long orgId,
Collection<SnapshotProbe> snapshotProbes,
Collection<MetricProbe> metricProbes,
Collection<LogProbe> logProbes,
FilterList allowList,
FilterList denyList,
SnapshotProbe.Sampling sampling) {
this.id = id;
this.orgId = orgId;
this.snapshotProbes = snapshotProbes;
this.metricProbes = metricProbes;
this.logProbes = logProbes;
Expand All @@ -97,14 +89,6 @@ public Configuration(
this.sampling = sampling;
}

public String getId() {
return id;
}

public long getOrgId() {
return orgId;
}

public Collection<SnapshotProbe> getSnapshotProbes() {
return snapshotProbes;
}
Expand Down Expand Up @@ -147,12 +131,7 @@ public Collection<ProbeDefinition> getDefinitions() {
@Override
public String toString() {
return "DebuggerConfiguration{"
+ "id='"
+ id
+ '\''
+ ", orgId="
+ orgId
+ ", probes="
+ "snapshotProbes="
+ snapshotProbes
+ ", metricProbes="
+ metricProbes
Expand All @@ -173,9 +152,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Configuration that = (Configuration) o;
return orgId == that.orgId
&& Objects.equals(id, that.id)
&& Objects.equals(snapshotProbes, that.snapshotProbes)
return Objects.equals(snapshotProbes, that.snapshotProbes)
&& Objects.equals(metricProbes, that.metricProbes)
&& Objects.equals(logProbes, that.logProbes)
&& Objects.equals(allowList, that.allowList)
Expand All @@ -186,7 +163,119 @@ public boolean equals(Object o) {
@Generated
@Override
public int hashCode() {
return Objects.hash(
id, orgId, snapshotProbes, metricProbes, logProbes, allowList, denyList, sampling);
return Objects.hash(snapshotProbes, metricProbes, logProbes, allowList, denyList, sampling);
}

public static Configuration.Builder builder() {
return new Configuration.Builder();
}

public static class Builder {
private List<SnapshotProbe> snapshotProbes = null;
private List<MetricProbe> metricProbes = null;
private List<LogProbe> logProbes = null;
private FilterList allowList = null;
private FilterList denyList = null;
private SnapshotProbe.Sampling sampling = null;

public Configuration.Builder add(SnapshotProbe probe) {
if (snapshotProbes == null) {
snapshotProbes = new ArrayList<>();
}
snapshotProbes.add(probe);
return this;
}

public Configuration.Builder add(MetricProbe probe) {
if (metricProbes == null) {
metricProbes = new ArrayList<>();
}
metricProbes.add(probe);
return this;
}

public Configuration.Builder add(LogProbe probe) {
if (logProbes == null) {
logProbes = new ArrayList<>();
}
logProbes.add(probe);
return this;
}

public Configuration.Builder add(SnapshotProbe.Sampling newSampling) {
if (newSampling != null) {
sampling = newSampling;
}
return this;
}

public Configuration.Builder addSnapshotsProbes(Collection<SnapshotProbe> probes) {
if (probes == null) {
return this;
}
for (SnapshotProbe probe : probes) {
add(probe);
}
return this;
}

public Configuration.Builder addMetricProbes(Collection<MetricProbe> probes) {
if (probes == null) {
return this;
}
for (MetricProbe probe : probes) {
add(probe);
}
return this;
}

public Configuration.Builder addLogProbes(Collection<LogProbe> probes) {
if (probes == null) {
return this;
}
for (LogProbe probe : probes) {
add(probe);
}
return this;
}

public Configuration.Builder addAllowList(FilterList newAllowList) {
if (newAllowList == null) {
return this;
}
if (allowList == null) {
allowList = new FilterList(new ArrayList<>(), new ArrayList<>());
}
allowList.getClasses().addAll(newAllowList.getClasses());
allowList.getPackagePrefixes().addAll(newAllowList.getPackagePrefixes());
return this;
}

public Configuration.Builder addDenyList(FilterList newDenyList) {
if (newDenyList == null) {
return this;
}
if (denyList == null) {
denyList = new FilterList(new ArrayList<>(), new ArrayList<>());
}
denyList.getClasses().addAll(newDenyList.getClasses());
denyList.getPackagePrefixes().addAll(newDenyList.getPackagePrefixes());
return this;
}

public Configuration.Builder add(Configuration other) {
addSnapshotsProbes(other.getSnapshotProbes());
addMetricProbes(other.getMetricProbes());
addLogProbes(other.getLogProbes());
addAllowList(other.getAllowList());
addDenyList(other.getDenyList());
add(other.getSampling());
return this;
}

public Configuration build() {
return new Configuration(
snapshotProbes, metricProbes, logProbes, allowList, denyList, sampling);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class ConfigurationComparer {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationComparer.class);

private Configuration originalConfiguration;
private Configuration incomingConfiguration;
private final Configuration originalConfiguration;
private final Configuration incomingConfiguration;

private final List<ProbeDefinition> addedDefinitions;
private final List<ProbeDefinition> removedDefinitions;
Expand Down Expand Up @@ -173,16 +173,15 @@ List<String> findChangesInBlockedTypes() {
new AllowListHelper(originalConfiguration.getAllowList());
DenyListHelper originalDenyListHelper = new DenyListHelper(originalConfiguration.getDenyList());

AllowListHelper incommingAllowListHelper =
AllowListHelper incomingAllowListHelper =
new AllowListHelper(incomingConfiguration.getAllowList());
DenyListHelper incommingDenyListHelper =
new DenyListHelper(incomingConfiguration.getDenyList());
DenyListHelper incomingDenyListHelper = new DenyListHelper(incomingConfiguration.getDenyList());

List<String> changedTypes = new ArrayList();

for (InstrumentationResult result : instrumentationResults.values()) {
boolean originalAllowed = true;
boolean incommingAllowed = true;
boolean incomingAllowed = true;
String typeName = result.getTypeName();

if (originalDenyListHelper.isDenied(typeName)) {
Expand All @@ -194,16 +193,16 @@ List<String> findChangesInBlockedTypes() {
originalAllowed = false;
}

if (incommingDenyListHelper.isDenied(typeName)) {
if (incomingDenyListHelper.isDenied(typeName)) {
LOGGER.debug("type {} will be denied", typeName);
incommingAllowed = false;
} else if (!incommingAllowListHelper.isAllowAll()
&& !incommingAllowListHelper.isAllowed(typeName)) {
incomingAllowed = false;
} else if (!incomingAllowListHelper.isAllowAll()
&& !incomingAllowListHelper.isAllowed(typeName)) {
LOGGER.debug("type {} will not be allowed", typeName);
incommingAllowed = false;
incomingAllowed = false;
}

if (incommingAllowed != originalAllowed) {
if (incomingAllowed != originalAllowed) {
changedTypes.add(typeName);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* Handles configuration updates if required by installing a new ClassFileTransformer and triggering
* re-transformation of required classes
*/
public class ConfigurationUpdater implements DebuggerContext.ProbeResolver {
public class ConfigurationUpdater
implements DebuggerContext.ProbeResolver, DebuggerProductChangesListener.ConfigurationAcceptor {

public static final int MAX_ALLOWED_PROBES = 100;
public static final int MAX_ALLOWED_METRIC_PROBES = 100;
Expand Down Expand Up @@ -89,12 +90,6 @@ public void accept(Configuration configuration) {
applyNewConfiguration(createEmptyConfiguration());
return;
}
// handle mismatched configurations
if (!configuration.getId().equals(serviceName)) {
log.debug(
"got debugConfig.serviceName = {}, ignoring configuration", configuration.getId());
return;
}
// apply new configuration
Configuration newConfiguration = applyConfigurationFilters(configuration);
applyNewConfiguration(newConfiguration);
Expand Down Expand Up @@ -147,8 +142,6 @@ private Configuration applyConfigurationFilters(Configuration configuration) {
.collect(Collectors.toList());
}
return new Configuration(
configuration.getId(),
configuration.getOrgId(),
probes,
metricProbes,
logProbes,
Expand Down Expand Up @@ -220,16 +213,14 @@ private void recordInstrumentationProgress(
private Configuration createEmptyConfiguration() {
if (currentConfiguration != null) {
return new Configuration(
currentConfiguration.getId(),
currentConfiguration.getOrgId(),
null,
null,
null,
currentConfiguration.getAllowList(),
currentConfiguration.getDenyList(),
currentConfiguration.getSampling());
}
return new Configuration("ID", 0, null, null, null, null, null, null);
return new Configuration(null, null, null, null, null, null);
}

private void retransformClasses(List<Class<?>> classesToBeTransformed) {
Expand Down
Loading

0 comments on commit 2e57d15

Please sign in to comment.