Skip to content

Commit 406ca84

Browse files
authored
Propagate record timestamps (#21)
Propagates kafka record timestamps for detection latency calculations
1 parent b0c3336 commit 406ca84

File tree

5 files changed

+71
-26
lines changed

5 files changed

+71
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Rockset Kafka Connect Changelog
2+
3+
## v2.1.0 2024-01-24
4+
- Propagate kafka record timestamps for source detection latency
5+
26
## v2.0.0 2023-10-30
37
- New configuration option `rockset.retry.backoff.ms`
48
- Removed deprecated configurations `rockset.apikey`, `rockset.collection`, and `rockset.workspace`

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>rockset</groupId>
77
<artifactId>kafka-connect-rockset</artifactId>
8-
<version>2.0.0</version>
8+
<version>2.1.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>kafka-connect-rockset</name>

src/main/java/rockset/RocksetRequestWrapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import okhttp3.Request;
1515
import okhttp3.RequestBody;
1616
import okhttp3.Response;
17+
import org.apache.kafka.common.record.TimestampType;
1718
import org.apache.kafka.connect.errors.ConnectException;
1819
import org.apache.kafka.connect.errors.RetriableException;
1920
import org.apache.kafka.connect.sink.SinkRecord;
@@ -68,6 +69,15 @@ public void addDoc(
6869
.key(key)
6970
.offset(record.kafkaOffset())
7071
.partition(record.kafkaPartition());
72+
73+
if(record.timestamp() != null){
74+
if (record.timestampType() == TimestampType.CREATE_TIME){
75+
message.createTime(record.timestamp());
76+
} else if (record.timestampType() == TimestampType.LOG_APPEND_TIME){
77+
message.logAppendTime(record.timestamp());
78+
}
79+
}
80+
7181
messages.add(message);
7282
} catch (Exception e) {
7383
throw new ConnectException("Invalid JSON encountered in stream ", e);

src/main/java/rockset/RocksetSinkTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void put(Collection<SinkRecord> records) {
106106
e ->
107107
executorService.submit(
108108
() ->
109-
requestWrapper.addDoc(
109+
requestWrapper.addDoc(
110110
e.getKey().topic(),
111111
e.getValue(),
112112
recordParser,

src/main/java/rockset/models/KafkaMessage.java

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package rockset.models;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.google.common.base.Objects;
45
import com.google.gson.annotations.SerializedName;
56
import io.swagger.annotations.ApiModelProperty;
6-
import java.util.Objects;
77

88
public class KafkaMessage {
99

@@ -23,6 +23,12 @@ public class KafkaMessage {
2323
@SerializedName("key")
2424
public Object key;
2525

26+
@SerializedName("create_time")
27+
public Long createTime;
28+
29+
@SerializedName("log_append_time")
30+
public Long logAppendTime;
31+
2632
/*
2733
* Getters
2834
*/
@@ -51,6 +57,19 @@ public Object getKey() {
5157
return this.key;
5258
}
5359

60+
@JsonProperty("create_time")
61+
@ApiModelProperty(required = false, value = "Create time of the message")
62+
public Long getCreateTime() {
63+
return this.createTime;
64+
}
65+
66+
@JsonProperty("log_append_time")
67+
@ApiModelProperty(required = false, value = "Log append time of the message")
68+
public Long getLogAppendTime() {
69+
return this.logAppendTime;
70+
}
71+
72+
5473
/*
5574
* Setters
5675
*/
@@ -71,6 +90,16 @@ public void setKey(Object key) {
7190
this.key = key;
7291
}
7392

93+
94+
public void setLogAppendTime(Long timestamp) {
95+
this.logAppendTime = timestamp;
96+
}
97+
98+
public void setCreateTime(Long timestamp) {
99+
this.createTime = timestamp;
100+
}
101+
102+
74103
/*
75104
* Builders
76105
*/
@@ -95,6 +124,16 @@ public KafkaMessage key(Object key) {
95124
return this;
96125
}
97126

127+
public KafkaMessage logAppendTime(Long timestamp) {
128+
this.logAppendTime = timestamp;
129+
return this;
130+
}
131+
132+
public KafkaMessage createTime(Long timestamp) {
133+
this.createTime = timestamp;
134+
return this;
135+
}
136+
98137
/*
99138
* Utilities
100139
*/
@@ -107,35 +146,27 @@ private String toIndentedString(java.lang.Object o) {
107146
}
108147

109148
@Override
110-
public String toString() {
111-
final StringBuilder sb = new StringBuilder();
112-
sb.append("class KafkaMessage {\n");
113-
114-
sb.append(" partition: ").append(this.toIndentedString(this.partition)).append("\n");
115-
sb.append(" offset: ").append(this.toIndentedString(this.offset)).append("\n");
116-
sb.append(" document: ").append(this.toIndentedString(this.document)).append("\n");
117-
sb.append(" key: ").append(this.toIndentedString(this.key)).append("\n");
118-
sb.append("}");
119-
return sb.toString();
149+
public boolean equals(Object o) {
150+
if (this == o) return true;
151+
if (o == null || getClass() != o.getClass()) return false;
152+
KafkaMessage that = (KafkaMessage) o;
153+
return partition == that.partition && offset == that.offset && Objects.equal(document, that.document) && Objects.equal(key, that.key) && Objects.equal(createTime, that.createTime) && Objects.equal(logAppendTime, that.logAppendTime);
120154
}
121155

122156
@Override
123157
public int hashCode() {
124-
return Objects.hash(this.document, this.partition, this.offset, this.key);
158+
return Objects.hashCode(document, partition, offset, key, createTime, logAppendTime);
125159
}
126160

127161
@Override
128-
public boolean equals(java.lang.Object o) {
129-
if (this == o) {
130-
return true;
131-
}
132-
if (o == null || this.getClass() != o.getClass()) {
133-
return false;
134-
}
135-
final KafkaMessage kafkaMessage = (KafkaMessage) o;
136-
return this.getPartition() == kafkaMessage.getPartition()
137-
&& this.getOffset() == kafkaMessage.getOffset()
138-
&& Objects.equals(this.document, kafkaMessage.document)
139-
&& Objects.equals(this.key, kafkaMessage.key);
162+
public String toString() {
163+
return "KafkaMessage{" +
164+
"document=" + document +
165+
", partition=" + partition +
166+
", offset=" + offset +
167+
", key=" + key +
168+
", createTime=" + createTime +
169+
", logAppendTime=" + logAppendTime +
170+
'}';
140171
}
141172
}

0 commit comments

Comments
 (0)