Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Release 0.36.0-SNAPSHOT

See merge request hercules/hercules!232
  • Loading branch information
gnkoshelev committed Feb 27, 2020
2 parents 8fc8a8f + be63595 commit 142c593
Show file tree
Hide file tree
Showing 64 changed files with 455 additions and 240 deletions.
2 changes: 1 addition & 1 deletion hercules-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-cassandra-sink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public CassandraSender(Properties properties, MetricsCollector metricsCollector)

@Override
public void start() {
cassandraConnector.connect();

CqlSession session = cassandraConnector.session();
preparedStatement = session.prepare(query());

Expand Down
2 changes: 1 addition & 1 deletion hercules-cassandra-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public CassandraConnector(Properties properties) {
this.consistencyLevel = PropertiesUtil.get(Props.CONSISTENCY_LEVEL, properties).get();

this.batchSizeBytesLimit = PropertiesUtil.get(Props.BATCH_SIZE_BYTES_LIMIT, properties).get();

init();
}

public void connect() {
private void init() {
DriverConfigLoader configLoader = DriverConfigLoader.programmaticBuilder().
withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(requestTimeoutMs)).
withString(DefaultDriverOption.REQUEST_CONSISTENCY, consistencyLevel).
Expand Down
2 changes: 1 addition & 1 deletion hercules-clickhouse-sink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.kontur.vostok.hercules.clickhouse.util.ClickHouseConnector;
import ru.kontur.vostok.hercules.configuration.Scopes;
import ru.kontur.vostok.hercules.health.AutoMetricStopwatch;
import ru.kontur.vostok.hercules.health.MetricsCollector;
import ru.kontur.vostok.hercules.health.Timer;
Expand Down Expand Up @@ -42,7 +43,7 @@ public abstract class ClickHouseSender extends Sender {
public ClickHouseSender(Properties properties, MetricsCollector metricsCollector) {
super(properties, metricsCollector);

Properties clickhouseProperties = PropertiesUtil.ofScope(properties, "clickhouse");
Properties clickhouseProperties = PropertiesUtil.ofScope(properties, Scopes.CLICKHOUSE);
this.connector = new ClickHouseConnector(clickhouseProperties);

this.processingTimeMsTimer = metricsCollector.timer("processingTimeMs");
Expand Down
2 changes: 1 addition & 1 deletion hercules-clickhouse-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class Scopes {
public static final String ZOOKEEPER = "zk";
public static final String KAFKA = "kafka";
public static final String CASSANDRA = "cassandra";
public static final String CLICKHOUSE = "clickhouse";

public static final String CURATOR = "curator";

Expand Down
2 changes: 1 addition & 1 deletion hercules-curator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-elastic-sink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-gate-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 6 additions & 0 deletions hercules-gate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ HTTP Server binds on host:port are defined in Main Application settings.

`http.server.throttling.requestTimeout` - timeout for request, which capacity throttling more then permissible, default value: `5000`

### Validation settings

`validation.max.event.size` - max size of Hercules event, value must be consistent with broker setting `max.message.bytes`, default value: `500000`

### Kafka Producer settings
See Producer's Config from Apache Kafka documentation. Main settings are presented below.

Expand Down Expand Up @@ -218,6 +222,8 @@ http.server.connection.threshold=100000
http.server.throttling.capacity=1073741824
http.server.throttling.requestTimeout=10000

validation.max.event.size=500000

producer.bootstrap.servers=localhost:9092
producer.acks=all
producer.batch.size=65536
Expand Down
2 changes: 2 additions & 0 deletions hercules-gate/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ http.server.connection.threshold=100000
http.server.throttling.capacity=1073741824
http.server.throttling.requestTimeout=10000

validation.max.event.size=500000

producer.bootstrap.servers=localhost:9092
producer.acks=all
producer.batch.size=65536
Expand Down
2 changes: 1 addition & 1 deletion hercules-gate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ru.kontur.vostok.hercules.configuration.Scopes;
import ru.kontur.vostok.hercules.configuration.util.ArgsParser;
import ru.kontur.vostok.hercules.curator.CuratorClient;
import ru.kontur.vostok.hercules.gate.validation.EventValidator;
import ru.kontur.vostok.hercules.health.CommonMetrics;
import ru.kontur.vostok.hercules.health.MetricsCollector;
import ru.kontur.vostok.hercules.http.HttpServer;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class GateApplication {
private static MetricsCollector metricsCollector;
private static HttpServer server;
private static EventSender eventSender;
private static EventValidator eventValidator;
private static CuratorClient curatorClient;
private static AuthManager authManager;
private static AuthValidationManager authValidationManager;
Expand All @@ -65,12 +67,14 @@ public static void main(String[] args) {
Properties curatorProperties = PropertiesUtil.ofScope(properties, Scopes.CURATOR);
Properties metricsProperties = PropertiesUtil.ofScope(properties, Scopes.METRICS);
Properties sdProperties = PropertiesUtil.ofScope(properties, Scopes.SERVICE_DISCOVERY);
Properties validationProperties = PropertiesUtil.ofScope(properties, "validation");

metricsCollector = new MetricsCollector(metricsProperties);
metricsCollector.start();
CommonMetrics.registerCommonMetrics(metricsCollector);

eventSender = new EventSender(producerProperties, new HashPartitioner(new NaiveHasher()), metricsCollector);
eventValidator = new EventValidator(validationProperties);

curatorClient = new CuratorClient(curatorProperties);
curatorClient.start();
Expand Down Expand Up @@ -164,13 +168,13 @@ private static void shutdown() {
LOGGER.info("Finished Gateway shutdown for {} millis", System.currentTimeMillis() - start);
}

private static HttpServer createHttpServer(Properties httpServerProperies) {
private static HttpServer createHttpServer(Properties httpServerProperties) {
StreamRepository streamRepository = new StreamRepository(curatorClient);
StreamStorage streamStorage = new StreamStorage(streamRepository, 30_000L /* TODO: for test usages; It should be moved to configuration */);

Properties throttlingProperties = PropertiesUtil.ofScope(httpServerProperies, Scopes.THROTTLING);
Properties throttlingProperties = PropertiesUtil.ofScope(httpServerProperties, Scopes.THROTTLING);

SendRequestProcessor sendRequestProcessor = new SendRequestProcessor(eventSender, metricsCollector);
SendRequestProcessor sendRequestProcessor = new SendRequestProcessor(eventSender, eventValidator, metricsCollector);
CapacityThrottle<HttpServerRequest, SendContext> throttle = new CapacityThrottle<>(
throttlingProperties,
new DefaultHttpServerRequestWeigher(),
Expand All @@ -180,7 +184,7 @@ private static HttpServer createHttpServer(Properties httpServerProperies) {
metricsCollector.gauge("throttling.totalCapacity", throttle::totalCapacity);
metricsCollector.gauge("throttling.availableCapacity", throttle::availableCapacity);

long maxContentLength = PropertiesUtil.get(HttpServer.Props.MAX_CONTENT_LENGTH, httpServerProperies).get();
long maxContentLength = PropertiesUtil.get(HttpServer.Props.MAX_CONTENT_LENGTH, httpServerProperties).get();

AuthProvider authProvider = new AuthProvider(new AdminAuthManager(Collections.emptySet()), authManager);
HandlerWrapper authHandlerWrapper = new OrdinaryAuthHandlerWrapper(authProvider);
Expand All @@ -190,15 +194,15 @@ private static HttpServer createHttpServer(Properties httpServerProperies) {
HttpHandler sendHandler = authHandlerWrapper.wrap(
new GateHandler(authProvider, throttle, authValidationManager, streamStorage, false, maxContentLength, metricsCollector));

RouteHandler handler = new InstrumentedRouteHandlerBuilder(httpServerProperies, metricsCollector).
RouteHandler handler = new InstrumentedRouteHandlerBuilder(httpServerProperties, metricsCollector).
post("/stream/sendAsync", sendAsyncHandler).
post("/stream/send", sendHandler).
build();

return new UndertowHttpServer(
Application.application().getConfig().getHost(),
Application.application().getConfig().getPort(),
httpServerProperies,
httpServerProperties,
handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ public class SendRequestProcessor implements RequestProcessor<HttpServerRequest,
private final EventSender eventSender;
private final TimeSource time;

private final EventValidator eventValidator = new EventValidator();
private final EventValidator eventValidator;
private final Lz4Decompressor lz4Decompressor = new Lz4Decompressor();

private final Timer readEventsDurationMsTimer;
private final Meter sentEventsMeter;
private final Timer decompressionTimeMsTimer;

public SendRequestProcessor(EventSender eventSender, MetricsCollector metricsCollector) {
this(eventSender, metricsCollector, TimeSource.SYSTEM);
public SendRequestProcessor(EventSender eventSender, EventValidator eventValidator, MetricsCollector metricsCollector) {
this(eventSender, eventValidator, metricsCollector, TimeSource.SYSTEM);
}

SendRequestProcessor(EventSender eventSender, MetricsCollector metricsCollector, TimeSource time) {
SendRequestProcessor(EventSender eventSender, EventValidator eventValidator, MetricsCollector metricsCollector, TimeSource time) {
this.eventSender = eventSender;
this.eventValidator = eventValidator;
this.time = time;

this.readEventsDurationMsTimer = metricsCollector.timer(this.getClass().getSimpleName() + ".readEventsDurationMs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.kontur.vostok.hercules.protocol.Event;
import ru.kontur.vostok.hercules.util.parameter.Parameter;
import ru.kontur.vostok.hercules.util.properties.PropertiesUtil;
import ru.kontur.vostok.hercules.util.validation.IntegerValidators;

import java.util.Properties;

/**
* @author Gregory Koshelev
*/
public class EventValidator {
private static final Logger LOGGER = LoggerFactory.getLogger(EventValidator.class);

private final int maxEventSize;

public EventValidator(Properties properties) {
this.maxEventSize = PropertiesUtil.get(Props.MAX_EVENT_SIZE, properties).get();
}

public boolean validate(Event event) {
if (event.getVersion() != 1) { // Gate supports Event of version 1 only
LOGGER.warn("Event version != 1");
Expand All @@ -21,6 +32,20 @@ public boolean validate(Event event) {
return false;
}

int eventSize = event.getBytes().length;
if (eventSize > maxEventSize) {
LOGGER.warn("Event size = {} bytes, more then limit = {}", eventSize, maxEventSize);
return false;
}

return true;
}

private static class Props {
static final Parameter<Integer> MAX_EVENT_SIZE =
Parameter.integerParameter("max.event.size").
withValidator(IntegerValidators.positive()).
withDefault(500_000).
build();
}
}
2 changes: 1 addition & 1 deletion hercules-graphite-sink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-health/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-init/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-kafka-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hercules-management-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hercules</artifactId>
<groupId>ru.kontur.vostok.hercules</groupId>
<version>0.35.1-SNAPSHOT</version>
<version>0.36.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit 142c593

Please sign in to comment.