Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions docs/content/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ The following monitors are available:
|`io.druid.segment.realtime.RealtimeMetricsMonitor`|Reports statistics on Realtime nodes.|
|`io.druid.server.metrics.EventReceiverFirehoseMonitor`|Reports how many events have been queued in the EventReceiverFirehose.|
|`io.druid.server.metrics.QueryCountStatsMonitor`|Reports how many queries have been successful/failed/interrupted.|
|`io.druid.server.emitter.HttpEmitterMonitor`|Reports internal metrics of `http` or `parametrized` emitter (see below). Must not be used with another emitter type. See the description of the metrics here: https://github.com/druid-io/druid/pull/4973.|

### Emitting Metrics

Expand All @@ -216,26 +217,26 @@ The Druid servers [emit various metrics](../operations/metrics.html) and alerts

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.http.readTimeout`|The timeout for data reads.|PT5M|
|`druid.emitter.http.flushMillis`|How often the internal message buffer is flushed (data is sent).|60000|
|`druid.emitter.http.flushCount`|How many messages the internal message buffer can hold before flushing (sending).|500|
|`druid.emitter.http.basicAuthentication`|Login and password for authentification in "login:password" form, e. g. `druid.emitter.http.basicAuthentication=admin:adminpassword`|not specified = no authentification|
|`druid.emitter.http.flushTimeOut|The timeout after which an event should be sent to the endpoint, even if internal buffers are not filled, in milliseconds.|not specified = no timeout|
|`druid.emitter.http.batchingStrategy`|The strategy of how the batch is formatted. "ARRAY" means `[event1,event2]`, "NEWLINES" means `event1\nevent2`, ONLY_EVENTS means `event1event2`.|ARRAY|
|`druid.emitter.http.maxBatchSize`|The maximum batch size, in bytes.|5191680 (i. e. 5 MB)|
|`druid.emitter.http.batchQueueSizeLimit`|The maximum number of batches in emitter queue, if there are problems with emitting.|50|
|`druid.emitter.http.minHttpTimeoutMillis`|If the speed of filling batches imposes timeout smaller than that, not even trying to send batch to endpoint, because it will likely fail, not being able to send the data that fast. Configure this depending based on emitter/successfulSending/minTimeMs metric. Reasonable values are 10ms..100ms.|0|
|`druid.emitter.http.recipientBaseUrl`|The base URL to emit messages to. Druid will POST JSON to be consumed at the HTTP endpoint specified by this property.|none, required config|

#### Parametrized Http Emitter Module

`druid.emitter.parametrized.httpEmitting.*` configs correspond to the configs of Http Emitter Modules, see above.
Except `readTimeout` and `recipientBaseUrl`. E. g. `druid.emitter.parametrized.httpEmitting.flushMillis`,
Except `recipientBaseUrl`. E. g. `druid.emitter.parametrized.httpEmitting.flushMillis`,
`druid.emitter.parametrized.httpEmitting.flushCount`, etc.

The additional configs are:

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.parametrized.readTimeout`|The timeout for data reads.|PT5M|
|`druid.emitter.parametrized.recipientBaseUrlPattern`|The URL pattern to send an event to, based on the event's feed. E. g. `http://foo.bar/{feed}`, that will send event to `http://foo.bar/metrics` if the event's feed is "metrics".|none, required config|

#### Composing Emitter Module
Expand Down
2 changes: 1 addition & 1 deletion extensions-contrib/ambari-metrics-emitter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-contrib/graphite-emitter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-contrib/kafka-eight-simpleConsumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-contrib/kafka-emitter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-contrib/statsd-emitter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-core/hdfs-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-core/s3-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion extensions-core/simple-client-sslcontext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<artifactId>java-util</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.druid.java.util.common.ISE;
import io.druid.java.util.common.logger.Logger;

import java.io.Closeable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
Expand Down Expand Up @@ -238,6 +239,16 @@ public <T> T addMaybeStartStartCloseInstance(T o, Stage stage) throws Exception
return o;
}

/**
* Adds a Closeable instance to the lifecycle at {@link Stage#NORMAL} stage, doesn't try to call any "start" method on
* it, use {@link #addStartCloseInstance(Object)} instead if you need the latter behaviour.
*/
public <T extends Closeable> T addCloseableInstance(T o)
{
addHandler(new CloseableHandler(o));
return o;
}

