-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
114 additions
and
40 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
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
8 changes: 0 additions & 8 deletions
8
canary/src/main/java/io/littlehorse/canary/prometheus/Measurable.java
This file was deleted.
Oops, something went wrong.
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
76 changes: 73 additions & 3 deletions
76
...y/src/test/java/io/littlehorse/canary/aggregator/topology/TaskRunLatencyTopologyTest.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,9 +1,79 @@ | ||
package io.littlehorse.canary.aggregator.topology; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.apache.kafka.streams.TopologyTestDriver; | ||
import com.google.protobuf.util.Timestamps; | ||
import io.littlehorse.canary.aggregator.internal.MetricTimeExtractor; | ||
import io.littlehorse.canary.aggregator.serdes.ProtobufSerdes; | ||
import io.littlehorse.canary.proto.Metadata; | ||
import io.littlehorse.canary.proto.Metric; | ||
import io.littlehorse.canary.proto.MetricAverage; | ||
import io.littlehorse.canary.proto.TaskRunLatency; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Properties; | ||
import org.apache.kafka.common.serialization.Serdes; | ||
import org.apache.kafka.streams.*; | ||
import org.apache.kafka.streams.kstream.Consumed; | ||
import org.apache.kafka.streams.state.KeyValueStore; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TaskRunLatencyTopologyTest { | ||
TopologyTestDriver testDriver; | ||
|
||
private TopologyTestDriver testDriver; | ||
private TestInputTopic<String, Metric> inputTopic; | ||
|
||
@BeforeEach | ||
void beforeEach() throws IOException { | ||
String topicName = "canary-metric-beats"; | ||
|
||
Consumed<String, Metric> serdes = Consumed.with(Serdes.String(), ProtobufSerdes.Metric()) | ||
.withTimestampExtractor(new MetricTimeExtractor()); | ||
|
||
StreamsBuilder builder = new StreamsBuilder(); | ||
new TaskRunLatencyTopology(builder.stream(topicName, serdes)); | ||
Topology topology = builder.build(); | ||
|
||
Properties properties = new Properties(); | ||
properties.put( | ||
StreamsConfig.STATE_DIR_CONFIG, | ||
Files.createTempDirectory("canaryStreamUnitTest").toString()); | ||
|
||
testDriver = new TopologyTestDriver(topology, properties); | ||
inputTopic = testDriver.createInputTopic( | ||
topicName, Serdes.String().serializer(), ProtobufSerdes.Metric().serializer()); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
testDriver.close(); | ||
} | ||
|
||
@Test | ||
void calculateLatency() { | ||
String key = "localhost:2023"; | ||
Metric metric1 = buildLatencyMetric(20); | ||
Metric metric2 = buildLatencyMetric(40); | ||
|
||
inputTopic.pipeInput(key, metric1); | ||
inputTopic.pipeInput(key, metric2); | ||
|
||
KeyValueStore store = testDriver.getKeyValueStore("latency-metrics"); | ||
|
||
assertThat(store.get(key)) | ||
.isEqualTo(MetricAverage.newBuilder() | ||
.setSum(60) | ||
.setAvg(30) | ||
.setCount(2) | ||
.build()); | ||
} | ||
|
||
private static Metric buildLatencyMetric(int latency) { | ||
return Metric.newBuilder() | ||
.setMetadata(Metadata.newBuilder().setTime(Timestamps.now())) | ||
.setTaskRunLatency(TaskRunLatency.newBuilder().setLatency(latency)) | ||
.build(); | ||
} | ||
} |