Skip to content

Commit

Permalink
Use shaded jackson (#15)
Browse files Browse the repository at this point in the history
* Use shaded Jackson. fixes #14

* Remove Optional<> from JSON object serialization
  • Loading branch information
tjake authored Jun 23, 2020
1 parent 6c7b006 commit 38a7094
Show file tree
Hide file tree
Showing 26 changed files with 127 additions and 204 deletions.
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.8</version>
<groupId>org.apache.flink</groupId>
<artifactId>flink-shaded-jackson</artifactId>
<version>2.10.1-10.0</version>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/datastax/mcac/UnixSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ private int writeMetric(String name, String tags, long[] estimatedBuckets)
com.datastax.mcac.insights.metrics.Histogram h = new com.datastax.mcac.insights.metrics.Histogram(
name,
System.currentTimeMillis(),
Optional.of(globalTags),
globalTags,
hist.count(),
new SamplingStats(min, max, mean, p50, p75, p90, p98, p99, p999, stddev)
);
Expand Down Expand Up @@ -965,7 +965,7 @@ private int writeMetric(String name, String tags, Timer timer)
com.datastax.mcac.insights.metrics.Timer t = new com.datastax.mcac.insights.metrics.Timer(
name,
System.currentTimeMillis(),
Optional.of(buckets),
buckets,
timer.getCount(),
new SamplingStats((long) min, (long) max, mean, p50, p75, p95, p98, p99, p999, stddev),
new RateStats(min1Rate, min5rate, min15rate, meanRate),
Expand Down Expand Up @@ -1005,7 +1005,7 @@ private int writeMetric(String name, String tags, Meter meter)
com.datastax.mcac.insights.metrics.Meter m = new com.datastax.mcac.insights.metrics.Meter(
name,
System.currentTimeMillis(),
Optional.of(globalTags),
globalTags,
meter.getCount(),
new RateStats(min1Rate, min5rate, min15rate, meanRate),
rateUnit.name()
Expand Down Expand Up @@ -1053,7 +1053,7 @@ private int writeMetric(String name, String tags, Histogram histogram)
com.datastax.mcac.insights.metrics.Histogram h = new com.datastax.mcac.insights.metrics.Histogram(
name,
System.currentTimeMillis(),
Optional.of(globalTags),
globalTags,
histogram.getCount(),
new SamplingStats(min, max, mean, p50, p75, p95, p98, p99, p999, stddev)
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/datastax/mcac/insights/Insight.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.Objects;

import com.datastax.mcac.utils.JacksonUtil;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

/**
* Instead of providing both `Object o` and `InsightsMetadata meta` to the associated <br>
Expand Down
40 changes: 21 additions & 19 deletions src/main/java/com/datastax/mcac/insights/InsightMetadata.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.datastax.mcac.insights;

import java.time.Instant;
import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

public class InsightMetadata
{
Expand All @@ -29,13 +30,14 @@ public enum InsightType
@JsonProperty("name")
public final String name;
@JsonProperty("timestamp")
public final Optional<Long> timestamp;
public final Long timestamp;
@JsonProperty("tags")
public final Map<String, String> tags;
@JsonProperty("insightType")
public final Optional<InsightType> insightType;
public final InsightType insightType;
@JsonProperty("insightMappingId")
public Optional<String> insightMappingId;
@JsonInclude(JsonInclude.Include.NON_NULL) //ignore null field on this property only
public String insightMappingId;

/**
* InsightsMetadata base constructor which all other constructors map to.
Expand All @@ -57,13 +59,13 @@ public InsightMetadata(
@JsonProperty("name")
String name,
@JsonProperty("timestamp")
Optional<Long> timestamp,
Long timestamp,
@JsonProperty("tags")
Optional<Map<String, String>> tags,
Map<String, String> tags,
@JsonProperty("insightType")
Optional<InsightType> insightType,
InsightType insightType,
@JsonProperty("insightMappingId")
Optional<String> insightMappingId
String insightMappingId
)
{
/*
Expand All @@ -78,9 +80,9 @@ public InsightMetadata(
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "name is required");

this.name = name;
this.timestamp = Optional.of(timestamp.filter(ts -> ts > 0).orElse(Instant.now().toEpochMilli()));
this.tags = tags.orElseGet(HashMap::new); //kept mutable since we want to add some default tags
this.insightType = Optional.of(insightType.orElse(InsightType.EVENT));
this.timestamp = timestamp == null || timestamp <= 0L ? Instant.now().toEpochMilli() : timestamp;
this.tags = tags == null ? Collections.emptyMap() : tags; //kept mutable since we want to add some default tags
this.insightType = insightType == null ? InsightType.EVENT : insightType;
this.insightMappingId = insightMappingId;
}

Expand All @@ -99,7 +101,7 @@ public InsightMetadata(
Map<String, String> tags
)
{
this(name, Optional.ofNullable(timestamp), Optional.ofNullable(tags), Optional.empty(), Optional.empty());
this(name, timestamp, tags, null, null);
}

/**
Expand All @@ -115,7 +117,7 @@ public InsightMetadata(
Map<String, String> tags
)
{
this(name, Optional.empty(), Optional.ofNullable(tags), Optional.empty(), Optional.empty());
this(name, null, tags, null, null);
}

/**
Expand All @@ -130,7 +132,7 @@ public InsightMetadata(
Long timestamp
)
{
this(name, Optional.ofNullable(timestamp), Optional.empty(), Optional.empty(), Optional.empty());
this(name, timestamp, null, null, null);
}

/**
Expand All @@ -141,17 +143,17 @@ public InsightMetadata(
*/
public InsightMetadata(String name)
{
this(name, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
this(name, null, null, null, null);
}

public InsightMetadata withTags(Map<String, String> newTags)
{
return new InsightMetadata(this.name, this.timestamp, Optional.of(newTags), insightType, insightMappingId);
return new InsightMetadata(this.name, this.timestamp, newTags, insightType, insightMappingId);
}

public InsightMetadata withName(String newName)
{
return new InsightMetadata(newName, this.timestamp, Optional.of(tags), insightType, insightMappingId);
return new InsightMetadata(newName, this.timestamp, tags, insightType, insightMappingId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public class ClientConnectionInformation extends Insight

public ClientConnectionInformation(UUID sessionId, ClientState clientState, Map<String, String> options, boolean isHeartbeat)
{
super(new InsightMetadata(
isHeartbeat ? NAME_HEARTBEAT : NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.empty()),
super(new InsightMetadata(isHeartbeat ? NAME_HEARTBEAT : NAME),
new Data(sessionId, clientState, options));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.cassandra.db.compaction.OperationType;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public final class CompactionEndedInformation extends Insight
Expand All @@ -32,10 +32,10 @@ public CompactionEndedInformation(
{
super(new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.of("version1")
System.currentTimeMillis(),
null,
InsightMetadata.InsightType.EVENT,
"version1"
),
new DataVersion1(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.cassandra.db.compaction.OperationType;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CompactionStartedInformation extends Insight
Expand All @@ -30,10 +30,10 @@ public CompactionStartedInformation(
{
super(new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.of("version1")
System.currentTimeMillis(),
null,
InsightMetadata.InsightType.EVENT,
"version1"
),
new CompactionStartedInformation.DataVersion1(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Optional;

Expand All @@ -20,13 +20,7 @@ public DroppedMessageInformation(
)
{
super(
new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.empty()
),
new InsightMetadata(NAME),
new Data(
groupName,
interval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

public class ExceptionInformation extends Insight
{
public static final String NAME = "oss.insights.event.exception";

public ExceptionInformation(Throwable t)
{
super(new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.empty()),
super(new InsightMetadata(NAME),
new Data(t));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package com.datastax.mcac.insights.events;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.cassandra.db.Memtable;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

public class FlushInformation extends Insight
{
public static final String NAME = "oss.insights.event.flush";

public FlushInformation(Memtable memtable, Collection<SSTableReader> sstables, long durationInMillis, boolean isTruncate)
{
super(new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.empty()
), new Data(
super(new InsightMetadata(NAME), new Data(
memtable,
sstables,
durationInMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public final class GCInformation extends Insight
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
package com.datastax.mcac.insights.events;

import java.net.InetAddress;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import com.datastax.mcac.insights.Insight;
import com.datastax.mcac.insights.InsightMetadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.EndpointState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.gms.VersionedValue;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

public class GossipChangeInformation extends Insight
{
public static final String NAME = "oss.insights.event.gossip_change";

public GossipChangeInformation(Data data)
{
super(new InsightMetadata(
NAME,
Optional.of(System.currentTimeMillis()),
Optional.empty(),
Optional.of(InsightMetadata.InsightType.EVENT),
Optional.empty()
), data);
super(new InsightMetadata(NAME), data);
}

public GossipChangeInformation(GossipEventType eventType, InetAddress ipAddress)
Expand Down
Loading

0 comments on commit 38a7094

Please sign in to comment.