-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #742 from allegro/release-0.11.2
Release 0.11.2
- Loading branch information
Showing
29 changed files
with
338 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
...s/consumer/sender/http/AvroMediaType.java → ...llegro/tech/hermes/api/AvroMediaType.java
This file contains 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 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 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 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 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 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
2 changes: 1 addition & 1 deletion
2
...es/frontend/metric/StartedTimersPair.java → ...ommon/metric/timer/StartedTimersPair.java
This file contains 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 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
72 changes: 72 additions & 0 deletions
72
...rc/main/java/pl/allegro/tech/hermes/common/schema/ReadMetricsTrackingRawSchemaClient.java
This file contains 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,72 @@ | ||
package pl.allegro.tech.hermes.common.schema; | ||
|
||
import com.codahale.metrics.Timer; | ||
import pl.allegro.tech.hermes.api.RawSchema; | ||
import pl.allegro.tech.hermes.api.TopicName; | ||
import pl.allegro.tech.hermes.common.metric.HermesMetrics; | ||
import pl.allegro.tech.hermes.common.metric.Timers; | ||
import pl.allegro.tech.hermes.schema.RawSchemaClient; | ||
import pl.allegro.tech.hermes.schema.SchemaVersion; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public class ReadMetricsTrackingRawSchemaClient implements RawSchemaClient { | ||
private final RawSchemaClient rawSchemaClient; | ||
private final HermesMetrics hermesMetrics; | ||
private final SchemaRepositoryType schemaRepoType; | ||
|
||
public ReadMetricsTrackingRawSchemaClient( | ||
RawSchemaClient rawSchemaClient, | ||
HermesMetrics hermesMetrics, | ||
SchemaRepositoryType schemaRepoType) { | ||
this.rawSchemaClient = rawSchemaClient; | ||
this.hermesMetrics = hermesMetrics; | ||
this.schemaRepoType = schemaRepoType; | ||
} | ||
|
||
@Override | ||
public Optional<RawSchema> getSchema(TopicName topic, SchemaVersion version) { | ||
return timedSchema(() -> rawSchemaClient.getSchema(topic, version)); | ||
} | ||
|
||
@Override | ||
public Optional<RawSchema> getLatestSchema(TopicName topic) { | ||
return timedSchema(() -> rawSchemaClient.getLatestSchema(topic)); | ||
} | ||
|
||
@Override | ||
public List<SchemaVersion> getVersions(TopicName topic) { | ||
return timedVersions(() -> rawSchemaClient.getVersions(topic)); | ||
} | ||
|
||
@Override | ||
public void registerSchema(TopicName topic, RawSchema rawSchema) { | ||
rawSchemaClient.registerSchema(topic, rawSchema); | ||
} | ||
|
||
@Override | ||
public void deleteAllSchemaVersions(TopicName topic) { | ||
rawSchemaClient.deleteAllSchemaVersions(topic); | ||
} | ||
|
||
private <T> T timedSchema(Supplier<? extends T> callable) { | ||
return timed(callable, Timers.GET_SCHEMA_LATENCY); | ||
} | ||
|
||
private <T> T timedVersions(Supplier<? extends T> callable) { | ||
return timed(callable, Timers.GET_SCHEMA_VERSIONS_LATENCY); | ||
} | ||
|
||
private <T> T timed(Supplier<? extends T> callable, String schemaTimer) { | ||
try (Timer.Context time = startLatencyTimer(schemaTimer)) { | ||
return callable.get(); | ||
} | ||
} | ||
|
||
private Timer.Context startLatencyTimer(String schemaReadLatency) { | ||
return hermesMetrics.schemaTimer(schemaReadLatency, schemaRepoType).time(); | ||
} | ||
|
||
} |
13 changes: 12 additions & 1 deletion
13
hermes-common/src/main/java/pl/allegro/tech/hermes/common/schema/SchemaRepositoryType.java
This file contains 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 |
---|---|---|
@@ -1,5 +1,16 @@ | ||
package pl.allegro.tech.hermes.common.schema; | ||
|
||
public enum SchemaRepositoryType { | ||
SCHEMA_REPO, SCHEMA_REGISTRY | ||
SCHEMA_REPO("schema-repo"), SCHEMA_REGISTRY("schema-registry"); | ||
|
||
private final String metricName; | ||
|
||
SchemaRepositoryType(String metricName) { | ||
this.metricName = metricName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return metricName; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...groovy/pl/allegro/tech/hermes/common/schema/ReadMetricsTrackingRawSchemaClientTest.groovy
This file contains 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,91 @@ | ||
package pl.allegro.tech.hermes.common.schema | ||
|
||
import com.codahale.metrics.Timer | ||
import pl.allegro.tech.hermes.api.RawSchema | ||
import pl.allegro.tech.hermes.api.TopicName | ||
import pl.allegro.tech.hermes.common.metric.HermesMetrics | ||
import pl.allegro.tech.hermes.common.metric.Timers | ||
import pl.allegro.tech.hermes.schema.RawSchemaClient | ||
import pl.allegro.tech.hermes.schema.SchemaVersion | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
import static pl.allegro.tech.hermes.common.schema.SchemaRepositoryType.SCHEMA_REGISTRY | ||
|
||
class ReadMetricsTrackingRawSchemaClientTest extends Specification { | ||
@Shared | ||
TopicName topicName = TopicName.fromQualifiedName("someGroup.someTopic") | ||
|
||
@Shared | ||
SchemaVersion schemaVersion = SchemaVersion.valueOf(1) | ||
|
||
@Shared | ||
RawSchema schema = RawSchema.valueOf("some_schema") | ||
|
||
HermesMetrics hermesMetrics = Mock() | ||
|
||
Timer schemaLatencyTimer = new Timer() | ||
|
||
Timer schemaVersionsLatencyTimer = new Timer() | ||
|
||
RawSchemaClient rawSchemaClient = Mock() | ||
|
||
@Subject | ||
RawSchemaClient readMetricsTrackingClient = new ReadMetricsTrackingRawSchemaClient(rawSchemaClient, hermesMetrics, SCHEMA_REGISTRY) | ||
|
||
def "should track latency metrics for schema retrieval"(){ | ||
expect: | ||
schemaLatencyTimer.count == 0 | ||
|
||
when: | ||
readMetricsTrackingClient.getSchema(topicName, schemaVersion) | ||
|
||
then: | ||
1 * hermesMetrics.schemaTimer(Timers.GET_SCHEMA_LATENCY, SCHEMA_REGISTRY) >> schemaLatencyTimer | ||
1 * rawSchemaClient.getSchema(topicName, schemaVersion) | ||
schemaLatencyTimer.count == 1 | ||
} | ||
|
||
def "should track latency metrics for latest schema retrieval"(){ | ||
expect: | ||
schemaLatencyTimer.count == 0 | ||
|
||
when: | ||
readMetricsTrackingClient.getLatestSchema(topicName) | ||
|
||
then: | ||
1 * hermesMetrics.schemaTimer(Timers.GET_SCHEMA_LATENCY, SCHEMA_REGISTRY) >> schemaLatencyTimer | ||
1 * rawSchemaClient.getLatestSchema(topicName) | ||
schemaLatencyTimer.count == 1 | ||
} | ||
|
||
def "should track latency metrics for versions retrieval"(){ | ||
expect: | ||
schemaVersionsLatencyTimer.count == 0 | ||
|
||
when: | ||
readMetricsTrackingClient.getVersions(topicName) | ||
|
||
then: | ||
1 * hermesMetrics.schemaTimer(Timers.GET_SCHEMA_VERSIONS_LATENCY, SCHEMA_REGISTRY) >> schemaVersionsLatencyTimer | ||
1 * rawSchemaClient.getVersions(topicName) | ||
schemaVersionsLatencyTimer.count == 1 | ||
} | ||
|
||
def "should call inner client for non-read operations"() { | ||
when: | ||
readMetricsTrackingClient.deleteAllSchemaVersions(topicName) | ||
|
||
then: | ||
1 * rawSchemaClient.deleteAllSchemaVersions(topicName) | ||
schemaVersionsLatencyTimer.count == 0 | ||
|
||
when: | ||
readMetricsTrackingClient.registerSchema(topicName, schema) | ||
|
||
then: | ||
1 * rawSchemaClient.registerSchema(topicName, schema) | ||
schemaLatencyTimer.count == 0 | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.