Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public String hierarchyMarkerType() {
public ElementMatcher<TypeDescription> hierarchyMatcher() {
return declaresMethod(named("writeTo"))
.and(extendsClass(named(hierarchyMarkerType())))
.and(not(nameStartsWith("com.google.protobuf")));
.and(
not(nameStartsWith("com.google.protobuf"))
.or(named("com.google.protobuf.DynamicMessage")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ public SchemaSampler() {
}

public int trySample(long currentTimeMillis) {
weight.incrementAndGet();
if (currentTimeMillis >= lastSampleMillis + SAMPLE_INTERVAL_MILLIS) {
synchronized (this) {
if (currentTimeMillis >= lastSampleMillis + SAMPLE_INTERVAL_MILLIS) {
lastSampleMillis = currentTimeMillis;
int currentWeight = weight.get();
weight.set(0);
return currentWeight;
return weight.getAndSet(0);
}
}
}
return 0;
}

public boolean canSample(long currentTimeMillis) {
weight.incrementAndGet();
return currentTimeMillis >= lastSampleMillis + SAMPLE_INTERVAL_MILLIS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ class DefaultDataStreamsMonitoringTest extends DDCoreSpecification {
def dataStreams = new DefaultDataStreamsMonitoring(sink, features, timeSource, { traceConfig }, wellKnownTags, payloadWriter, DEFAULT_BUCKET_DURATION_NANOS)

then:
dataStreams.canSampleSchema("schema1")
dataStreams.trySampleSchema("schema1") == 1
dataStreams.canSampleSchema("schema2")
dataStreams.trySampleSchema("schema2") == 1
dataStreams.trySampleSchema("schema1") == 0
dataStreams.trySampleSchema("schema1") == 0
!dataStreams.canSampleSchema("schema1")
!dataStreams.canSampleSchema("schema1")
timeSource.advance(30*1e9 as long)
dataStreams.canSampleSchema("schema1")
dataStreams.trySampleSchema("schema1") == 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a future maintainer would be grateful if there was one or two comments explaining why we expect those results

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ class SchemaSamplerTest extends DDCoreSpecification {
boolean canSample1 = sampler.canSample(currentTimeMillis)
int weight1 = sampler.trySample(currentTimeMillis)
boolean canSample2= sampler.canSample(currentTimeMillis + 1000)
int weight2 = sampler.trySample(currentTimeMillis + 1000)
boolean canSample3 = sampler.canSample(currentTimeMillis + 2000)
int weight3 = sampler.trySample(currentTimeMillis + 2000)
boolean canSample4 = sampler.canSample(currentTimeMillis + 30000)
int weight4 = sampler.trySample(currentTimeMillis + 30000)
boolean canSample5 = sampler.canSample(currentTimeMillis + 30001)
int weight5 = sampler.trySample(currentTimeMillis + 30001)

then:
canSample1
weight1 == 1
!canSample2
weight2 == 0
!canSample3
weight3 == 0
canSample4
weight4 == 3
!canSample5
weight5 == 0
}
}