Skip to content

Commit e0fcc34

Browse files
danielbelchiorebyhr
authored andcommitted
Add support for configuring HTTP method in event listener
Add support for configuring the HTTP method used by the HTTP Event Listener. Previously, only POST was supported. Now users can choose between POST (default) and PUT via the new `http-event-listener.connect-http-method` setting in the configuration file. This change increases flexibility for different integration scenarios that may require PUT requests instead of POST.
1 parent 170c714 commit e0fcc34

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

docs/src/main/sphinx/admin/event-listeners-http.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ event-listener.config-files=etc/http-event-listener.properties,...
7575
[](http-event-listener-custom-headers) for more details
7676
- Empty
7777

78+
* - http-event-listener.connect-http-method
79+
- Specifies the HTTP method to use for the request. Supported values
80+
are POST and PUT.
81+
- `POST`
82+
7883
* - http-event-listener.connect-retry-count
7984
- The number of retries on server error. A server is considered to be
8085
in an error state when the response code is 500 or higher

plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import static com.google.common.net.MediaType.JSON_UTF_8;
4343
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
4444
import static io.airlift.http.client.JsonBodyGenerator.jsonBodyGenerator;
45-
import static io.airlift.http.client.Request.Builder.preparePost;
4645
import static io.airlift.http.client.StatusResponseHandler.StatusResponse;
4746
import static io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler;
4847
import static java.util.Objects.requireNonNull;
@@ -75,6 +74,7 @@ public class HttpEventListener
7574
private final double backoffBase;
7675
private final Map<String, String> httpHeaders;
7776
private final URI ingestUri;
77+
private final HttpEventListenerHttpMethod httpMethod;
7878
private final ScheduledExecutorService executor;
7979

8080
@Inject
@@ -100,6 +100,7 @@ public HttpEventListener(
100100
this.retryDelay = config.getRetryDelay();
101101
this.maxDelay = config.getMaxDelay();
102102
this.backoffBase = config.getBackoffBase();
103+
this.httpMethod = config.getHttpMethod();
103104
this.httpHeaders = ImmutableMap.copyOf(config.getHttpHeaders());
104105

105106
try {
@@ -144,7 +145,8 @@ public void splitCompleted(SplitCompletedEvent splitCompletedEvent)
144145

145146
private void sendLog(BodyGenerator eventBodyGenerator, String queryId)
146147
{
147-
Request request = preparePost()
148+
Request request = Request.builder()
149+
.setMethod(httpMethod.name())
148150
.addHeaders(Multimaps.forMap(httpHeaders))
149151
.addHeader(CONTENT_TYPE, JSON_UTF_8.toString())
150152
.setUri(ingestUri)

plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListenerConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class HttpEventListenerConfig
3333
private Duration maxDelay = Duration.valueOf("1m");
3434
private final EnumSet<HttpEventListenerEventType> loggedEvents = EnumSet.noneOf(HttpEventListenerEventType.class);
3535
private String ingestUri;
36+
private HttpEventListenerHttpMethod httpMethod = HttpEventListenerHttpMethod.POST;
3637
private Map<String, String> httpHeaders = ImmutableMap.of();
3738

3839
@ConfigDescription("Will log io.trino.spi.eventlistener.QueryCreatedEvent")
@@ -94,6 +95,20 @@ public HttpEventListenerConfig setIngestUri(String ingestUri)
9495
return this;
9596
}
9697

98+
@NotNull
99+
public HttpEventListenerHttpMethod getHttpMethod()
100+
{
101+
return httpMethod;
102+
}
103+
104+
@ConfigDescription("Specifies the HTTP method to use for the request. Supported values are POST (default) and PUT.")
105+
@Config("http-event-listener.connect-http-method")
106+
public HttpEventListenerConfig setHttpMethod(HttpEventListenerHttpMethod httpMethod)
107+
{
108+
this.httpMethod = httpMethod;
109+
return this;
110+
}
111+
97112
public Map<String, String> getHttpHeaders()
98113
{
99114
return httpHeaders;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.plugin.httpquery;
15+
16+
public enum HttpEventListenerHttpMethod
17+
{
18+
POST,
19+
PUT
20+
}

plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListenerConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void testDefaults()
3737
.setRetryDelay(Duration.succinctDuration(1, TimeUnit.SECONDS))
3838
.setMaxDelay(Duration.succinctDuration(1, TimeUnit.MINUTES))
3939
.setBackoffBase(2.0)
40+
.setHttpMethod(HttpEventListenerHttpMethod.POST)
4041
.setLogCompleted(false)
4142
.setLogCreated(false)
4243
.setLogSplit(false));
@@ -53,6 +54,7 @@ void testExplicitPropertyMappings()
5354
"http-event-listener.connect-ingest-uri", "http://example.com:8080/api",
5455
"http-event-listener.connect-http-headers", "Authorization: Trust Me, Cache-Control: no-cache",
5556
"http-event-listener.connect-retry-count", "2",
57+
"http-event-listener.connect-http-method", "PUT",
5658
"http-event-listener.connect-retry-delay", "101s",
5759
"http-event-listener.connect-backoff-base", "1.5",
5860
"http-event-listener.connect-max-delay", "10m");
@@ -64,6 +66,7 @@ void testExplicitPropertyMappings()
6466
.setIngestUri("http://example.com:8080/api")
6567
.setHttpHeaders(List.of("Authorization: Trust Me", "Cache-Control: no-cache"))
6668
.setRetryCount(2)
69+
.setHttpMethod(HttpEventListenerHttpMethod.PUT)
6770
.setRetryDelay(Duration.succinctDuration(101, TimeUnit.SECONDS))
6871
.setBackoffBase(1.5)
6972
.setMaxDelay(Duration.succinctDuration(10, TimeUnit.MINUTES));

0 commit comments

Comments
 (0)