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

capture metrics around json messages size #17973

Merged
merged 4 commits into from
Oct 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.logging.MdcScope;
import io.airbyte.metrics.lib.MetricClientFactory;
import io.airbyte.metrics.lib.OssMetricsRegistry;
import io.airbyte.protocol.models.AirbyteLogMessage;
import io.airbyte.protocol.models.AirbyteMessage;
import java.io.BufferedReader;
Expand Down Expand Up @@ -42,17 +44,22 @@ public DefaultAirbyteStreamFactory(final MdcScope.Builder containerLogMdcBuilder
this(new AirbyteProtocolPredicate(), LOGGER, containerLogMdcBuilder);
}

DefaultAirbyteStreamFactory(final AirbyteProtocolPredicate protocolPredicate, final Logger logger, final MdcScope.Builder containerLogMdcBuilder) {
DefaultAirbyteStreamFactory(final AirbyteProtocolPredicate protocolPredicate,
final Logger logger,
final MdcScope.Builder containerLogMdcBuilder) {
protocolValidator = protocolPredicate;
this.logger = logger;
this.containerLogMdcBuilder = containerLogMdcBuilder;
}

@Override
public Stream<AirbyteMessage> create(final BufferedReader bufferedReader) {
final var metricClient = MetricClientFactory.getMetricClient();
return bufferedReader
.lines()
.peek(str -> metricClient.distribution(OssMetricsRegistry.JSON_STRING_LENGTH, str.length()))
.flatMap(this::parseJson)
.peek(json -> metricClient.distribution(OssMetricsRegistry.JSON_SIZE, json.size()))
.filter(this::validate)
.flatMap(this::toAirbyteMessage)
.filter(this::filterLog);
Expand Down Expand Up @@ -99,7 +106,8 @@ protected boolean filterLog(final AirbyteMessage message) {

protected void internalLog(final AirbyteLogMessage logMessage) {
final String combinedMessage =
logMessage.getMessage() + (logMessage.getStackTrace() != null ? (System.lineSeparator() + "Stack Trace: " + logMessage.getStackTrace()) : "");
logMessage.getMessage() + (logMessage.getStackTrace() != null ? (System.lineSeparator()
+ "Stack Trace: " + logMessage.getStackTrace()) : "");

switch (logMessage.getLevel()) {
case FATAL, ERROR -> logger.error(combinedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public enum OssMetricsRegistry implements MetricsRegistry {
MetricEmittingApps.WORKER,
"kube_pod_process_create_time_millisecs",
"time taken to create a new kube pod process"),
JSON_STRING_LENGTH(
MetricEmittingApps.WORKER,
"json_string_length",
"string length of a raw json string"),
JSON_SIZE(
MetricEmittingApps.WORKER,
"json_size",
"size of the json object"),
NUM_PENDING_JOBS(
MetricEmittingApps.METRICS_REPORTER,
"num_pending_jobs",
Expand Down Expand Up @@ -124,7 +132,9 @@ public enum OssMetricsRegistry implements MetricsRegistry {
private final String metricName;
private final String metricDescription;

OssMetricsRegistry(final MetricEmittingApp application, final String metricName, final String metricDescription) {
OssMetricsRegistry(final MetricEmittingApp application,
final String metricName,
final String metricDescription) {
Preconditions.checkNotNull(metricDescription);
Preconditions.checkNotNull(application);

Expand Down