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

feat: add HTTP connection interceptor which TTL configuration #643

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

bednar
Copy link
Contributor

@bednar bednar commented Nov 8, 2023

Proposed Changes

This PR introduces the ConnectionClosingInterceptor.

This interceptor closes connections that exceed a specified maximum lifetime age (TTL). It's beneficial for scenarios where your application requires establishing new connections to the same host after a predetermined interval. This interceptor is most effective in applications that use a single connection, meaning requests are not made in parallel.

package example;

import java.time.Duration;
import java.util.Collections;

import okhttp3.OkHttpClient;
import okhttp3.Protocol;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxDBClientOptions;
import com.influxdb.rest.ConnectionClosingInterceptor;

public class InfluxTTLExample {

    public static void main(final String[] args) throws InterruptedException {


        ConnectionClosingInterceptor interceptor = new ConnectionClosingInterceptor(Duration.ofSeconds(60));

        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
                .addNetworkInterceptor(interceptor)
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .eventListenerFactory(call -> interceptor);

        InfluxDBClientOptions options = InfluxDBClientOptions.builder()
                .okHttpClient(okHttpClientBuilder)
                .url("http://localhost:8086")
                .authenticateToken("my-token".toCharArray())
                .build();

        try (InfluxDBClient client = InfluxDBClientFactory.create(options)) {

            //
            // TODO use client
            //
        }
    }
}

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • mvn test completes successfully
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (997599d) 88.39% compared to head (964e316) 88.35%.

Files Patch % Lines
...om/influxdb/rest/ConnectionClosingInterceptor.java 75.00% 2 Missing and 3 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #643      +/-   ##
============================================
- Coverage     88.39%   88.35%   -0.04%     
+ Complexity      779      777       -2     
============================================
  Files           172      173       +1     
  Lines          7058     7078      +20     
  Branches        389      393       +4     
============================================
+ Hits           6239     6254      +15     
- Misses          697      699       +2     
- Partials        122      125       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bednar bednar marked this pull request as ready for review November 10, 2023 13:05
@bednar bednar added this to the 6.12.0 milestone Dec 5, 2023
@bednar bednar merged commit d05c6d2 into master Dec 13, 2023
11 checks passed
@bednar bednar deleted the connection-interceptor branch December 13, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants