Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #4824] Add HTTP Sink Connector #4837

Merged
merged 27 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8275b59
feat: Add HTTP Sink Connector
cnzakii Apr 13, 2024
6776490
refactor: Replace okHttpClient with vertx.WebClient
cnzakii Apr 13, 2024
003f078
fix: Resolving dependency conflicts
cnzakii Apr 14, 2024
cd21ea3
test: Add HttpSinkConnectorTest
cnzakii Apr 14, 2024
dc08ce1
Merge branch 'apache:master' into feat_4824
cnzakii Apr 14, 2024
8486080
fix: Add License
cnzakii Apr 14, 2024
f2e3835
fix: Solving dependency issues
cnzakii Apr 14, 2024
eda1d14
fix: License Check
cnzakii Apr 14, 2024
611c8d6
feat: Add HTTPS/SSL support
cnzakii Apr 14, 2024
64f2822
fix: Optimize logging
cnzakii Apr 15, 2024
77ad32f
feat: Add webhook functionality
cnzakii Apr 16, 2024
3eb3af6
fix: Fix some bugs
cnzakii Apr 16, 2024
3c59c8e
test: add callback test
cnzakii Apr 16, 2024
408aaa6
refactor: Add webhook Support
cnzakii Apr 17, 2024
5cb55a8
fix: Optimization tests and configuration additions
cnzakii Apr 18, 2024
1050f8a
fix: code style
cnzakii Apr 18, 2024
fe2b732
feat: rebuild WebhookHttpSinkHandler and add RetryHttpSinkHandler
cnzakii Apr 27, 2024
7e2d978
fix: fix ci
cnzakii Apr 27, 2024
9c9e4a8
refactor: Use failsafe alternative resilience4j and optimize webhook …
cnzakii Apr 28, 2024
33b14e4
fix: fix License Check
cnzakii Apr 28, 2024
4af7455
fix: update something
cnzakii Apr 29, 2024
5e2bf52
fix: fix ci
cnzakii Apr 29, 2024
3dcc5a9
fix: update something
cnzakii Apr 29, 2024
6f3b361
fix: Optimized naming
cnzakii Apr 29, 2024
71c12e8
fix: fix ci
cnzakii Apr 29, 2024
6732e53
fix: fix style check error
cnzakii Apr 29, 2024
2f2e81e
test: update HttpSinkConnectorTest
cnzakii Apr 30, 2024
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 @@ -75,14 +75,14 @@ private void doInit() {
}

