Search in sources :

Example 1 with SSLSender

use of org.komamitsu.fluency.fluentd.ingester.sender.SSLSender in project fluency by komamitsu.

the class FluencyBuilderForFluentdTest method buildWithSslAndComplexConfig.

@Test
void buildWithSslAndComplexConfig() throws IOException {
    String tmpdir = System.getProperty("java.io.tmpdir");
    assertThat(tmpdir, is(notNullValue()));
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(true);
    builder.setFlushAttemptIntervalMillis(200);
    builder.setMaxBufferSize(Long.MAX_VALUE);
    builder.setBufferChunkInitialSize(7 * 1024 * 1024);
    builder.setBufferChunkRetentionSize(13 * 1024 * 1024);
    builder.setJvmHeapBufferMode(true);
    builder.setSenderMaxRetryCount(99);
    builder.setSenderBaseRetryIntervalMillis(20);
    builder.setSenderMaxRetryIntervalMillis(100000);
    builder.setConnectionTimeoutMilli(12345);
    builder.setReadTimeoutMilli(9876);
    builder.setAckResponseMode(true);
    builder.setWaitUntilBufferFlushed(42);
    builder.setWaitUntilFlusherTerminated(24);
    builder.setFileBackupDir(tmpdir);
    try (Fluency fluency = builder.build(Arrays.asList(new InetSocketAddress("333.333.333.333", 11111), new InetSocketAddress("444.444.444.444", 22222)))) {
        assertThat(fluency.getFlusher().getIngester().getSender(), instanceOf(RetryableSender.class));
        RetryableSender retryableSender = (RetryableSender) fluency.getFlusher().getIngester().getSender();
        assertThat(retryableSender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
        ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) retryableSender.getRetryStrategy();
        assertThat(retryStrategy.getMaxRetryCount(), is(99));
        assertThat(retryStrategy.getBaseIntervalMillis(), is(20));
        assertThat(retryStrategy.getMaxIntervalMillis(), is(100000));
        assertThat(retryableSender.getBaseSender(), instanceOf(MultiSender.class));
        MultiSender multiSender = (MultiSender) retryableSender.getBaseSender();
        assertThat(multiSender.getSenders().size(), is(2));
        assertThat(multiSender.getSenders().get(0), instanceOf(SSLSender.class));
        {
            SSLSender sender = (SSLSender) multiSender.getSenders().get(0);
            assertThat(sender.getHost(), is("333.333.333.333"));
            assertThat(sender.getPort(), is(11111));
            assertThat(sender.getConnectionTimeoutMilli(), is(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(SSLHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("333.333.333.333"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(11111));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
        assertThat(multiSender.getSenders().get(1), instanceOf(SSLSender.class));
        {
            SSLSender sender = (SSLSender) multiSender.getSenders().get(1);
            assertThat(sender.getHost(), is("444.444.444.444"));
            assertThat(sender.getPort(), is(22222));
            assertThat(sender.getConnectionTimeoutMilli(), is(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(SSLHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("444.444.444.444"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(22222));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) SSLSender(org.komamitsu.fluency.fluentd.ingester.sender.SSLSender) InetSocketAddress(java.net.InetSocketAddress) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) FailureDetector(org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector) MultiSender(org.komamitsu.fluency.fluentd.ingester.sender.MultiSender) RetryableSender(org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender) Test(org.junit.jupiter.api.Test)

Example 2 with SSLSender

use of org.komamitsu.fluency.fluentd.ingester.sender.SSLSender in project fluency by komamitsu.

the class FluencyBuilderForFluentd method createBaseSender.

private FluentdSender createBaseSender(String host, Integer port, boolean withHeartBeater) {
    if (withHeartBeater && port == null) {
        throw new IllegalArgumentException("`port` should be specified when using heartbeat");
    }
    if (isSslEnabled()) {
        SSLSender.Config senderConfig = new SSLSender.Config();
        FailureDetector failureDetector = null;
        if (host != null) {
            senderConfig.setHost(host);
        }
        if (port != null) {
            senderConfig.setPort(port);
        }
        if (withHeartBeater) {
            SSLHeartbeater.Config hbConfig = new SSLHeartbeater.Config();
            hbConfig.setHost(host);
            hbConfig.setPort(port);
            SSLHeartbeater heartbeater = new SSLHeartbeater(hbConfig);
            failureDetector = new FailureDetector(new PhiAccrualFailureDetectStrategy(), heartbeater);
        }
        if (connectionTimeoutMilli != null) {
            senderConfig.setConnectionTimeoutMilli(connectionTimeoutMilli);
        }
        if (readTimeoutMilli != null) {
            senderConfig.setReadTimeoutMilli(readTimeoutMilli);
        }
        return new SSLSender(senderConfig, failureDetector);
    } else {
        TCPSender.Config senderConfig = new TCPSender.Config();
        FailureDetector failureDetector = null;
        if (host != null) {
            senderConfig.setHost(host);
        }
        if (port != null) {
            senderConfig.setPort(port);
        }
        if (withHeartBeater) {
            TCPHeartbeater.Config hbConfig = new TCPHeartbeater.Config();
            hbConfig.setHost(host);
            hbConfig.setPort(port);
            TCPHeartbeater heartbeater = new TCPHeartbeater(hbConfig);
            failureDetector = new FailureDetector(new PhiAccrualFailureDetectStrategy(), heartbeater);
        }
        if (connectionTimeoutMilli != null) {
            senderConfig.setConnectionTimeoutMilli(connectionTimeoutMilli);
        }
        if (readTimeoutMilli != null) {
            senderConfig.setReadTimeoutMilli(readTimeoutMilli);
        }
        return new TCPSender(senderConfig, failureDetector);
    }
}
Also used : SSLSender(org.komamitsu.fluency.fluentd.ingester.sender.SSLSender) PhiAccrualFailureDetectStrategy(org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.PhiAccrualFailureDetectStrategy) SSLHeartbeater(org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.SSLHeartbeater) FailureDetector(org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector) TCPHeartbeater(org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater) TCPSender(org.komamitsu.fluency.fluentd.ingester.sender.TCPSender)

Aggregations

SSLSender (org.komamitsu.fluency.fluentd.ingester.sender.SSLSender)2 FailureDetector (org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector)2 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.jupiter.api.Test)1 Fluency (org.komamitsu.fluency.Fluency)1 MultiSender (org.komamitsu.fluency.fluentd.ingester.sender.MultiSender)1 RetryableSender (org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender)1 TCPSender (org.komamitsu.fluency.fluentd.ingester.sender.TCPSender)1 PhiAccrualFailureDetectStrategy (org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.PhiAccrualFailureDetectStrategy)1 SSLHeartbeater (org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.SSLHeartbeater)1 TCPHeartbeater (org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater)1 ExponentialBackOffRetryStrategy (org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy)1