/**
* Adds a handler to the Lifecycle at the Stage.NORMAL stage and starts it if the lifecycle has already been started.
*
Expand Down Expand Up @@ -472,4 +483,33 @@ public void stop()
}
}
}

private static class CloseableHandler implements Handler
{
private static final Logger log = new Logger(CloseableHandler.class);
private final Closeable o;

private CloseableHandler(Closeable o)
{
this.o = o;
}

@Override
public void start() throws Exception
{
// do nothing
}

@Override
public void stop()
{
log.info("Closing object[%s]", o);
try {
o.close();
}
catch (Exception e) {
log.error(e, "Exception when closing object [%s]", o);
}
}
}
}
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,8 @@
<!-- Compile Scope -->
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>http-client</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>server-metrics</artifactId>
<version>0.5.2</version>
<artifactId>java-util</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Expand Down
6 changes: 1 addition & 5 deletions processing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>emitter</artifactId>
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>server-metrics</artifactId>
<artifactId>java-util</artifactId>
</dependency>
<dependency>
<groupId>com.ning</groupId>
Expand Down
6 changes: 1 addition & 5 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>http-client</artifactId>
</dependency>
<dependency>
<groupId>com.metamx</groupId>
<artifactId>server-metrics</artifactId>
<artifactId>java-util</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down

This file was deleted.

22 changes: 12 additions & 10 deletions server/src/main/java/io/druid/server/emitter/HttpEmitterModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import com.google.inject.name.Named;
import com.google.inject.util.Providers;
import com.metamx.emitter.core.Emitter;
import com.metamx.emitter.core.HttpEmitterConfig;
import com.metamx.emitter.core.HttpPostEmitter;
import com.metamx.http.client.HttpClientConfig;
import com.metamx.http.client.HttpClientInit;
import io.druid.guice.JsonConfigProvider;
import io.druid.guice.LazySingleton;
import io.druid.guice.ManageLifecycle;
import io.druid.guice.http.LifecycleUtils;
import io.druid.java.util.common.lifecycle.Lifecycle;
import io.netty.handler.ssl.ClientAuth;
import io.netty.handler.ssl.JdkSslContext;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClientConfig;

import javax.annotation.Nullable;
import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -75,14 +78,13 @@ public Emitter getEmitter(
ObjectMapper jsonMapper
)
{
final HttpClientConfig.Builder builder = HttpClientConfig
.builder()
.withNumConnections(1)
.withReadTimeout(config.get().getReadTimeout().toStandardDuration());

final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
if (sslContext != null) {
builder.withSslContext(sslContext);
builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE));
}
return new HttpPostEmitter(config.get(), HttpClientInit.createClient(builder.build(), LifecycleUtils.asMmxLifecycle(lifecycle)), jsonMapper);
final AsyncHttpClient client = new DefaultAsyncHttpClient(builder.build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emitter doesn't use the metamx http-client anymore? Out of curiosity why is this?

lifecycle.addCloseableInstance(client);

return new HttpPostEmitter(config.get(), client, jsonMapper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.druid.server.emitter;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.metamx.emitter.core.Emitter;
import com.metamx.emitter.core.HttpPostEmitter;
import com.metamx.emitter.core.ParametrizedUriEmitter;
import com.metamx.emitter.service.ServiceEmitter;
import com.metamx.metrics.AbstractMonitor;
import com.metamx.metrics.FeedDefiningMonitor;
import com.metamx.metrics.HttpPostEmitterMonitor;
import com.metamx.metrics.ParametrizedUriEmitterMonitor;

/**
* Able to monitor {@link HttpPostEmitter} or {@link ParametrizedUriEmitter}, which is based on the former.
*/
public class HttpEmittingMonitor extends AbstractMonitor
{
private AbstractMonitor delegate;

@Inject
public HttpEmittingMonitor(Emitter emitter)
{
if (emitter instanceof HttpPostEmitter) {
delegate = new HttpPostEmitterMonitor(
FeedDefiningMonitor.DEFAULT_METRICS_FEED,
(HttpPostEmitter) emitter,
ImmutableMap.of()
);
} else if (emitter instanceof ParametrizedUriEmitter) {
delegate = new ParametrizedUriEmitterMonitor(
FeedDefiningMonitor.DEFAULT_METRICS_FEED,
(ParametrizedUriEmitter) emitter
);
} else {
throw new IllegalStateException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow up, I'd suggest detecting ComposingEmitter and unpacking that to monitor the emitters within. And probably in that case, we'll want this to be a warning rather than an error if there is at least one emitter that can be monitored.

Does not need to block this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would a ComposingEmitterMonitor be a better place for such functionality?

"Unable to use HttpEmittingMonitor with emitter other than HttpPostEmitter or ParametrizedUriEmitter, " +
emitter.getClass() + " is used"
);
}
}

@Override
public boolean doMonitor(ServiceEmitter serviceEmitter)
{
return delegate.doMonitor(serviceEmitter);
}
}

This file was deleted.

Loading