int maxRetries = this.httpSinkConfig.connectorConfig.getRetryConfig().getMaxRetries();
if (maxRetries < 0) {
throw new IllegalArgumentException("Max retries must be greater than or equal to 0.");
} else if (maxRetries == 0) {
if (maxRetries == 0) {
// Use the original sink handler
this.sinkHandler = nonRetryHandler;
} else {
} else if (maxRetries > 0) {
// Wrap the sink handler with a retry handler
this.sinkHandler = new RetryHttpSinkHandler(this.httpSinkConfig.connectorConfig, nonRetryHandler);
} else {
throw new IllegalArgumentException("Max retries must be greater than or equal to 0.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;

import java.time.LocalDateTime;
import java.util.UUID;

import lombok.Builder;
import lombok.Data;
Expand All @@ -33,7 +34,11 @@ public class HttpConnectRecord {

private String type;

private String timestamp;
private String time;

private String uuid;

private String eventId;

private ConnectRecord data;

Expand All @@ -46,7 +51,9 @@ public class HttpConnectRecord {
public static HttpConnectRecord convertConnectRecord(ConnectRecord record, String type) {
return HttpConnectRecord.builder()
.type(type)
.timestamp(LocalDateTime.now().toString())
.time(LocalDateTime.now().toString())
.uuid(UUID.randomUUID().toString())
.eventId(type + "-" + record.getTimestamp())
.data(record)
cnzakii marked this conversation as resolved.
Show resolved Hide resolved
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,43 @@ public void handle(ConnectRecord record) {
*/
@Override
public Future<HttpResponse<Buffer>> deliver(URI url, HttpConnectRecord httpConnectRecord) {
// Only webhook mode needs to use the firstTryId
String firstTryId = UUID.randomUUID().toString();
// Only webhook mode needs to use the UUID to identify the request
String id = httpConnectRecord.getUuid();

// Build the retry policy
RetryPolicy<HttpResponse<Buffer>> retryPolicy = retryPolicyBuilder
.onSuccess(e -> {
.onSuccess(event -> {
if (connectorConfig.getWebhookConfig().isActivate()) {
// convert the result to an HttpExportRecord
HttpExportRecord exportRecord = covertToExportRecord(e, e.getResult(), e.getException(), url, firstTryId);
HttpExportRecord exportRecord = covertToExportRecord(httpConnectRecord, event, event.getResult(), event.getException(), url, id);
// add the data to the queue
((WebhookHttpSinkHandler) sinkHandler).addDataToQueue(exportRecord);
}
})
.onRetry(e -> {
.onRetry(event -> {
if (log.isDebugEnabled()) {
log.warn("Retrying the request to {} for the {} time. HttpConnectRecord= {}", url, e.getAttemptCount(), httpConnectRecord);
log.warn("Retrying the request to {} for the {} time. HttpConnectRecord= {}", url, event.getAttemptCount(), httpConnectRecord);
} else {
log.warn("Retrying the request to {} for the {} time.", url, e.getAttemptCount());
log.warn("Retrying the request to {} for the {} time.", url, event.getAttemptCount());
}
if (connectorConfig.getWebhookConfig().isActivate()) {
HttpExportRecord exportRecord = covertToExportRecord(e, e.getLastResult(), e.getLastException(), url, firstTryId);
HttpExportRecord exportRecord =
covertToExportRecord(httpConnectRecord, event, event.getLastResult(), event.getLastException(), url, id);
((WebhookHttpSinkHandler) sinkHandler).addDataToQueue(exportRecord);
}
// update the HttpConnectRecord
httpConnectRecord.setTime(LocalDateTime.now().toString());
httpConnectRecord.setUuid(UUID.randomUUID().toString());
})
.onFailure(e -> {
.onFailure(event -> {
if (log.isDebugEnabled()) {
log.error("Failed to send the request to {} after {} attempts. HttpConnectRecord= {}", url, e.getAttemptCount(),
httpConnectRecord, e.getException());
log.error("Failed to send the request to {} after {} attempts. HttpConnectRecord= {}", url, event.getAttemptCount(),
httpConnectRecord, event.getException());
} else {
log.error("Failed to send the request to {} after {} attempts.", url, e.getAttemptCount(), e.getException());
log.error("Failed to send the request to {} after {} attempts.", url, event.getAttemptCount(), event.getException());
}
if (connectorConfig.getWebhookConfig().isActivate()) {
HttpExportRecord exportRecord = covertToExportRecord(e, e.getResult(), e.getException(), url, firstTryId);
HttpExportRecord exportRecord = covertToExportRecord(httpConnectRecord, event, event.getResult(), event.getException(), url, id);
((WebhookHttpSinkHandler) sinkHandler).addDataToQueue(exportRecord);
}
}).build();
Expand All @@ -170,25 +174,24 @@ public Future<HttpResponse<Buffer>> deliver(URI url, HttpConnectRecord httpConne
/**
* Converts the ExecutionCompletedEvent to an HttpExportRecord.
*
* @param event the ExecutionCompletedEvent to convert
* @param response the response of the request, may be null
* @param e the exception thrown during the request, may be null
* @param url the URL the request was sent to
* @param firstTryId the UUID of the first try
* @param httpConnectRecord HttpConnectRecord
* @param event ExecutionEvent
* @param response the response of the request, may be null
* @param e the exception thrown during the request, may be null
* @param url the URL the request was sent to
* @param id UUID
* @return the converted HttpExportRecord
*/
private HttpExportRecord covertToExportRecord(ExecutionEvent event, HttpResponse<Buffer> response, Throwable e, URI url, String firstTryId) {
private HttpExportRecord covertToExportRecord(HttpConnectRecord httpConnectRecord, ExecutionEvent event, HttpResponse<Buffer> response,
Throwable e, URI url, String id) {
HttpExportMetadataBuilder builder = HttpExportMetadata.builder()
.url(url.toString())
.receivedTime(LocalDateTime.now())
.retryNum(event.getAttemptCount() - 1);
.retryNum(event.getAttemptCount() - 1)
.uuid(httpConnectRecord.getUuid());

if (event.getAttemptCount() == 1) {
builder.retriedBy(null)
.uuid(firstTryId);
} else {
builder.retriedBy(firstTryId)
.uuid(UUID.randomUUID().toString());
if (event.getAttemptCount() > 1) {
builder.retriedBy(id);
}

if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -233,7 +232,7 @@ public Future<HttpResponse<Buffer>> deliver(URI url, HttpConnectRecord httpConne
.url(url.toString())
.receivedTime(LocalDateTime.now())
.retriedBy(null)
.uuid(UUID.randomUUID().toString())
.uuid(httpConnectRecord.getUuid())
.retryNum(0);

if (arr.succeeded()) {
Expand Down Expand Up @@ -271,11 +270,7 @@ public void addDataToQueue(HttpExportRecord exportRecord) {
// Try to put the received data into the queue
if (receivedDataQueue.offer(exportRecord)) {
currentQueueSize.incrementAndGet();
if (log.isDebugEnabled()) {
log.debug("Successfully put the received data into the queue: {}", exportRecord);
} else {
log.info("Successfully put the received data into the queue");
}
log.debug("Successfully put the received data into the queue: {}", exportRecord);
} else {
log.error("Failed to put the received data into the queue: {}", exportRecord);
}
Expand Down