diff --git a/DEVELOPER.md b/DEVELOPER.md index 2127e5f..8be7c8e 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -7,6 +7,7 @@ This document summarizes information relevant to Java tally contributors. ### Prerequisites In order to build this project, you must have: - JDK-7 or later +- Apache Thrift 0.9.x -- only if you plan to make changes to Thrift files and recompile (regenerate) source files ### Building and testing Gradle is used to build tally. Run this from the top-level directory to build the project: @@ -19,6 +20,12 @@ To run the project's tests: ./gradlew check ``` +By default, the build does *not* compile Thrift files to generate sources. If you make changes to Thrift files and need +regenerate sources, make sure you have thrift 0.9.x installed and build with the `genThrift` property set, e.g. +```bash +./gradlew clean :tally-m3:build -PgenThrift +``` + ### Making changes The source code of tally is managed using GitHub, and as such, we use its features to, for example, track [issues](https://help.github.com/articles/about-issues/) and create diff --git a/build.gradle b/build.gradle index 1fecca2..7268724 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ plugins { id 'signing' id 'checkstyle' id 'jacoco' - id 'net.researchgate.release' version '2.4.0' apply false + id 'net.researchgate.release' version '2.6.0' apply false id 'com.github.kt3k.coveralls' version '2.8.1' } @@ -126,13 +126,6 @@ allprojects { } } - // ---------------------- - // Build & Release - // ---------------------- - task wrapper(type: Wrapper) { - gradleVersion = '3.3' - } - release { tagTemplate = '$name-$version' } @@ -171,6 +164,11 @@ subprojects { ext."signing.secretKeyRingFile" = "ci/${ext.secretKeyRingFileName}" +task wrapper(type: Wrapper) { + // Gradle version 4+ required for JMH benchmarking, otherwise v3.5+ is sufficient + gradleVersion = '4.0' +} + // ---------------------- // Fat jar task factories // ---------------------- @@ -206,7 +204,8 @@ def fatJavadocJar(name, projects) { type: Javadoc, dependsOn: projects.collect{it + ':classes'} ]) { - source = projects.collect{ project(it).sourceSets.main.allSource } + classpath = files(projects.collect{ project(it).sourceSets.main.compileClasspath }) + source = projects.collect{ project(it).sourceSets.main.allJava } } return tasks.create([ @@ -221,19 +220,29 @@ def fatJavadocJar(name, projects) { } // -------------------------------------- -// StatsD fat jar +// StatsD reporter fat jar // -------------------------------------- def statsd_fat_jar_name = 'tally-statsd-fat' def statsd_fat_jar_projs = [':tally-core', ':tally-statsd'] +// -------------------------------------- +// M3 reporter fat jar +// -------------------------------------- + +def m3_fat_jar_name = 'tally-m3-fat' +def m3_fat_jar_projs = [':tally-core', ':tally-m3'] + // ------------------- // Fat jars to publish // ------------------- artifacts { archives fatJar(statsd_fat_jar_name, statsd_fat_jar_projs), fatSourcesJar(statsd_fat_jar_name, statsd_fat_jar_projs), - fatJavadocJar(statsd_fat_jar_name, statsd_fat_jar_projs) + fatJavadocJar(statsd_fat_jar_name, statsd_fat_jar_projs), + fatJar(m3_fat_jar_name, m3_fat_jar_projs), + fatSourcesJar(m3_fat_jar_name, m3_fat_jar_projs), + fatJavadocJar(m3_fat_jar_name, m3_fat_jar_projs) } nexusStaging {} @@ -248,7 +257,7 @@ coveralls { task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { dependsOn = subprojects.test sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories = files(subprojects.sourceSets.main.output.classesDir) + classDirectories = files(subprojects.sourceSets.main.output.classesDirs) executionData = files(subprojects.jacocoTestReport.executionData) reports { diff --git a/checkstyles/suppressions.xml b/checkstyles/suppressions.xml new file mode 100644 index 0000000..94b9a4f --- /dev/null +++ b/checkstyles/suppressions.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/checkstyles/uber_checks.xml b/checkstyles/uber_checks.xml index 7789ab1..9a6a8f8 100644 --- a/checkstyles/uber_checks.xml +++ b/checkstyles/uber_checks.xml @@ -6,6 +6,10 @@ + + + + diff --git a/core/src/main/java/com/uber/m3/tally/AbstractBuckets.java b/core/src/main/java/com/uber/m3/tally/AbstractBuckets.java index dd43be2..fdd60db 100644 --- a/core/src/main/java/com/uber/m3/tally/AbstractBuckets.java +++ b/core/src/main/java/com/uber/m3/tally/AbstractBuckets.java @@ -22,6 +22,7 @@ import com.uber.m3.util.Duration; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -35,7 +36,15 @@ public abstract class AbstractBuckets implements Buckets { protected List buckets; AbstractBuckets(T[] buckets) { - this.buckets = Arrays.asList(buckets); + if (buckets == null) { + this.buckets = new ArrayList<>(); + } else { + this.buckets = new ArrayList<>(Arrays.asList(buckets)); + } + } + + AbstractBuckets() { + this(null); } @Override diff --git a/core/src/main/java/com/uber/m3/tally/BucketPairImpl.java b/core/src/main/java/com/uber/m3/tally/BucketPairImpl.java index ab2882f..17732c8 100644 --- a/core/src/main/java/com/uber/m3/tally/BucketPairImpl.java +++ b/core/src/main/java/com/uber/m3/tally/BucketPairImpl.java @@ -22,16 +22,18 @@ import com.uber.m3.util.Duration; +import java.util.Collections; + /** * Default implementation of a {@link BucketPair} */ -class BucketPairImpl implements BucketPair { +public class BucketPairImpl implements BucketPair { private double lowerBoundValue; private double upperBoundValue; private Duration lowerBoundDuration; private Duration upperBoundDuration; - BucketPairImpl( + public BucketPairImpl( double lowerBoundValue, double upperBoundValue, Duration lowerBoundDuration, @@ -43,6 +45,78 @@ class BucketPairImpl implements BucketPair { this.upperBoundDuration = upperBoundDuration; } + public static BucketPair[] bucketPairs(Buckets buckets) { + if (buckets == null || buckets.size() < 1) { + return new BucketPair[]{ + new BucketPairImpl( + -Double.MAX_VALUE, + Double.MAX_VALUE, + Duration.MIN_VALUE, + Duration.MAX_VALUE + ) + }; + } + + if (buckets instanceof DurationBuckets) { + // If using duration buckets separating negative times and + // positive times is very much desirable as depending on the + // reporter will create buckets "-infinity,0" and "0,{first_bucket}" + // instead of just "-infinity,{first_bucket}" which for time + // durations is not desirable nor pragmatic + boolean hasZero = false; + + for (Duration duration : buckets.asDurations()) { + if (duration.equals(Duration.ZERO)) { + hasZero = true; + break; + } + } + + if (!hasZero) { + ((DurationBuckets) buckets).add(Duration.ZERO); + } + } + + Collections.sort(buckets); + + Double[] asValueBuckets = buckets.asValues(); + Duration[] asDurationBuckets = buckets.asDurations(); + BucketPair[] pairs = new BucketPair[buckets.size() + 1]; + + // Add lower bound + pairs[0] = new BucketPairImpl( + -Double.MAX_VALUE, + asValueBuckets[0], + Duration.MIN_VALUE, + asDurationBuckets[0] + ); + + double prevValueBucket = asValueBuckets[0]; + Duration prevDurationBucket = asDurationBuckets[0]; + + for (int i = 1; i < buckets.size(); i++) { + pairs[i] = new BucketPairImpl( + prevValueBucket, + asValueBuckets[i], + prevDurationBucket, + asDurationBuckets[i] + ); + + prevValueBucket = asValueBuckets[i]; + prevDurationBucket = asDurationBuckets[i]; + } + + // Add upper bound + pairs[pairs.length - 1] = new BucketPairImpl( + prevValueBucket, + Double.MAX_VALUE, + prevDurationBucket, + Duration.MAX_VALUE + ); + + return pairs; + } + @Override public double lowerBoundValue() { return lowerBoundValue; diff --git a/core/src/main/java/com/uber/m3/tally/CachedCounter.java b/core/src/main/java/com/uber/m3/tally/CachedCounter.java deleted file mode 100644 index 1b78018..0000000 --- a/core/src/main/java/com/uber/m3/tally/CachedCounter.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package com.uber.m3.tally; - -/** - * A cached count for reporting an individual {@link Counter}. - */ -public interface CachedCounter { - /** - * Reports a count for a {@link Counter}. - * @param value value to report - */ - void reportCount(long value); -} diff --git a/core/src/main/java/com/uber/m3/tally/CachedGauge.java b/core/src/main/java/com/uber/m3/tally/CachedGauge.java deleted file mode 100644 index f4e6a50..0000000 --- a/core/src/main/java/com/uber/m3/tally/CachedGauge.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package com.uber.m3.tally; - -/** - * A cached gauge for reporting an individual {@link Gauge}. - */ -public interface CachedGauge { - /** - * Reports a value for a {@link Gauge}. - * @param value value to report - */ - void reportGauge(double value); -} diff --git a/core/src/main/java/com/uber/m3/tally/CachedHistogramBucket.java b/core/src/main/java/com/uber/m3/tally/CachedHistogramBucket.java deleted file mode 100644 index 060d984..0000000 --- a/core/src/main/java/com/uber/m3/tally/CachedHistogramBucket.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package com.uber.m3.tally; - -/** - * Interface for reporting histogram samples to a specific bucket. - */ -public interface CachedHistogramBucket { - /** - * Report a sample to a specific bucket. - * @param value value to report - */ - void reportSamples(long value); -} diff --git a/core/src/main/java/com/uber/m3/tally/CachedTimer.java b/core/src/main/java/com/uber/m3/tally/CachedTimer.java deleted file mode 100644 index 8dd4f79..0000000 --- a/core/src/main/java/com/uber/m3/tally/CachedTimer.java +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package com.uber.m3.tally; - -import com.uber.m3.util.Duration; - -/** - * A cached timer for reporting an individual {@link Timer}. - */ -public interface CachedTimer { - /** - * Reports a {@link Duration} for a {@link Timer}. - * @param interval interval to report - */ - void reportTimer(Duration interval); -} diff --git a/core/src/main/java/com/uber/m3/tally/CapableOf.java b/core/src/main/java/com/uber/m3/tally/CapableOf.java index 8a9f2e6..cb554c6 100644 --- a/core/src/main/java/com/uber/m3/tally/CapableOf.java +++ b/core/src/main/java/com/uber/m3/tally/CapableOf.java @@ -46,4 +46,32 @@ public boolean reporting() { public boolean tagging() { return tagging; } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other == this) { + return true; + } + if (!(other instanceof CapableOf)) { + return false; + } + + CapableOf capabilities = (CapableOf) other; + + return capabilities.reporting == reporting + && capabilities.tagging == tagging; + } + + @Override + public int hashCode() { + int code = 0; + + code = 31 * code + new Boolean(reporting).hashCode(); + code = 31 * code + new Boolean(tagging).hashCode(); + + return code; + } } diff --git a/core/src/main/java/com/uber/m3/tally/CounterImpl.java b/core/src/main/java/com/uber/m3/tally/CounterImpl.java index ad6a098..bb56e96 100644 --- a/core/src/main/java/com/uber/m3/tally/CounterImpl.java +++ b/core/src/main/java/com/uber/m3/tally/CounterImpl.java @@ -30,15 +30,6 @@ class CounterImpl implements Counter { private AtomicLong prev = new AtomicLong(0); private AtomicLong curr = new AtomicLong(0); - private CachedCounter cachedCount; - - CounterImpl(CachedCounter cachedCount) { - this.cachedCount = cachedCount; - } - - CounterImpl() { - this(null); - } @Override public void inc(long delta) { @@ -68,16 +59,6 @@ void report(String name, ImmutableMap tags, StatsReporter report reporter.reportCounter(name, tags, delta); } - void cachedReport() { - long delta = value(); - - if (delta == 0) { - return; - } - - cachedCount.reportCount(delta); - } - long snapshot() { return curr.get() - prev.get(); } diff --git a/core/src/main/java/com/uber/m3/tally/DurationBuckets.java b/core/src/main/java/com/uber/m3/tally/DurationBuckets.java index 23485eb..8068934 100644 --- a/core/src/main/java/com/uber/m3/tally/DurationBuckets.java +++ b/core/src/main/java/com/uber/m3/tally/DurationBuckets.java @@ -26,10 +26,14 @@ * {@link Buckets} implementation backed by {@link Duration}s. */ public class DurationBuckets extends AbstractBuckets { - DurationBuckets(Duration[] durations) { + public DurationBuckets(Duration[] durations) { super(durations); } + public DurationBuckets() { + super(); + } + @Override public Double[] asValues() { Double[] values = new Double[buckets.size()]; diff --git a/core/src/main/java/com/uber/m3/tally/GaugeImpl.java b/core/src/main/java/com/uber/m3/tally/GaugeImpl.java index 9decdcc..e4b75de 100644 --- a/core/src/main/java/com/uber/m3/tally/GaugeImpl.java +++ b/core/src/main/java/com/uber/m3/tally/GaugeImpl.java @@ -31,15 +31,6 @@ class GaugeImpl implements Gauge { private AtomicBoolean updated = new AtomicBoolean(false); private AtomicLong curr = new AtomicLong(0); - private CachedGauge cachedGauge; - - GaugeImpl(CachedGauge cachedGauge) { - this.cachedGauge = cachedGauge; - } - - GaugeImpl() { - this(null); - } @Override public void update(double value) { @@ -57,12 +48,6 @@ void report(String name, ImmutableMap tags, StatsReporter report } } - void cachedReport() { - if (updated.getAndSet(false)) { - cachedGauge.reportGauge(value()); - } - } - double snapshot() { return value(); } diff --git a/core/src/main/java/com/uber/m3/tally/HistogramImpl.java b/core/src/main/java/com/uber/m3/tally/HistogramImpl.java index fc5b8fc..cf833c6 100644 --- a/core/src/main/java/com/uber/m3/tally/HistogramImpl.java +++ b/core/src/main/java/com/uber/m3/tally/HistogramImpl.java @@ -36,7 +36,6 @@ class HistogramImpl implements Histogram { private Type type; private String name; private ImmutableMap tags; - private StatsReporter reporter; private Buckets specification; private List buckets; private List lookupByValue; @@ -46,8 +45,7 @@ class HistogramImpl implements Histogram { String name, ImmutableMap tags, StatsReporter reporter, - Buckets buckets, - CachedHistogram cachedHistogram + Buckets buckets ) { if (buckets instanceof DurationBuckets) { type = Type.DURATION; @@ -55,12 +53,11 @@ class HistogramImpl implements Histogram { type = Type.VALUE; } - BucketPair[] pairs = bucketPairs(buckets); + BucketPair[] pairs = BucketPairImpl.bucketPairs(buckets); int pairsLen = pairs.length; this.name = name; this.tags = tags; - this.reporter = reporter; specification = buckets; this.buckets = new ArrayList<>(pairsLen); lookupByValue = new ArrayList<>(pairsLen); @@ -71,21 +68,11 @@ class HistogramImpl implements Histogram { pair.lowerBoundValue(), pair.upperBoundValue(), pair.lowerBoundDuration(), - pair.upperBoundDuration(), - cachedHistogram + pair.upperBoundDuration() )); } } - HistogramImpl( - String name, - ImmutableMap tags, - StatsReporter reporter, - Buckets buckets - ) { - this(name, tags, reporter, buckets, null); - } - private void addBucket(HistogramBucket bucket) { buckets.add(bucket); lookupByValue.add(bucket.valueUpperBound); @@ -154,25 +141,6 @@ void report(String name, ImmutableMap tags, StatsReporter report } } - void cachedReport() { - for (HistogramBucket bucket : buckets) { - long samples = bucket.samples.value(); - - if (samples == 0) { - continue; - } - - switch (type) { - case VALUE: - bucket.cachedValueBucket.reportSamples(samples); - break; - case DURATION: - bucket.cachedDurationBucket.reportSamples(samples); - break; - } - } - } - Map snapshotValues() { if (type == Type.DURATION) { return null; @@ -201,104 +169,24 @@ Map snapshotDurations() { return durations; } - static BucketPair[] bucketPairs(Buckets buckets) { - if (buckets == null || buckets.size() < 1) { - return new BucketPair[]{ - new BucketPairImpl( - -Double.MAX_VALUE, - Double.MAX_VALUE, - Duration.MIN_VALUE, - Duration.MAX_VALUE - ) - }; - } - - if (buckets instanceof DurationBuckets) { - // If using duration buckets separating negative times and - // positive times is very much desirable as depending on the - // reporter will create buckets "-infinity,0" and "0,{first_bucket}" - // instead of just "-infinity,{first_bucket}" which for time - // durations is not desirable nor pragmatic - boolean hasZero = false; - - for (Duration duration : buckets.asDurations()) { - if (duration.equals(Duration.ZERO)) { - hasZero = true; - break; - } - } - - if (!hasZero) { - ((DurationBuckets) buckets).add(Duration.ZERO); - } - } - - Collections.sort(buckets); - - Double[] asValueBuckets = buckets.asValues(); - Duration[] asDurationBuckets = buckets.asDurations(); - BucketPair[] pairs = new BucketPair[buckets.size() + 1]; - - // Add lower bound - pairs[0] = new BucketPairImpl( - -Double.MAX_VALUE, - asValueBuckets[0], - Duration.MIN_VALUE, - asDurationBuckets[0] - ); - - double prevValueBucket = asValueBuckets[0]; - Duration prevDurationBucket = asDurationBuckets[0]; - - for (int i = 1; i < buckets.size(); i++) { - pairs[i] = new BucketPairImpl( - prevValueBucket, - asValueBuckets[i], - prevDurationBucket, - asDurationBuckets[i] - ); - - prevValueBucket = asValueBuckets[i]; - prevDurationBucket = asDurationBuckets[i]; - } - - // Add upper bound - pairs[pairs.length - 1] = new BucketPairImpl( - prevValueBucket, - Double.MAX_VALUE, - prevDurationBucket, - Duration.MAX_VALUE - ); - - return pairs; - } - class HistogramBucket { CounterImpl samples; double valueLowerBound; double valueUpperBound; Duration durationLowerBound; Duration durationUpperBound; - CachedHistogramBucket cachedValueBucket; - CachedHistogramBucket cachedDurationBucket; HistogramBucket( double valueLowerBound, double valueUpperBound, Duration durationLowerBound, - Duration durationUpperBound, - CachedHistogram cachedHistogram + Duration durationUpperBound ) { samples = new CounterImpl(); this.valueLowerBound = valueLowerBound; this.valueUpperBound = valueUpperBound; this.durationLowerBound = durationLowerBound; this.durationUpperBound = durationUpperBound; - - if (cachedHistogram != null) { - cachedValueBucket = cachedHistogram.valueBucket(valueLowerBound, valueUpperBound); - cachedDurationBucket = cachedHistogram.durationBucket(durationLowerBound, durationUpperBound); - } } } diff --git a/core/src/main/java/com/uber/m3/tally/ScopeBuilder.java b/core/src/main/java/com/uber/m3/tally/ScopeBuilder.java index a77bb92..9e0eefd 100644 --- a/core/src/main/java/com/uber/m3/tally/ScopeBuilder.java +++ b/core/src/main/java/com/uber/m3/tally/ScopeBuilder.java @@ -51,8 +51,6 @@ public class ScopeBuilder { }); StatsReporter reporter = null; - CachedStatsReporter cachedReporter = null; - BaseStatsReporter baseReporter = null; String prefix = ""; String separator = DEFAULT_SEPARATOR; ImmutableMap tags; @@ -78,16 +76,6 @@ public ScopeBuilder reporter(StatsReporter reporter) { return this; } - /** - * Update the cachedReporter - * @param cachedReporter value to update to - * @return Builder with new param updated - */ - public ScopeBuilder cachedReporter(CachedStatsReporter cachedReporter) { - this.cachedReporter = cachedReporter; - return this; - } - /** * Update the prefix * @param prefix value to update to @@ -143,12 +131,6 @@ public ScopeBuilder defaultBuckets(Buckets defaultBuckets) { // Private build method - clients should rely on `reportEvery` to create root scopes, and // a root scope's `tagged` and `subScope` functions to create subscopes. ScopeImpl build() { - if (reporter != null) { - baseReporter = reporter; - } else if (cachedReporter != null) { - baseReporter = cachedReporter; - } - return new ScopeImpl(scheduler, registry, this); } diff --git a/core/src/main/java/com/uber/m3/tally/ScopeImpl.java b/core/src/main/java/com/uber/m3/tally/ScopeImpl.java index cafcc36..5f8a380 100644 --- a/core/src/main/java/com/uber/m3/tally/ScopeImpl.java +++ b/core/src/main/java/com/uber/m3/tally/ScopeImpl.java @@ -28,16 +28,12 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; /** * Default {@link Scope} implementation. */ class ScopeImpl implements Scope { private StatsReporter reporter; - private CachedStatsReporter cachedReporter; - private BaseStatsReporter baseReporter; private String prefix; private String separator; private ImmutableMap tags; @@ -48,17 +44,12 @@ class ScopeImpl implements Scope { // ConcurrentHashMap nearly always allowing read operations seems like a good // performance upside to the consequence of reporting a newly-made metric in - // the middle of looping and reporting through all metrics. Therefore, locks - // are generally only used when having to allocate new metrics. - private Map counters = new ConcurrentHashMap<>(); - private Map gauges = new ConcurrentHashMap<>(); - private Map timers = new ConcurrentHashMap<>(); - private Map histograms = new ConcurrentHashMap<>(); - - private Lock counterAllocationLock = new ReentrantLock(); - private Lock gaugeAllocationLock = new ReentrantLock(); - private Lock timerAllocationLock = new ReentrantLock(); - private Lock histogramAllocationLock = new ReentrantLock(); + // the middle of looping and reporting through all metrics. Therefore, we only + // synchronize on these maps when having to allocate new metrics. + private final Map counters = new ConcurrentHashMap<>(); + private final Map gauges = new ConcurrentHashMap<>(); + private final Map timers = new ConcurrentHashMap<>(); + private final Map histograms = new ConcurrentHashMap<>(); // Private ScopeImpl constructor. Root scopes should be built using the RootScopeBuilder class ScopeImpl(ScheduledExecutorService scheduler, Registry registry, ScopeBuilder builder) { @@ -66,8 +57,6 @@ class ScopeImpl implements Scope { this.registry = registry; this.reporter = builder.reporter; - this.cachedReporter = builder.cachedReporter; - this.baseReporter = builder.baseReporter; this.prefix = builder.prefix; this.separator = builder.separator; this.tags = builder.tags; @@ -82,22 +71,14 @@ public Counter counter(String name) { return counter; } - counterAllocationLock.lock(); - - if (!counters.containsKey(name)) { - CachedCounter cachedCounter = null; - - if (cachedReporter != null) { - cachedCounter = cachedReporter.allocateCounter(fullyQualifiedName(name), tags); + synchronized (counters) { + if (!counters.containsKey(name)) { + counters.put(name, new CounterImpl()); } - counters.put(name, new CounterImpl(cachedCounter)); + counter = counters.get(name); } - counter = counters.get(name); - - counterAllocationLock.unlock(); - return counter; } @@ -109,22 +90,14 @@ public Gauge gauge(String name) { return gauge; } - gaugeAllocationLock.lock(); - - if (!gauges.containsKey(name)) { - CachedGauge cachedGauge = null; - - if (cachedReporter != null) { - cachedGauge = cachedReporter.allocateGauge(fullyQualifiedName(name), tags); + synchronized (gauges) { + if (!gauges.containsKey(name)) { + gauges.put(name, new GaugeImpl()); } - gauges.put(name, new GaugeImpl(cachedGauge)); + gauge = gauges.get(name); } - gauge = gauges.get(name); - - gaugeAllocationLock.unlock(); - return gauge; } @@ -136,24 +109,14 @@ public Timer timer(String name) { return timer; } - timerAllocationLock.lock(); - - if (!timers.containsKey(name)) { - CachedTimer cachedTimer = null; - - String fullName = fullyQualifiedName(name); - - if (cachedReporter != null) { - cachedTimer = cachedReporter.allocateTimer(fullName, tags); + synchronized (timers) { + if (!timers.containsKey(name)) { + timers.put(name, new TimerImpl(fullyQualifiedName(name), tags, reporter)); } - timers.put(name, new TimerImpl(fullName, tags, reporter, cachedTimer)); + timer = timers.get(name); } - timer = timers.get(name); - - timerAllocationLock.unlock(); - return timer; } @@ -169,24 +132,14 @@ public Histogram histogram(String name, Buckets buckets) { return histogram; } - histogramAllocationLock.lock(); - - if (!histograms.containsKey(name)) { - CachedHistogram cachedHistogram = null; - - String fullName = fullyQualifiedName(name); - - if (cachedReporter != null) { - cachedHistogram = cachedReporter.allocateHistogram(fullName, tags, buckets); + synchronized (histograms) { + if (!histograms.containsKey(name)) { + histograms.put(name, new HistogramImpl(fullyQualifiedName(name), tags, reporter, buckets)); } - histograms.put(name, new HistogramImpl(fullName, tags, reporter, buckets, cachedHistogram)); + histogram = histograms.get(name); } - histogram = histograms.get(name); - - histogramAllocationLock.unlock(); - return histogram; } @@ -202,8 +155,8 @@ public Scope subScope(String name) { @Override public Capabilities capabilities() { - if (baseReporter != null) { - return baseReporter.capabilities(); + if (reporter != null) { + return reporter.capabilities(); } return CapableOf.NONE; @@ -220,7 +173,7 @@ public void close() { reportLoopIteration(); // Now that all metrics should be known to the reporter, close the reporter - baseReporter.close(); + reporter.close(); } /** @@ -246,30 +199,8 @@ void report(StatsReporter reporter) { reporter.flush(); } - /** - * Reports using the specified cachedReporter. - * @param cachedReporter the cachedReporter to report - */ - void cachedReport(CachedStatsReporter cachedReporter) { - for (CounterImpl counter : counters.values()) { - counter.cachedReport(); - } - - for (GaugeImpl gauge : gauges.values()) { - gauge.cachedReport(); - } - - // No operations on timers required here; they report directly to the StatsReporter - // i.e. they are not buffered - - for (HistogramImpl histogram : histograms.values()) { - histogram.cachedReport(); - } - - cachedReporter.flush(); - } - // Serializes a map to generate a key for a prefix/map combination + // Non-generic EMPTY ImmutableMap will never contain any elements @SuppressWarnings("unchecked") static String keyForPrefixedStringMap(String prefix, ImmutableMap stringMap) { if (prefix == null) { @@ -313,7 +244,7 @@ String fullyQualifiedName(String name) { * Returns a {@link Snapshot} of this {@link Scope}. * @return a {@link Snapshot} of this {@link Scope} */ - Snapshot snapshot() { + public Snapshot snapshot() { Snapshot snap = new SnapshotImpl(); for (ScopeImpl subscope : registry.subscopes.values()) { @@ -398,25 +329,24 @@ private Scope subScopeHelper(String prefix, Map tags) { String key = keyForPrefixedStringMap(prefix, mergedTags); - registry.allocationLock.lock(); - - if (!registry.subscopes.containsKey(key)) { - registry.subscopes.put( - key, - new ScopeBuilder(scheduler, registry) - .reporter(reporter) - .cachedReporter(cachedReporter) - .prefix(prefix) - .separator(separator) - .tags(mergedTags) - .defaultBuckets(defaultBuckets) - .build() - ); - } - - Scope subscope = registry.subscopes.get(key); + Scope subscope; + + synchronized (registry.allocationLock) { + if (!registry.subscopes.containsKey(key)) { + registry.subscopes.put( + key, + new ScopeBuilder(scheduler, registry) + .reporter(reporter) + .prefix(prefix) + .separator(separator) + .tags(mergedTags) + .defaultBuckets(defaultBuckets) + .build() + ); + } - registry.allocationLock.unlock(); + subscope = registry.subscopes.get(key); + } return subscope; } @@ -430,12 +360,6 @@ private void reportLoopIteration() { subscope.report(reporter); } } - - if (cachedReporter != null) { - for (ScopeImpl subscope : subscopes) { - subscope.cachedReport(cachedReporter); - } - } } class ReportLoop implements Runnable { @@ -445,7 +369,7 @@ public void run() { } static class Registry { - Lock allocationLock = new ReentrantLock(); + final Object allocationLock = new Object(); Map subscopes = new ConcurrentHashMap<>(); } } diff --git a/core/src/main/java/com/uber/m3/tally/TimerImpl.java b/core/src/main/java/com/uber/m3/tally/TimerImpl.java index 6ef1a8e..b31be1c 100644 --- a/core/src/main/java/com/uber/m3/tally/TimerImpl.java +++ b/core/src/main/java/com/uber/m3/tally/TimerImpl.java @@ -37,13 +37,11 @@ class TimerImpl implements Timer, StopwatchRecorder { private String name; private ImmutableMap tags; private StatsReporter reporter; - private CachedTimer cachedTimer; private Values unreported = new Values(); - TimerImpl(String name, ImmutableMap tags, StatsReporter reporter, CachedTimer cachedTimer) { + TimerImpl(String name, ImmutableMap tags, StatsReporter reporter) { this.name = name; this.tags = tags; - this.cachedTimer = cachedTimer; if (reporter == null) { this.reporter = new NoReporterSink(); @@ -52,17 +50,9 @@ class TimerImpl implements Timer, StopwatchRecorder { } } - TimerImpl(String name, ImmutableMap tags, StatsReporter reporter) { - this(name, tags, reporter, null); - } - @Override public void record(Duration interval) { - if (cachedTimer != null) { - cachedTimer.reportTimer(interval); - } else { - reporter.reportTimer(name, tags, interval); - } + reporter.reportTimer(name, tags, interval); } @Override @@ -94,7 +84,11 @@ Duration[] snapshot() { } static class Values { - private ReadWriteLock rwlock = new ReentrantReadWriteLock(); + // Using a ReadWriteLock here to protect against multithreaded reads + // and writes separately. In other places, synchronized blocks are used + // instead as this separation is not needed e.g. we only lock a + // ConcurrentHashMap when doing writes and not for reads. + private final ReadWriteLock rwlock = new ReentrantReadWriteLock(); private List values = new ArrayList<>(); Lock readLock() { diff --git a/core/src/main/java/com/uber/m3/tally/ValueBuckets.java b/core/src/main/java/com/uber/m3/tally/ValueBuckets.java index e461b34..23acf9d 100644 --- a/core/src/main/java/com/uber/m3/tally/ValueBuckets.java +++ b/core/src/main/java/com/uber/m3/tally/ValueBuckets.java @@ -26,10 +26,14 @@ * {@link Buckets} implementation backed by {@code Double} values. */ public class ValueBuckets extends AbstractBuckets { - ValueBuckets(Double[] values) { + public ValueBuckets(Double[] values) { super(values); } + public ValueBuckets() { + super(); + } + @Override public Double[] asValues() { return buckets.toArray(new Double[buckets.size()]); diff --git a/core/src/main/java/com/uber/m3/util/Duration.java b/core/src/main/java/com/uber/m3/util/Duration.java index f1cb44c..913a496 100644 --- a/core/src/main/java/com/uber/m3/util/Duration.java +++ b/core/src/main/java/com/uber/m3/util/Duration.java @@ -39,6 +39,11 @@ public class Duration implements Comparable { */ public static final Duration MAX_VALUE = new Duration(Long.MAX_VALUE); + /** + * The number of nanoseconds in a microsecond. + */ + public static final long NANOS_PER_MICRO = 1_000; + /** * The number of nanoseconds in a millisecond. */ @@ -47,7 +52,7 @@ public class Duration implements Comparable { /** * The number of milliseconds in a second. */ - public static final long MILLIS_PER_SECOND = 1000; + public static final long MILLIS_PER_SECOND = 1_000; /** * The number of seconds in a minute. @@ -74,6 +79,9 @@ public class Duration implements Comparable { */ public static final long NANOS_PER_HOUR = NANOS_PER_MINUTE * MINUTES_PER_HOUR; + // Max string length produced from a Duration is 25 when nanos == Long.MIN_VALUE + private static final int STRING_BUILDER_INIT_CAP = 25; + // Long.MAX_VALUE nanos > 290 years, which should be good enough private final long nanos; @@ -87,8 +95,8 @@ private Duration(long nanos) { * @param nanos number of nanos in this {@link Duration} * @return a {@link Duration} of these nanos */ - public static Duration ofNanos(double nanos) { - return new Duration((long) nanos); + public static Duration ofNanos(long nanos) { + return new Duration(nanos); } /** @@ -185,21 +193,32 @@ public int compareTo(Duration other) { return Long.compare(nanos, other.nanos); } + /** + * This toString method is designed to mimic Go's time.Duration String(). In short, it is + * designed so that the least granular unit is used such that the first digit is not 0, + * e.g. 100µs instead of 0.1ms. + * @return String representation of this {@link Duration} + */ @Override public String toString() { if (nanos == 0) { return "0s"; + } else if (nanos == Long.MIN_VALUE) { + // Return hard coded response as workaround because + // Math.abs(Long.MIN_VALUE) == Long.MIN_VALUE + return "-2562047h47m16.854775808s"; } boolean isNegative = nanos < 0; - long localNanos = Math.abs(nanos); + long nanosLocal = Math.abs(nanos); - long hours = localNanos / NANOS_PER_HOUR; - int minutes = (int) ((localNanos % NANOS_PER_HOUR) / NANOS_PER_MINUTE); - float seconds = (float) (localNanos % NANOS_PER_MINUTE) / (float) NANOS_PER_SECOND; + long hours = nanosLocal / NANOS_PER_HOUR; + int minutes = (int) ((nanosLocal % NANOS_PER_HOUR) / NANOS_PER_MINUTE); + long secondsInNanos = nanosLocal % NANOS_PER_MINUTE; + int nanoOffset = (int) (nanosLocal % NANOS_PER_SECOND); - StringBuilder buf = new StringBuilder(16); + StringBuilder buf = new StringBuilder(STRING_BUILDER_INIT_CAP); if (isNegative) { buf.append("-"); @@ -210,13 +229,44 @@ public String toString() { if (minutes != 0) { buf.append(minutes).append("m"); } - if (seconds != 0) { - buf.append(seconds).append("s"); + if (secondsInNanos / NANOS_PER_SECOND > 0) { + appendDurationSegment(buf, secondsInNanos, 9, "s"); + } else if (nanoOffset > 0) { + // If less than one second, print the highest unit that is >1 + if (nanoOffset / NANOS_PER_MILLI > 0) { + appendDurationSegment(buf, nanoOffset, 6, "ms"); + } else if (nanoOffset / NANOS_PER_MICRO > 0) { + appendDurationSegment(buf, nanoOffset % NANOS_PER_MILLI, 3, "µs"); + } else { + buf.append(nanoOffset).append("ns"); + } } return buf.toString(); } + private static void appendDurationSegment( + StringBuilder buf, + long durationPart, + int exponent, + String suffix + ) { + buf.append(durationPart); + + int decimalIdx = buf.length() - exponent; + + // Remove trailing 0s if they come after decimal + while (decimalIdx < buf.length() && buf.charAt(buf.length() - 1) == '0') { + buf.setLength(buf.length() - 1); + } + + if (decimalIdx < buf.length()) { + buf.insert(decimalIdx, '.'); + } + + buf.append(suffix); + } + @Override public boolean equals(Object other) { if (other == null) { diff --git a/core/src/main/java/com/uber/m3/util/ImmutableSet.java b/core/src/main/java/com/uber/m3/util/ImmutableSet.java index 6c8f26d..006fa21 100644 --- a/core/src/main/java/com/uber/m3/util/ImmutableSet.java +++ b/core/src/main/java/com/uber/m3/util/ImmutableSet.java @@ -119,4 +119,40 @@ public boolean equals(Object other) { public int hashCode() { return set.hashCode(); } + + /** + * Helper class to construct {@link ImmutableSet}s. + * @param the type of elements in this set + */ + public static class Builder { + private HashSet set; + + public Builder() { + this(16, 0.75f); + } + + public Builder(int initialCapacity) { + this(initialCapacity, 1); + } + + public Builder(int initialCapacity, float loadFactor) { + set = new HashSet<>(initialCapacity, loadFactor); + } + + public Builder add(E element) { + set.add(element); + + return this; + } + + public Builder addAll(Set otherSet) { + set.addAll(otherSet); + + return this; + } + + public ImmutableSet build() { + return new ImmutableSet<>(set); + } + } } diff --git a/core/src/test/java/com/uber/m3/tally/HistogramImplTest.java b/core/src/test/java/com/uber/m3/tally/HistogramImplTest.java index 68aa161..c46006d 100644 --- a/core/src/test/java/com/uber/m3/tally/HistogramImplTest.java +++ b/core/src/test/java/com/uber/m3/tally/HistogramImplTest.java @@ -166,7 +166,7 @@ public void bucketPairs() { ) }; - assertArrayEquals(expectedPairs, HistogramImpl.bucketPairs(null)); + assertArrayEquals(expectedPairs, BucketPairImpl.bucketPairs(null)); expectedPairs = new BucketPair[]{ new BucketPairImpl( @@ -197,7 +197,7 @@ public void bucketPairs() { assertArrayEquals( expectedPairs, - HistogramImpl.bucketPairs(ValueBuckets.linear(0, 50, 3)) + BucketPairImpl.bucketPairs(ValueBuckets.linear(0, 50, 3)) ); } } diff --git a/core/src/test/java/com/uber/m3/util/DurationTest.java b/core/src/test/java/com/uber/m3/util/DurationTest.java index f9875a6..d4eb43f 100644 --- a/core/src/test/java/com/uber/m3/util/DurationTest.java +++ b/core/src/test/java/com/uber/m3/util/DurationTest.java @@ -157,8 +157,12 @@ public void toStringTest() { assertEquals("1.234s", Duration.ofMillis(1234).toString()); assertEquals("2m3.456789s", Duration.ofSeconds(123.456789).toString()); assertEquals("26h30m", Duration.ofHours(26.5).toString()); - assertEquals("1.0E-9s", Duration.ofNanos(1).toString()); - assertEquals("1.2345678s", Duration.ofNanos(1234567800).toString()); + assertEquals("1ns", Duration.ofNanos(1).toString()); + assertEquals("1.03µs", Duration.ofNanos(1_030).toString()); + assertEquals("1.23456789s", Duration.ofNanos(1_234_567_890).toString()); + assertEquals("50ms", Duration.ofMillis(50).toString()); + assertEquals("200µs", Duration.ofNanos(200_000).toString()); + assertEquals("99.009µs", Duration.ofNanos(99_009).toString()); assertEquals("-1.25s", Duration.ofSeconds(-1.25).toString()); assertEquals("-34h17m36.7s", Duration.ofSeconds(-123456.7).toString()); diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 37406ed..736fb7d 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 08227bc..89626ea 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jul 07 11:19:17 EDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip diff --git a/core/src/main/java/com/uber/m3/tally/CachedStatsReporter.java b/m3/build.gradle similarity index 65% rename from core/src/main/java/com/uber/m3/tally/CachedStatsReporter.java rename to m3/build.gradle index fcc118b..5e17944 100644 --- a/core/src/main/java/com/uber/m3/tally/CachedStatsReporter.java +++ b/m3/build.gradle @@ -18,20 +18,40 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package com.uber.m3.tally; +plugins { + id "org.jruyi.thrift" version "0.4.0" + id "me.champeau.gradle.jmh" version "0.4.3" +} + +description = 'tally M3 reporter' + +dependencies { + compile('org.apache.thrift:libthrift:0.9.3') + + compile project(':tally-core') +} -import java.util.Map; +compileThrift { + generator 'java', 'private-members' + + outputDir "${projectDir}/src/generated/java" + + createGenFolder false + + onlyIf { + project.hasProperty('genThrift') + } +} -/** - * A backend for {@link Scope}s that pre allocates all metrics. - * This results in a more performant reporter. - */ -public interface CachedStatsReporter extends BaseStatsReporter { - CachedCounter allocateCounter(String name, Map tags); +jmh { + benchmarkMode = ['Throughput'] - CachedGauge allocateGauge(String name, Map tags); + warmupIterations = 0 - CachedTimer allocateTimer(String name, Map tags); + iterations = 5 + batchSize = 1 - CachedHistogram allocateHistogram(String name, Map tags, Buckets buckets); + fork = 1 + forceGC = true + includeTests = true } diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/CountValue.java b/m3/src/generated/java/com/uber/m3/thrift/generated/CountValue.java new file mode 100644 index 0000000..8ce5dfa --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/CountValue.java @@ -0,0 +1,384 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Different types of count values + */ +public class CountValue implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("CountValue"); + + private static final org.apache.thrift.protocol.TField I64_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("i64Value", org.apache.thrift.protocol.TType.I64, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new CountValueStandardSchemeFactory()); + schemes.put(TupleScheme.class, new CountValueTupleSchemeFactory()); + } + + public long i64Value; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + I64_VALUE((short)1, "i64Value"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // I64_VALUE + return I64_VALUE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __I64VALUE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private _Fields optionals[] = {_Fields.I64_VALUE}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.I64_VALUE, new org.apache.thrift.meta_data.FieldMetaData("i64Value", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(CountValue.class, metaDataMap); + } + + public CountValue() { + } + + /** + * Performs a deep copy on other. + */ + public CountValue(CountValue other) { + __isset_bitfield = other.__isset_bitfield; + this.i64Value = other.i64Value; + } + + public CountValue deepCopy() { + return new CountValue(this); + } + + @Override + public void clear() { + setI64ValueIsSet(false); + this.i64Value = 0; + } + + public long getI64Value() { + return this.i64Value; + } + + public CountValue setI64Value(long i64Value) { + this.i64Value = i64Value; + setI64ValueIsSet(true); + return this; + } + + public void unsetI64Value() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + /** Returns true if field i64Value is set (has been assigned a value) and false otherwise */ + public boolean isSetI64Value() { + return EncodingUtils.testBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + public void setI64ValueIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __I64VALUE_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case I64_VALUE: + if (value == null) { + unsetI64Value(); + } else { + setI64Value((Long)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case I64_VALUE: + return Long.valueOf(getI64Value()); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case I64_VALUE: + return isSetI64Value(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof CountValue) + return this.equals((CountValue)that); + return false; + } + + public boolean equals(CountValue that) { + if (that == null) + return false; + + boolean this_present_i64Value = true && this.isSetI64Value(); + boolean that_present_i64Value = true && that.isSetI64Value(); + if (this_present_i64Value || that_present_i64Value) { + if (!(this_present_i64Value && that_present_i64Value)) + return false; + if (this.i64Value != that.i64Value) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(CountValue other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + CountValue typedOther = (CountValue)other; + + lastComparison = Boolean.valueOf(isSetI64Value()).compareTo(typedOther.isSetI64Value()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetI64Value()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i64Value, typedOther.i64Value); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("CountValue("); + boolean first = true; + + if (isSetI64Value()) { + sb.append("i64Value:"); + sb.append(this.i64Value); + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class CountValueStandardSchemeFactory implements SchemeFactory { + public CountValueStandardScheme getScheme() { + return new CountValueStandardScheme(); + } + } + + private static class CountValueStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, CountValue struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // I64_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, CountValue struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetI64Value()) { + oprot.writeFieldBegin(I64_VALUE_FIELD_DESC); + oprot.writeI64(struct.i64Value); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class CountValueTupleSchemeFactory implements SchemeFactory { + public CountValueTupleScheme getScheme() { + return new CountValueTupleScheme(); + } + } + + private static class CountValueTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, CountValue struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetI64Value()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetI64Value()) { + oprot.writeI64(struct.i64Value); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, CountValue struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/GaugeValue.java b/m3/src/generated/java/com/uber/m3/thrift/generated/GaugeValue.java new file mode 100644 index 0000000..5d313ea --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/GaugeValue.java @@ -0,0 +1,479 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Different types of gauge values + */ +public class GaugeValue implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("GaugeValue"); + + private static final org.apache.thrift.protocol.TField I64_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("i64Value", org.apache.thrift.protocol.TType.I64, (short)1); + private static final org.apache.thrift.protocol.TField D_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("dValue", org.apache.thrift.protocol.TType.DOUBLE, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new GaugeValueStandardSchemeFactory()); + schemes.put(TupleScheme.class, new GaugeValueTupleSchemeFactory()); + } + + public long i64Value; // optional + public double dValue; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + I64_VALUE((short)1, "i64Value"), + D_VALUE((short)2, "dValue"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // I64_VALUE + return I64_VALUE; + case 2: // D_VALUE + return D_VALUE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __I64VALUE_ISSET_ID = 0; + private static final int __DVALUE_ISSET_ID = 1; + private byte __isset_bitfield = 0; + private _Fields optionals[] = {_Fields.I64_VALUE,_Fields.D_VALUE}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.I64_VALUE, new org.apache.thrift.meta_data.FieldMetaData("i64Value", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.D_VALUE, new org.apache.thrift.meta_data.FieldMetaData("dValue", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(GaugeValue.class, metaDataMap); + } + + public GaugeValue() { + } + + /** + * Performs a deep copy on other. + */ + public GaugeValue(GaugeValue other) { + __isset_bitfield = other.__isset_bitfield; + this.i64Value = other.i64Value; + this.dValue = other.dValue; + } + + public GaugeValue deepCopy() { + return new GaugeValue(this); + } + + @Override + public void clear() { + setI64ValueIsSet(false); + this.i64Value = 0; + setDValueIsSet(false); + this.dValue = 0.0; + } + + public long getI64Value() { + return this.i64Value; + } + + public GaugeValue setI64Value(long i64Value) { + this.i64Value = i64Value; + setI64ValueIsSet(true); + return this; + } + + public void unsetI64Value() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + /** Returns true if field i64Value is set (has been assigned a value) and false otherwise */ + public boolean isSetI64Value() { + return EncodingUtils.testBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + public void setI64ValueIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __I64VALUE_ISSET_ID, value); + } + + public double getDValue() { + return this.dValue; + } + + public GaugeValue setDValue(double dValue) { + this.dValue = dValue; + setDValueIsSet(true); + return this; + } + + public void unsetDValue() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __DVALUE_ISSET_ID); + } + + /** Returns true if field dValue is set (has been assigned a value) and false otherwise */ + public boolean isSetDValue() { + return EncodingUtils.testBit(__isset_bitfield, __DVALUE_ISSET_ID); + } + + public void setDValueIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __DVALUE_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case I64_VALUE: + if (value == null) { + unsetI64Value(); + } else { + setI64Value((Long)value); + } + break; + + case D_VALUE: + if (value == null) { + unsetDValue(); + } else { + setDValue((Double)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case I64_VALUE: + return Long.valueOf(getI64Value()); + + case D_VALUE: + return Double.valueOf(getDValue()); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case I64_VALUE: + return isSetI64Value(); + case D_VALUE: + return isSetDValue(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof GaugeValue) + return this.equals((GaugeValue)that); + return false; + } + + public boolean equals(GaugeValue that) { + if (that == null) + return false; + + boolean this_present_i64Value = true && this.isSetI64Value(); + boolean that_present_i64Value = true && that.isSetI64Value(); + if (this_present_i64Value || that_present_i64Value) { + if (!(this_present_i64Value && that_present_i64Value)) + return false; + if (this.i64Value != that.i64Value) + return false; + } + + boolean this_present_dValue = true && this.isSetDValue(); + boolean that_present_dValue = true && that.isSetDValue(); + if (this_present_dValue || that_present_dValue) { + if (!(this_present_dValue && that_present_dValue)) + return false; + if (this.dValue != that.dValue) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(GaugeValue other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + GaugeValue typedOther = (GaugeValue)other; + + lastComparison = Boolean.valueOf(isSetI64Value()).compareTo(typedOther.isSetI64Value()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetI64Value()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i64Value, typedOther.i64Value); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetDValue()).compareTo(typedOther.isSetDValue()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDValue()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.dValue, typedOther.dValue); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("GaugeValue("); + boolean first = true; + + if (isSetI64Value()) { + sb.append("i64Value:"); + sb.append(this.i64Value); + first = false; + } + if (isSetDValue()) { + if (!first) sb.append(", "); + sb.append("dValue:"); + sb.append(this.dValue); + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class GaugeValueStandardSchemeFactory implements SchemeFactory { + public GaugeValueStandardScheme getScheme() { + return new GaugeValueStandardScheme(); + } + } + + private static class GaugeValueStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, GaugeValue struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // I64_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // D_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.dValue = iprot.readDouble(); + struct.setDValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, GaugeValue struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetI64Value()) { + oprot.writeFieldBegin(I64_VALUE_FIELD_DESC); + oprot.writeI64(struct.i64Value); + oprot.writeFieldEnd(); + } + if (struct.isSetDValue()) { + oprot.writeFieldBegin(D_VALUE_FIELD_DESC); + oprot.writeDouble(struct.dValue); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class GaugeValueTupleSchemeFactory implements SchemeFactory { + public GaugeValueTupleScheme getScheme() { + return new GaugeValueTupleScheme(); + } + } + + private static class GaugeValueTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, GaugeValue struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetI64Value()) { + optionals.set(0); + } + if (struct.isSetDValue()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetI64Value()) { + oprot.writeI64(struct.i64Value); + } + if (struct.isSetDValue()) { + oprot.writeDouble(struct.dValue); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, GaugeValue struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } + if (incoming.get(1)) { + struct.dValue = iprot.readDouble(); + struct.setDValueIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/M3.java b/m3/src/generated/java/com/uber/m3/thrift/generated/M3.java new file mode 100644 index 0000000..d4547f3 --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/M3.java @@ -0,0 +1,533 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class M3 { + + /** + * M3 Metrics Service + */ + public interface Iface { + + /** + * Emits a batch of metrics. + * + * @param batch + */ + public void emitMetricBatch(MetricBatch batch) throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void emitMetricBatch(MetricBatch batch, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + } + + public static class Client extends org.apache.thrift.TServiceClient implements Iface { + public static class Factory implements org.apache.thrift.TServiceClientFactory { + public Factory() {} + public Client getClient(org.apache.thrift.protocol.TProtocol prot) { + return new Client(prot); + } + public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(org.apache.thrift.protocol.TProtocol prot) + { + super(prot, prot); + } + + public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + super(iprot, oprot); + } + + public void emitMetricBatch(MetricBatch batch) throws org.apache.thrift.TException + { + send_emitMetricBatch(batch); + } + + public void send_emitMetricBatch(MetricBatch batch) throws org.apache.thrift.TException + { + emitMetricBatch_args args = new emitMetricBatch_args(); + args.setBatch(batch); + sendBase("emitMetricBatch", args); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + private org.apache.thrift.async.TAsyncClientManager clientManager; + private org.apache.thrift.protocol.TProtocolFactory protocolFactory; + public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + } + + public void emitMetricBatch(MetricBatch batch, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + emitMetricBatch_call method_call = new emitMetricBatch_call(batch, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class emitMetricBatch_call extends org.apache.thrift.async.TAsyncMethodCall { + private MetricBatch batch; + public emitMetricBatch_call(MetricBatch batch, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, true); + this.batch = batch; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("emitMetricBatch", org.apache.thrift.protocol.TMessageType.CALL, 0)); + emitMetricBatch_args args = new emitMetricBatch_args(); + args.setBatch(batch); + args.write(prot); + prot.writeMessageEnd(); + } + + public void getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new HashMap>())); + } + + protected Processor(I iface, Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static Map> getProcessMap(Map> processMap) { + processMap.put("emitMetricBatch", new emitMetricBatch()); + return processMap; + } + + public static class emitMetricBatch extends org.apache.thrift.ProcessFunction { + public emitMetricBatch() { + super("emitMetricBatch"); + } + + public emitMetricBatch_args getEmptyArgsInstance() { + return new emitMetricBatch_args(); + } + + protected boolean isOneway() { + return true; + } + + public org.apache.thrift.TBase getResult(I iface, emitMetricBatch_args args) throws org.apache.thrift.TException { + iface.emitMetricBatch(args.batch); + return null; + } + } + + } + + public static class emitMetricBatch_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("emitMetricBatch_args"); + + private static final org.apache.thrift.protocol.TField BATCH_FIELD_DESC = new org.apache.thrift.protocol.TField("batch", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new emitMetricBatch_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new emitMetricBatch_argsTupleSchemeFactory()); + } + + public MetricBatch batch; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + BATCH((short)1, "batch"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // BATCH + return BATCH; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.BATCH, new org.apache.thrift.meta_data.FieldMetaData("batch", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, MetricBatch.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(emitMetricBatch_args.class, metaDataMap); + } + + public emitMetricBatch_args() { + } + + public emitMetricBatch_args( + MetricBatch batch) + { + this(); + this.batch = batch; + } + + /** + * Performs a deep copy on other. + */ + public emitMetricBatch_args(emitMetricBatch_args other) { + if (other.isSetBatch()) { + this.batch = new MetricBatch(other.batch); + } + } + + public emitMetricBatch_args deepCopy() { + return new emitMetricBatch_args(this); + } + + @Override + public void clear() { + this.batch = null; + } + + public MetricBatch getBatch() { + return this.batch; + } + + public emitMetricBatch_args setBatch(MetricBatch batch) { + this.batch = batch; + return this; + } + + public void unsetBatch() { + this.batch = null; + } + + /** Returns true if field batch is set (has been assigned a value) and false otherwise */ + public boolean isSetBatch() { + return this.batch != null; + } + + public void setBatchIsSet(boolean value) { + if (!value) { + this.batch = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case BATCH: + if (value == null) { + unsetBatch(); + } else { + setBatch((MetricBatch)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case BATCH: + return getBatch(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case BATCH: + return isSetBatch(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof emitMetricBatch_args) + return this.equals((emitMetricBatch_args)that); + return false; + } + + public boolean equals(emitMetricBatch_args that) { + if (that == null) + return false; + + boolean this_present_batch = true && this.isSetBatch(); + boolean that_present_batch = true && that.isSetBatch(); + if (this_present_batch || that_present_batch) { + if (!(this_present_batch && that_present_batch)) + return false; + if (!this.batch.equals(that.batch)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(emitMetricBatch_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + emitMetricBatch_args typedOther = (emitMetricBatch_args)other; + + lastComparison = Boolean.valueOf(isSetBatch()).compareTo(typedOther.isSetBatch()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetBatch()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.batch, typedOther.batch); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("emitMetricBatch_args("); + boolean first = true; + + sb.append("batch:"); + if (this.batch == null) { + sb.append("null"); + } else { + sb.append(this.batch); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (batch != null) { + batch.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class emitMetricBatch_argsStandardSchemeFactory implements SchemeFactory { + public emitMetricBatch_argsStandardScheme getScheme() { + return new emitMetricBatch_argsStandardScheme(); + } + } + + private static class emitMetricBatch_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, emitMetricBatch_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // BATCH + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.batch = new MetricBatch(); + struct.batch.read(iprot); + struct.setBatchIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, emitMetricBatch_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.batch != null) { + oprot.writeFieldBegin(BATCH_FIELD_DESC); + struct.batch.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class emitMetricBatch_argsTupleSchemeFactory implements SchemeFactory { + public emitMetricBatch_argsTupleScheme getScheme() { + return new emitMetricBatch_argsTupleScheme(); + } + } + + private static class emitMetricBatch_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, emitMetricBatch_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetBatch()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetBatch()) { + struct.batch.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, emitMetricBatch_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.batch = new MetricBatch(); + struct.batch.read(iprot); + struct.setBatchIsSet(true); + } + } + } + + } + +} diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/Metric.java b/m3/src/generated/java/com/uber/m3/thrift/generated/Metric.java new file mode 100644 index 0000000..f2e0f8d --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/Metric.java @@ -0,0 +1,752 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The metric that is being emitted + */ +public class Metric implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Metric"); + + private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField METRIC_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("metricValue", org.apache.thrift.protocol.TType.STRUCT, (short)2); + private static final org.apache.thrift.protocol.TField TIMESTAMP_FIELD_DESC = new org.apache.thrift.protocol.TField("timestamp", org.apache.thrift.protocol.TType.I64, (short)3); + private static final org.apache.thrift.protocol.TField TAGS_FIELD_DESC = new org.apache.thrift.protocol.TField("tags", org.apache.thrift.protocol.TType.SET, (short)4); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new MetricStandardSchemeFactory()); + schemes.put(TupleScheme.class, new MetricTupleSchemeFactory()); + } + + public String name; // required + public MetricValue metricValue; // optional + public long timestamp; // optional + public Set tags; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + NAME((short)1, "name"), + METRIC_VALUE((short)2, "metricValue"), + TIMESTAMP((short)3, "timestamp"), + TAGS((short)4, "tags"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // NAME + return NAME; + case 2: // METRIC_VALUE + return METRIC_VALUE; + case 3: // TIMESTAMP + return TIMESTAMP; + case 4: // TAGS + return TAGS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __TIMESTAMP_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private _Fields optionals[] = {_Fields.METRIC_VALUE,_Fields.TIMESTAMP,_Fields.TAGS}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.METRIC_VALUE, new org.apache.thrift.meta_data.FieldMetaData("metricValue", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, MetricValue.class))); + tmpMap.put(_Fields.TIMESTAMP, new org.apache.thrift.meta_data.FieldMetaData("timestamp", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.TAGS, new org.apache.thrift.meta_data.FieldMetaData("tags", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, MetricTag.class)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Metric.class, metaDataMap); + } + + public Metric() { + } + + public Metric( + String name) + { + this(); + this.name = name; + } + + /** + * Performs a deep copy on other. + */ + public Metric(Metric other) { + __isset_bitfield = other.__isset_bitfield; + if (other.isSetName()) { + this.name = other.name; + } + if (other.isSetMetricValue()) { + this.metricValue = new MetricValue(other.metricValue); + } + this.timestamp = other.timestamp; + if (other.isSetTags()) { + Set __this__tags = new HashSet(); + for (MetricTag other_element : other.tags) { + __this__tags.add(new MetricTag(other_element)); + } + this.tags = __this__tags; + } + } + + public Metric deepCopy() { + return new Metric(this); + } + + @Override + public void clear() { + this.name = null; + this.metricValue = null; + setTimestampIsSet(false); + this.timestamp = 0; + this.tags = null; + } + + public String getName() { + return this.name; + } + + public Metric setName(String name) { + this.name = name; + return this; + } + + public void unsetName() { + this.name = null; + } + + /** Returns true if field name is set (has been assigned a value) and false otherwise */ + public boolean isSetName() { + return this.name != null; + } + + public void setNameIsSet(boolean value) { + if (!value) { + this.name = null; + } + } + + public MetricValue getMetricValue() { + return this.metricValue; + } + + public Metric setMetricValue(MetricValue metricValue) { + this.metricValue = metricValue; + return this; + } + + public void unsetMetricValue() { + this.metricValue = null; + } + + /** Returns true if field metricValue is set (has been assigned a value) and false otherwise */ + public boolean isSetMetricValue() { + return this.metricValue != null; + } + + public void setMetricValueIsSet(boolean value) { + if (!value) { + this.metricValue = null; + } + } + + public long getTimestamp() { + return this.timestamp; + } + + public Metric setTimestamp(long timestamp) { + this.timestamp = timestamp; + setTimestampIsSet(true); + return this; + } + + public void unsetTimestamp() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TIMESTAMP_ISSET_ID); + } + + /** Returns true if field timestamp is set (has been assigned a value) and false otherwise */ + public boolean isSetTimestamp() { + return EncodingUtils.testBit(__isset_bitfield, __TIMESTAMP_ISSET_ID); + } + + public void setTimestampIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TIMESTAMP_ISSET_ID, value); + } + + public int getTagsSize() { + return (this.tags == null) ? 0 : this.tags.size(); + } + + public java.util.Iterator getTagsIterator() { + return (this.tags == null) ? null : this.tags.iterator(); + } + + public void addToTags(MetricTag elem) { + if (this.tags == null) { + this.tags = new HashSet(); + } + this.tags.add(elem); + } + + public Set getTags() { + return this.tags; + } + + public Metric setTags(Set tags) { + this.tags = tags; + return this; + } + + public void unsetTags() { + this.tags = null; + } + + /** Returns true if field tags is set (has been assigned a value) and false otherwise */ + public boolean isSetTags() { + return this.tags != null; + } + + public void setTagsIsSet(boolean value) { + if (!value) { + this.tags = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case NAME: + if (value == null) { + unsetName(); + } else { + setName((String)value); + } + break; + + case METRIC_VALUE: + if (value == null) { + unsetMetricValue(); + } else { + setMetricValue((MetricValue)value); + } + break; + + case TIMESTAMP: + if (value == null) { + unsetTimestamp(); + } else { + setTimestamp((Long)value); + } + break; + + case TAGS: + if (value == null) { + unsetTags(); + } else { + setTags((Set)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case NAME: + return getName(); + + case METRIC_VALUE: + return getMetricValue(); + + case TIMESTAMP: + return Long.valueOf(getTimestamp()); + + case TAGS: + return getTags(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case NAME: + return isSetName(); + case METRIC_VALUE: + return isSetMetricValue(); + case TIMESTAMP: + return isSetTimestamp(); + case TAGS: + return isSetTags(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof Metric) + return this.equals((Metric)that); + return false; + } + + public boolean equals(Metric that) { + if (that == null) + return false; + + boolean this_present_name = true && this.isSetName(); + boolean that_present_name = true && that.isSetName(); + if (this_present_name || that_present_name) { + if (!(this_present_name && that_present_name)) + return false; + if (!this.name.equals(that.name)) + return false; + } + + boolean this_present_metricValue = true && this.isSetMetricValue(); + boolean that_present_metricValue = true && that.isSetMetricValue(); + if (this_present_metricValue || that_present_metricValue) { + if (!(this_present_metricValue && that_present_metricValue)) + return false; + if (!this.metricValue.equals(that.metricValue)) + return false; + } + + boolean this_present_timestamp = true && this.isSetTimestamp(); + boolean that_present_timestamp = true && that.isSetTimestamp(); + if (this_present_timestamp || that_present_timestamp) { + if (!(this_present_timestamp && that_present_timestamp)) + return false; + if (this.timestamp != that.timestamp) + return false; + } + + boolean this_present_tags = true && this.isSetTags(); + boolean that_present_tags = true && that.isSetTags(); + if (this_present_tags || that_present_tags) { + if (!(this_present_tags && that_present_tags)) + return false; + if (!this.tags.equals(that.tags)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(Metric other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + Metric typedOther = (Metric)other; + + lastComparison = Boolean.valueOf(isSetName()).compareTo(typedOther.isSetName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, typedOther.name); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetMetricValue()).compareTo(typedOther.isSetMetricValue()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMetricValue()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.metricValue, typedOther.metricValue); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetTimestamp()).compareTo(typedOther.isSetTimestamp()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTimestamp()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timestamp, typedOther.timestamp); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetTags()).compareTo(typedOther.isSetTags()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTags()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tags, typedOther.tags); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Metric("); + boolean first = true; + + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (isSetMetricValue()) { + if (!first) sb.append(", "); + sb.append("metricValue:"); + if (this.metricValue == null) { + sb.append("null"); + } else { + sb.append(this.metricValue); + } + first = false; + } + if (isSetTimestamp()) { + if (!first) sb.append(", "); + sb.append("timestamp:"); + sb.append(this.timestamp); + first = false; + } + if (isSetTags()) { + if (!first) sb.append(", "); + sb.append("tags:"); + if (this.tags == null) { + sb.append("null"); + } else { + sb.append(this.tags); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (metricValue != null) { + metricValue.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class MetricStandardSchemeFactory implements SchemeFactory { + public MetricStandardScheme getScheme() { + return new MetricStandardScheme(); + } + } + + private static class MetricStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, Metric struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.name = iprot.readString(); + struct.setNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // METRIC_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.metricValue = new MetricValue(); + struct.metricValue.read(iprot); + struct.setMetricValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // TIMESTAMP + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.timestamp = iprot.readI64(); + struct.setTimestampIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 4: // TAGS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); + struct.tags = new HashSet(2*_set0.size); + for (int _i1 = 0; _i1 < _set0.size; ++_i1) + { + MetricTag _elem2; // required + _elem2 = new MetricTag(); + _elem2.read(iprot); + struct.tags.add(_elem2); + } + iprot.readSetEnd(); + } + struct.setTagsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, Metric struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.name != null) { + oprot.writeFieldBegin(NAME_FIELD_DESC); + oprot.writeString(struct.name); + oprot.writeFieldEnd(); + } + if (struct.metricValue != null) { + if (struct.isSetMetricValue()) { + oprot.writeFieldBegin(METRIC_VALUE_FIELD_DESC); + struct.metricValue.write(oprot); + oprot.writeFieldEnd(); + } + } + if (struct.isSetTimestamp()) { + oprot.writeFieldBegin(TIMESTAMP_FIELD_DESC); + oprot.writeI64(struct.timestamp); + oprot.writeFieldEnd(); + } + if (struct.tags != null) { + if (struct.isSetTags()) { + oprot.writeFieldBegin(TAGS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.tags.size())); + for (MetricTag _iter3 : struct.tags) + { + _iter3.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class MetricTupleSchemeFactory implements SchemeFactory { + public MetricTupleScheme getScheme() { + return new MetricTupleScheme(); + } + } + + private static class MetricTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, Metric struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetName()) { + optionals.set(0); + } + if (struct.isSetMetricValue()) { + optionals.set(1); + } + if (struct.isSetTimestamp()) { + optionals.set(2); + } + if (struct.isSetTags()) { + optionals.set(3); + } + oprot.writeBitSet(optionals, 4); + if (struct.isSetName()) { + oprot.writeString(struct.name); + } + if (struct.isSetMetricValue()) { + struct.metricValue.write(oprot); + } + if (struct.isSetTimestamp()) { + oprot.writeI64(struct.timestamp); + } + if (struct.isSetTags()) { + { + oprot.writeI32(struct.tags.size()); + for (MetricTag _iter4 : struct.tags) + { + _iter4.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, Metric struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(4); + if (incoming.get(0)) { + struct.name = iprot.readString(); + struct.setNameIsSet(true); + } + if (incoming.get(1)) { + struct.metricValue = new MetricValue(); + struct.metricValue.read(iprot); + struct.setMetricValueIsSet(true); + } + if (incoming.get(2)) { + struct.timestamp = iprot.readI64(); + struct.setTimestampIsSet(true); + } + if (incoming.get(3)) { + { + org.apache.thrift.protocol.TSet _set5 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.tags = new HashSet(2*_set5.size); + for (int _i6 = 0; _i6 < _set5.size; ++_i6) + { + MetricTag _elem7; // required + _elem7 = new MetricTag(); + _elem7.read(iprot); + struct.tags.add(_elem7); + } + } + struct.setTagsIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/MetricBatch.java b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricBatch.java new file mode 100644 index 0000000..ecfd2fd --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricBatch.java @@ -0,0 +1,601 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Structure that holds a group of metrics which share + * common properties like the cluster and service. + */ +public class MetricBatch implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("MetricBatch"); + + private static final org.apache.thrift.protocol.TField METRICS_FIELD_DESC = new org.apache.thrift.protocol.TField("metrics", org.apache.thrift.protocol.TType.LIST, (short)1); + private static final org.apache.thrift.protocol.TField COMMON_TAGS_FIELD_DESC = new org.apache.thrift.protocol.TField("commonTags", org.apache.thrift.protocol.TType.SET, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new MetricBatchStandardSchemeFactory()); + schemes.put(TupleScheme.class, new MetricBatchTupleSchemeFactory()); + } + + public List metrics; // required + public Set commonTags; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + METRICS((short)1, "metrics"), + COMMON_TAGS((short)2, "commonTags"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // METRICS + return METRICS; + case 2: // COMMON_TAGS + return COMMON_TAGS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private _Fields optionals[] = {_Fields.COMMON_TAGS}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.METRICS, new org.apache.thrift.meta_data.FieldMetaData("metrics", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Metric.class)))); + tmpMap.put(_Fields.COMMON_TAGS, new org.apache.thrift.meta_data.FieldMetaData("commonTags", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, MetricTag.class)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(MetricBatch.class, metaDataMap); + } + + public MetricBatch() { + } + + public MetricBatch( + List metrics) + { + this(); + this.metrics = metrics; + } + + /** + * Performs a deep copy on other. + */ + public MetricBatch(MetricBatch other) { + if (other.isSetMetrics()) { + List __this__metrics = new ArrayList(); + for (Metric other_element : other.metrics) { + __this__metrics.add(new Metric(other_element)); + } + this.metrics = __this__metrics; + } + if (other.isSetCommonTags()) { + Set __this__commonTags = new HashSet(); + for (MetricTag other_element : other.commonTags) { + __this__commonTags.add(new MetricTag(other_element)); + } + this.commonTags = __this__commonTags; + } + } + + public MetricBatch deepCopy() { + return new MetricBatch(this); + } + + @Override + public void clear() { + this.metrics = null; + this.commonTags = null; + } + + public int getMetricsSize() { + return (this.metrics == null) ? 0 : this.metrics.size(); + } + + public java.util.Iterator getMetricsIterator() { + return (this.metrics == null) ? null : this.metrics.iterator(); + } + + public void addToMetrics(Metric elem) { + if (this.metrics == null) { + this.metrics = new ArrayList(); + } + this.metrics.add(elem); + } + + public List getMetrics() { + return this.metrics; + } + + public MetricBatch setMetrics(List metrics) { + this.metrics = metrics; + return this; + } + + public void unsetMetrics() { + this.metrics = null; + } + + /** Returns true if field metrics is set (has been assigned a value) and false otherwise */ + public boolean isSetMetrics() { + return this.metrics != null; + } + + public void setMetricsIsSet(boolean value) { + if (!value) { + this.metrics = null; + } + } + + public int getCommonTagsSize() { + return (this.commonTags == null) ? 0 : this.commonTags.size(); + } + + public java.util.Iterator getCommonTagsIterator() { + return (this.commonTags == null) ? null : this.commonTags.iterator(); + } + + public void addToCommonTags(MetricTag elem) { + if (this.commonTags == null) { + this.commonTags = new HashSet(); + } + this.commonTags.add(elem); + } + + public Set getCommonTags() { + return this.commonTags; + } + + public MetricBatch setCommonTags(Set commonTags) { + this.commonTags = commonTags; + return this; + } + + public void unsetCommonTags() { + this.commonTags = null; + } + + /** Returns true if field commonTags is set (has been assigned a value) and false otherwise */ + public boolean isSetCommonTags() { + return this.commonTags != null; + } + + public void setCommonTagsIsSet(boolean value) { + if (!value) { + this.commonTags = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case METRICS: + if (value == null) { + unsetMetrics(); + } else { + setMetrics((List)value); + } + break; + + case COMMON_TAGS: + if (value == null) { + unsetCommonTags(); + } else { + setCommonTags((Set)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case METRICS: + return getMetrics(); + + case COMMON_TAGS: + return getCommonTags(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case METRICS: + return isSetMetrics(); + case COMMON_TAGS: + return isSetCommonTags(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof MetricBatch) + return this.equals((MetricBatch)that); + return false; + } + + public boolean equals(MetricBatch that) { + if (that == null) + return false; + + boolean this_present_metrics = true && this.isSetMetrics(); + boolean that_present_metrics = true && that.isSetMetrics(); + if (this_present_metrics || that_present_metrics) { + if (!(this_present_metrics && that_present_metrics)) + return false; + if (!this.metrics.equals(that.metrics)) + return false; + } + + boolean this_present_commonTags = true && this.isSetCommonTags(); + boolean that_present_commonTags = true && that.isSetCommonTags(); + if (this_present_commonTags || that_present_commonTags) { + if (!(this_present_commonTags && that_present_commonTags)) + return false; + if (!this.commonTags.equals(that.commonTags)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(MetricBatch other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + MetricBatch typedOther = (MetricBatch)other; + + lastComparison = Boolean.valueOf(isSetMetrics()).compareTo(typedOther.isSetMetrics()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMetrics()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.metrics, typedOther.metrics); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetCommonTags()).compareTo(typedOther.isSetCommonTags()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCommonTags()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.commonTags, typedOther.commonTags); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("MetricBatch("); + boolean first = true; + + sb.append("metrics:"); + if (this.metrics == null) { + sb.append("null"); + } else { + sb.append(this.metrics); + } + first = false; + if (isSetCommonTags()) { + if (!first) sb.append(", "); + sb.append("commonTags:"); + if (this.commonTags == null) { + sb.append("null"); + } else { + sb.append(this.commonTags); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class MetricBatchStandardSchemeFactory implements SchemeFactory { + public MetricBatchStandardScheme getScheme() { + return new MetricBatchStandardScheme(); + } + } + + private static class MetricBatchStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, MetricBatch struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // METRICS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list8 = iprot.readListBegin(); + struct.metrics = new ArrayList(_list8.size); + for (int _i9 = 0; _i9 < _list8.size; ++_i9) + { + Metric _elem10; // required + _elem10 = new Metric(); + _elem10.read(iprot); + struct.metrics.add(_elem10); + } + iprot.readListEnd(); + } + struct.setMetricsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // COMMON_TAGS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set11 = iprot.readSetBegin(); + struct.commonTags = new HashSet(2*_set11.size); + for (int _i12 = 0; _i12 < _set11.size; ++_i12) + { + MetricTag _elem13; // required + _elem13 = new MetricTag(); + _elem13.read(iprot); + struct.commonTags.add(_elem13); + } + iprot.readSetEnd(); + } + struct.setCommonTagsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, MetricBatch struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.metrics != null) { + oprot.writeFieldBegin(METRICS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.metrics.size())); + for (Metric _iter14 : struct.metrics) + { + _iter14.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + if (struct.commonTags != null) { + if (struct.isSetCommonTags()) { + oprot.writeFieldBegin(COMMON_TAGS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.commonTags.size())); + for (MetricTag _iter15 : struct.commonTags) + { + _iter15.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class MetricBatchTupleSchemeFactory implements SchemeFactory { + public MetricBatchTupleScheme getScheme() { + return new MetricBatchTupleScheme(); + } + } + + private static class MetricBatchTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, MetricBatch struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetMetrics()) { + optionals.set(0); + } + if (struct.isSetCommonTags()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetMetrics()) { + { + oprot.writeI32(struct.metrics.size()); + for (Metric _iter16 : struct.metrics) + { + _iter16.write(oprot); + } + } + } + if (struct.isSetCommonTags()) { + { + oprot.writeI32(struct.commonTags.size()); + for (MetricTag _iter17 : struct.commonTags) + { + _iter17.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, MetricBatch struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list18 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.metrics = new ArrayList(_list18.size); + for (int _i19 = 0; _i19 < _list18.size; ++_i19) + { + Metric _elem20; // required + _elem20 = new Metric(); + _elem20.read(iprot); + struct.metrics.add(_elem20); + } + } + struct.setMetricsIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TSet _set21 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.commonTags = new HashSet(2*_set21.size); + for (int _i22 = 0; _i22 < _set21.size; ++_i22) + { + MetricTag _elem23; // required + _elem23 = new MetricTag(); + _elem23.read(iprot); + struct.commonTags.add(_elem23); + } + } + struct.setCommonTagsIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/MetricTag.java b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricTag.java new file mode 100644 index 0000000..96ec0b4 --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricTag.java @@ -0,0 +1,492 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tags that can be applied to a metric + */ +public class MetricTag implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("MetricTag"); + + private static final org.apache.thrift.protocol.TField TAG_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("tagName", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField TAG_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("tagValue", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new MetricTagStandardSchemeFactory()); + schemes.put(TupleScheme.class, new MetricTagTupleSchemeFactory()); + } + + public String tagName; // required + public String tagValue; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + TAG_NAME((short)1, "tagName"), + TAG_VALUE((short)2, "tagValue"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // TAG_NAME + return TAG_NAME; + case 2: // TAG_VALUE + return TAG_VALUE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private _Fields optionals[] = {_Fields.TAG_VALUE}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.TAG_NAME, new org.apache.thrift.meta_data.FieldMetaData("tagName", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.TAG_VALUE, new org.apache.thrift.meta_data.FieldMetaData("tagValue", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(MetricTag.class, metaDataMap); + } + + public MetricTag() { + } + + public MetricTag( + String tagName) + { + this(); + this.tagName = tagName; + } + + /** + * Performs a deep copy on other. + */ + public MetricTag(MetricTag other) { + if (other.isSetTagName()) { + this.tagName = other.tagName; + } + if (other.isSetTagValue()) { + this.tagValue = other.tagValue; + } + } + + public MetricTag deepCopy() { + return new MetricTag(this); + } + + @Override + public void clear() { + this.tagName = null; + this.tagValue = null; + } + + public String getTagName() { + return this.tagName; + } + + public MetricTag setTagName(String tagName) { + this.tagName = tagName; + return this; + } + + public void unsetTagName() { + this.tagName = null; + } + + /** Returns true if field tagName is set (has been assigned a value) and false otherwise */ + public boolean isSetTagName() { + return this.tagName != null; + } + + public void setTagNameIsSet(boolean value) { + if (!value) { + this.tagName = null; + } + } + + public String getTagValue() { + return this.tagValue; + } + + public MetricTag setTagValue(String tagValue) { + this.tagValue = tagValue; + return this; + } + + public void unsetTagValue() { + this.tagValue = null; + } + + /** Returns true if field tagValue is set (has been assigned a value) and false otherwise */ + public boolean isSetTagValue() { + return this.tagValue != null; + } + + public void setTagValueIsSet(boolean value) { + if (!value) { + this.tagValue = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case TAG_NAME: + if (value == null) { + unsetTagName(); + } else { + setTagName((String)value); + } + break; + + case TAG_VALUE: + if (value == null) { + unsetTagValue(); + } else { + setTagValue((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case TAG_NAME: + return getTagName(); + + case TAG_VALUE: + return getTagValue(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case TAG_NAME: + return isSetTagName(); + case TAG_VALUE: + return isSetTagValue(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof MetricTag) + return this.equals((MetricTag)that); + return false; + } + + public boolean equals(MetricTag that) { + if (that == null) + return false; + + boolean this_present_tagName = true && this.isSetTagName(); + boolean that_present_tagName = true && that.isSetTagName(); + if (this_present_tagName || that_present_tagName) { + if (!(this_present_tagName && that_present_tagName)) + return false; + if (!this.tagName.equals(that.tagName)) + return false; + } + + boolean this_present_tagValue = true && this.isSetTagValue(); + boolean that_present_tagValue = true && that.isSetTagValue(); + if (this_present_tagValue || that_present_tagValue) { + if (!(this_present_tagValue && that_present_tagValue)) + return false; + if (!this.tagValue.equals(that.tagValue)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(MetricTag other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + MetricTag typedOther = (MetricTag)other; + + lastComparison = Boolean.valueOf(isSetTagName()).compareTo(typedOther.isSetTagName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTagName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tagName, typedOther.tagName); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetTagValue()).compareTo(typedOther.isSetTagValue()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTagValue()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tagValue, typedOther.tagValue); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("MetricTag("); + boolean first = true; + + sb.append("tagName:"); + if (this.tagName == null) { + sb.append("null"); + } else { + sb.append(this.tagName); + } + first = false; + if (isSetTagValue()) { + if (!first) sb.append(", "); + sb.append("tagValue:"); + if (this.tagValue == null) { + sb.append("null"); + } else { + sb.append(this.tagValue); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class MetricTagStandardSchemeFactory implements SchemeFactory { + public MetricTagStandardScheme getScheme() { + return new MetricTagStandardScheme(); + } + } + + private static class MetricTagStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, MetricTag struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // TAG_NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.tagName = iprot.readString(); + struct.setTagNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // TAG_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.tagValue = iprot.readString(); + struct.setTagValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, MetricTag struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.tagName != null) { + oprot.writeFieldBegin(TAG_NAME_FIELD_DESC); + oprot.writeString(struct.tagName); + oprot.writeFieldEnd(); + } + if (struct.tagValue != null) { + if (struct.isSetTagValue()) { + oprot.writeFieldBegin(TAG_VALUE_FIELD_DESC); + oprot.writeString(struct.tagValue); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class MetricTagTupleSchemeFactory implements SchemeFactory { + public MetricTagTupleScheme getScheme() { + return new MetricTagTupleScheme(); + } + } + + private static class MetricTagTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, MetricTag struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetTagName()) { + optionals.set(0); + } + if (struct.isSetTagValue()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetTagName()) { + oprot.writeString(struct.tagName); + } + if (struct.isSetTagValue()) { + oprot.writeString(struct.tagValue); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, MetricTag struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.tagName = iprot.readString(); + struct.setTagNameIsSet(true); + } + if (incoming.get(1)) { + struct.tagValue = iprot.readString(); + struct.setTagValueIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/MetricValue.java b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricValue.java new file mode 100644 index 0000000..d12c798 --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/MetricValue.java @@ -0,0 +1,607 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Different types of values that m3 emits. Each metric + * must contain one of these values + */ +public class MetricValue implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("MetricValue"); + + private static final org.apache.thrift.protocol.TField COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("count", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField GAUGE_FIELD_DESC = new org.apache.thrift.protocol.TField("gauge", org.apache.thrift.protocol.TType.STRUCT, (short)2); + private static final org.apache.thrift.protocol.TField TIMER_FIELD_DESC = new org.apache.thrift.protocol.TField("timer", org.apache.thrift.protocol.TType.STRUCT, (short)3); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new MetricValueStandardSchemeFactory()); + schemes.put(TupleScheme.class, new MetricValueTupleSchemeFactory()); + } + + public CountValue count; // optional + public GaugeValue gauge; // optional + public TimerValue timer; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + COUNT((short)1, "count"), + GAUGE((short)2, "gauge"), + TIMER((short)3, "timer"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // COUNT + return COUNT; + case 2: // GAUGE + return GAUGE; + case 3: // TIMER + return TIMER; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private _Fields optionals[] = {_Fields.COUNT,_Fields.GAUGE,_Fields.TIMER}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.COUNT, new org.apache.thrift.meta_data.FieldMetaData("count", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CountValue.class))); + tmpMap.put(_Fields.GAUGE, new org.apache.thrift.meta_data.FieldMetaData("gauge", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, GaugeValue.class))); + tmpMap.put(_Fields.TIMER, new org.apache.thrift.meta_data.FieldMetaData("timer", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TimerValue.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(MetricValue.class, metaDataMap); + } + + public MetricValue() { + } + + /** + * Performs a deep copy on other. + */ + public MetricValue(MetricValue other) { + if (other.isSetCount()) { + this.count = new CountValue(other.count); + } + if (other.isSetGauge()) { + this.gauge = new GaugeValue(other.gauge); + } + if (other.isSetTimer()) { + this.timer = new TimerValue(other.timer); + } + } + + public MetricValue deepCopy() { + return new MetricValue(this); + } + + @Override + public void clear() { + this.count = null; + this.gauge = null; + this.timer = null; + } + + public CountValue getCount() { + return this.count; + } + + public MetricValue setCount(CountValue count) { + this.count = count; + return this; + } + + public void unsetCount() { + this.count = null; + } + + /** Returns true if field count is set (has been assigned a value) and false otherwise */ + public boolean isSetCount() { + return this.count != null; + } + + public void setCountIsSet(boolean value) { + if (!value) { + this.count = null; + } + } + + public GaugeValue getGauge() { + return this.gauge; + } + + public MetricValue setGauge(GaugeValue gauge) { + this.gauge = gauge; + return this; + } + + public void unsetGauge() { + this.gauge = null; + } + + /** Returns true if field gauge is set (has been assigned a value) and false otherwise */ + public boolean isSetGauge() { + return this.gauge != null; + } + + public void setGaugeIsSet(boolean value) { + if (!value) { + this.gauge = null; + } + } + + public TimerValue getTimer() { + return this.timer; + } + + public MetricValue setTimer(TimerValue timer) { + this.timer = timer; + return this; + } + + public void unsetTimer() { + this.timer = null; + } + + /** Returns true if field timer is set (has been assigned a value) and false otherwise */ + public boolean isSetTimer() { + return this.timer != null; + } + + public void setTimerIsSet(boolean value) { + if (!value) { + this.timer = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case COUNT: + if (value == null) { + unsetCount(); + } else { + setCount((CountValue)value); + } + break; + + case GAUGE: + if (value == null) { + unsetGauge(); + } else { + setGauge((GaugeValue)value); + } + break; + + case TIMER: + if (value == null) { + unsetTimer(); + } else { + setTimer((TimerValue)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case COUNT: + return getCount(); + + case GAUGE: + return getGauge(); + + case TIMER: + return getTimer(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case COUNT: + return isSetCount(); + case GAUGE: + return isSetGauge(); + case TIMER: + return isSetTimer(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof MetricValue) + return this.equals((MetricValue)that); + return false; + } + + public boolean equals(MetricValue that) { + if (that == null) + return false; + + boolean this_present_count = true && this.isSetCount(); + boolean that_present_count = true && that.isSetCount(); + if (this_present_count || that_present_count) { + if (!(this_present_count && that_present_count)) + return false; + if (!this.count.equals(that.count)) + return false; + } + + boolean this_present_gauge = true && this.isSetGauge(); + boolean that_present_gauge = true && that.isSetGauge(); + if (this_present_gauge || that_present_gauge) { + if (!(this_present_gauge && that_present_gauge)) + return false; + if (!this.gauge.equals(that.gauge)) + return false; + } + + boolean this_present_timer = true && this.isSetTimer(); + boolean that_present_timer = true && that.isSetTimer(); + if (this_present_timer || that_present_timer) { + if (!(this_present_timer && that_present_timer)) + return false; + if (!this.timer.equals(that.timer)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(MetricValue other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + MetricValue typedOther = (MetricValue)other; + + lastComparison = Boolean.valueOf(isSetCount()).compareTo(typedOther.isSetCount()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCount()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.count, typedOther.count); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetGauge()).compareTo(typedOther.isSetGauge()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetGauge()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.gauge, typedOther.gauge); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetTimer()).compareTo(typedOther.isSetTimer()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTimer()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timer, typedOther.timer); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("MetricValue("); + boolean first = true; + + if (isSetCount()) { + sb.append("count:"); + if (this.count == null) { + sb.append("null"); + } else { + sb.append(this.count); + } + first = false; + } + if (isSetGauge()) { + if (!first) sb.append(", "); + sb.append("gauge:"); + if (this.gauge == null) { + sb.append("null"); + } else { + sb.append(this.gauge); + } + first = false; + } + if (isSetTimer()) { + if (!first) sb.append(", "); + sb.append("timer:"); + if (this.timer == null) { + sb.append("null"); + } else { + sb.append(this.timer); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (count != null) { + count.validate(); + } + if (gauge != null) { + gauge.validate(); + } + if (timer != null) { + timer.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class MetricValueStandardSchemeFactory implements SchemeFactory { + public MetricValueStandardScheme getScheme() { + return new MetricValueStandardScheme(); + } + } + + private static class MetricValueStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, MetricValue struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // COUNT + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.count = new CountValue(); + struct.count.read(iprot); + struct.setCountIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // GAUGE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.gauge = new GaugeValue(); + struct.gauge.read(iprot); + struct.setGaugeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // TIMER + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.timer = new TimerValue(); + struct.timer.read(iprot); + struct.setTimerIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, MetricValue struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.count != null) { + if (struct.isSetCount()) { + oprot.writeFieldBegin(COUNT_FIELD_DESC); + struct.count.write(oprot); + oprot.writeFieldEnd(); + } + } + if (struct.gauge != null) { + if (struct.isSetGauge()) { + oprot.writeFieldBegin(GAUGE_FIELD_DESC); + struct.gauge.write(oprot); + oprot.writeFieldEnd(); + } + } + if (struct.timer != null) { + if (struct.isSetTimer()) { + oprot.writeFieldBegin(TIMER_FIELD_DESC); + struct.timer.write(oprot); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class MetricValueTupleSchemeFactory implements SchemeFactory { + public MetricValueTupleScheme getScheme() { + return new MetricValueTupleScheme(); + } + } + + private static class MetricValueTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, MetricValue struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetCount()) { + optionals.set(0); + } + if (struct.isSetGauge()) { + optionals.set(1); + } + if (struct.isSetTimer()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetCount()) { + struct.count.write(oprot); + } + if (struct.isSetGauge()) { + struct.gauge.write(oprot); + } + if (struct.isSetTimer()) { + struct.timer.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, MetricValue struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.count = new CountValue(); + struct.count.read(iprot); + struct.setCountIsSet(true); + } + if (incoming.get(1)) { + struct.gauge = new GaugeValue(); + struct.gauge.read(iprot); + struct.setGaugeIsSet(true); + } + if (incoming.get(2)) { + struct.timer = new TimerValue(); + struct.timer.read(iprot); + struct.setTimerIsSet(true); + } + } + } + +} + diff --git a/m3/src/generated/java/com/uber/m3/thrift/generated/TimerValue.java b/m3/src/generated/java/com/uber/m3/thrift/generated/TimerValue.java new file mode 100644 index 0000000..547b974 --- /dev/null +++ b/m3/src/generated/java/com/uber/m3/thrift/generated/TimerValue.java @@ -0,0 +1,479 @@ +/** + * Autogenerated by Thrift Compiler (0.9.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.uber.m3.thrift.generated; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Different types of timer values + */ +public class TimerValue implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TimerValue"); + + private static final org.apache.thrift.protocol.TField I64_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("i64Value", org.apache.thrift.protocol.TType.I64, (short)1); + private static final org.apache.thrift.protocol.TField D_VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("dValue", org.apache.thrift.protocol.TType.DOUBLE, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new TimerValueStandardSchemeFactory()); + schemes.put(TupleScheme.class, new TimerValueTupleSchemeFactory()); + } + + public long i64Value; // optional + public double dValue; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + I64_VALUE((short)1, "i64Value"), + D_VALUE((short)2, "dValue"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // I64_VALUE + return I64_VALUE; + case 2: // D_VALUE + return D_VALUE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __I64VALUE_ISSET_ID = 0; + private static final int __DVALUE_ISSET_ID = 1; + private byte __isset_bitfield = 0; + private _Fields optionals[] = {_Fields.I64_VALUE,_Fields.D_VALUE}; + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.I64_VALUE, new org.apache.thrift.meta_data.FieldMetaData("i64Value", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.D_VALUE, new org.apache.thrift.meta_data.FieldMetaData("dValue", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TimerValue.class, metaDataMap); + } + + public TimerValue() { + } + + /** + * Performs a deep copy on other. + */ + public TimerValue(TimerValue other) { + __isset_bitfield = other.__isset_bitfield; + this.i64Value = other.i64Value; + this.dValue = other.dValue; + } + + public TimerValue deepCopy() { + return new TimerValue(this); + } + + @Override + public void clear() { + setI64ValueIsSet(false); + this.i64Value = 0; + setDValueIsSet(false); + this.dValue = 0.0; + } + + public long getI64Value() { + return this.i64Value; + } + + public TimerValue setI64Value(long i64Value) { + this.i64Value = i64Value; + setI64ValueIsSet(true); + return this; + } + + public void unsetI64Value() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + /** Returns true if field i64Value is set (has been assigned a value) and false otherwise */ + public boolean isSetI64Value() { + return EncodingUtils.testBit(__isset_bitfield, __I64VALUE_ISSET_ID); + } + + public void setI64ValueIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __I64VALUE_ISSET_ID, value); + } + + public double getDValue() { + return this.dValue; + } + + public TimerValue setDValue(double dValue) { + this.dValue = dValue; + setDValueIsSet(true); + return this; + } + + public void unsetDValue() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __DVALUE_ISSET_ID); + } + + /** Returns true if field dValue is set (has been assigned a value) and false otherwise */ + public boolean isSetDValue() { + return EncodingUtils.testBit(__isset_bitfield, __DVALUE_ISSET_ID); + } + + public void setDValueIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __DVALUE_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case I64_VALUE: + if (value == null) { + unsetI64Value(); + } else { + setI64Value((Long)value); + } + break; + + case D_VALUE: + if (value == null) { + unsetDValue(); + } else { + setDValue((Double)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case I64_VALUE: + return Long.valueOf(getI64Value()); + + case D_VALUE: + return Double.valueOf(getDValue()); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case I64_VALUE: + return isSetI64Value(); + case D_VALUE: + return isSetDValue(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof TimerValue) + return this.equals((TimerValue)that); + return false; + } + + public boolean equals(TimerValue that) { + if (that == null) + return false; + + boolean this_present_i64Value = true && this.isSetI64Value(); + boolean that_present_i64Value = true && that.isSetI64Value(); + if (this_present_i64Value || that_present_i64Value) { + if (!(this_present_i64Value && that_present_i64Value)) + return false; + if (this.i64Value != that.i64Value) + return false; + } + + boolean this_present_dValue = true && this.isSetDValue(); + boolean that_present_dValue = true && that.isSetDValue(); + if (this_present_dValue || that_present_dValue) { + if (!(this_present_dValue && that_present_dValue)) + return false; + if (this.dValue != that.dValue) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(TimerValue other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + TimerValue typedOther = (TimerValue)other; + + lastComparison = Boolean.valueOf(isSetI64Value()).compareTo(typedOther.isSetI64Value()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetI64Value()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i64Value, typedOther.i64Value); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetDValue()).compareTo(typedOther.isSetDValue()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDValue()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.dValue, typedOther.dValue); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("TimerValue("); + boolean first = true; + + if (isSetI64Value()) { + sb.append("i64Value:"); + sb.append(this.i64Value); + first = false; + } + if (isSetDValue()) { + if (!first) sb.append(", "); + sb.append("dValue:"); + sb.append(this.dValue); + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class TimerValueStandardSchemeFactory implements SchemeFactory { + public TimerValueStandardScheme getScheme() { + return new TimerValueStandardScheme(); + } + } + + private static class TimerValueStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, TimerValue struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // I64_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // D_VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.dValue = iprot.readDouble(); + struct.setDValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, TimerValue struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetI64Value()) { + oprot.writeFieldBegin(I64_VALUE_FIELD_DESC); + oprot.writeI64(struct.i64Value); + oprot.writeFieldEnd(); + } + if (struct.isSetDValue()) { + oprot.writeFieldBegin(D_VALUE_FIELD_DESC); + oprot.writeDouble(struct.dValue); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class TimerValueTupleSchemeFactory implements SchemeFactory { + public TimerValueTupleScheme getScheme() { + return new TimerValueTupleScheme(); + } + } + + private static class TimerValueTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, TimerValue struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetI64Value()) { + optionals.set(0); + } + if (struct.isSetDValue()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetI64Value()) { + oprot.writeI64(struct.i64Value); + } + if (struct.isSetDValue()) { + oprot.writeDouble(struct.dValue); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, TimerValue struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.i64Value = iprot.readI64(); + struct.setI64ValueIsSet(true); + } + if (incoming.get(1)) { + struct.dValue = iprot.readDouble(); + struct.setDValueIsSet(true); + } + } + } + +} + diff --git a/m3/src/main/java/com/uber/m3/tally/m3/M3Reporter.java b/m3/src/main/java/com/uber/m3/tally/m3/M3Reporter.java new file mode 100644 index 0000000..9c5c30a --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/M3Reporter.java @@ -0,0 +1,753 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3; + +import com.uber.m3.tally.BucketPair; +import com.uber.m3.tally.BucketPairImpl; +import com.uber.m3.tally.Buckets; +import com.uber.m3.tally.Capabilities; +import com.uber.m3.tally.CapableOf; +import com.uber.m3.tally.StatsReporter; +import com.uber.m3.tally.m3.thrift.TCalcTransport; +import com.uber.m3.tally.m3.thrift.TMultiUdpClient; +import com.uber.m3.tally.m3.thrift.TUdpClient; +import com.uber.m3.thrift.generated.CountValue; +import com.uber.m3.thrift.generated.GaugeValue; +import com.uber.m3.thrift.generated.M3; +import com.uber.m3.thrift.generated.Metric; +import com.uber.m3.thrift.generated.MetricBatch; +import com.uber.m3.thrift.generated.MetricTag; +import com.uber.m3.thrift.generated.MetricValue; +import com.uber.m3.thrift.generated.TimerValue; +import com.uber.m3.util.Duration; +import com.uber.m3.util.ImmutableMap; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TCompactProtocol; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.transport.TTransport; + +import java.net.InetAddress; +import java.net.SocketAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.Phaser; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.apache.thrift.transport.TTransportException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * An M3 implementation of a {@link StatsReporter}. + */ +public class M3Reporter implements StatsReporter, AutoCloseable { + public static final String SERVICE_TAG = "service"; + public static final String ENV_TAG = "env"; + public static final String HOST_TAG = "host"; + public static final String DEFAULT_TAG_VALUE = "default"; + + public static final String DEFAULT_HISTOGRAM_BUCKET_ID_NAME = "bucketid"; + public static final String DEFAULT_HISTOGRAM_BUCKET_NAME = "bucket"; + public static final int DEFAULT_HISTOGRAM_BUCKET_TAG_PRECISION = 6; + + private static final Logger LOG = LoggerFactory.getLogger(M3Reporter.class); + + private static final int MAX_PROCESSOR_WAIT_ON_CLOSE_MILLIS = 1000; + + private static final int DEFAULT_METRIC_SIZE = 100; + private static final int DEFAULT_MAX_QUEUE_SIZE = 4096; + private static final int DEFAULT_MAX_PACKET_SIZE = 1440; + + private static final int THREAD_POOL_SIZE = 10; + + private static final int EMIT_METRIC_BATCH_OVERHEAD = 19; + private static final int MIN_METRIC_BUCKET_ID_TAG_LENGTH = 4; + + private M3.Client client; + + // calcLock protects both calc and calcProtocol + private final Object calcLock = new Object(); + private TCalcTransport calc; + private TProtocol calcProtocol; + + private int maxProcessorWaitUntilFlushMillis; + + private int freeBytes; + + private String bucketIdTagName; + private String bucketTagName; + private String bucketValFmt; + + // Holds metrics to be flushed + private final BlockingQueue metricQueue; + // The service used to execute metric flushes + private ExecutorService executor; + // Used to keep track of how many processors are in progress in + // order to wait for them to finish before closing + private Phaser phaser = new Phaser(1); + + private TTransport transport; + + // Use inner Builder class to construct an M3Reporter + private M3Reporter(Builder builder) { + try { + // Builder verifies non-null, non-empty socketAddresses + SocketAddress[] socketAddresses = builder.socketAddresses; + + TProtocolFactory protocolFactory = new TCompactProtocol.Factory(); + + if (socketAddresses.length > 1) { + transport = new TMultiUdpClient(socketAddresses); + } else { + transport = new TUdpClient(socketAddresses[0]); + } + + transport.open(); + + client = new M3.Client(protocolFactory.getProtocol(transport)); + + calcProtocol = new TCompactProtocol.Factory().getProtocol(new TCalcTransport()); + calc = (TCalcTransport) calcProtocol.getTransport(); + + freeBytes = calculateFreeBytes(builder.maxPacketSizeBytes, builder.metricTagSet); + + maxProcessorWaitUntilFlushMillis = builder.maxProcessorWaitUntilFlushMillis; + + bucketIdTagName = builder.histogramBucketIdName; + bucketTagName = builder.histogramBucketName; + bucketValFmt = String.format("%%.%df", builder.histogramBucketTagPrecision); + + metricQueue = new LinkedBlockingQueue<>(builder.maxQueueSize); + + executor = builder.executor; + + addAndRunProcessor(builder.metricTagSet); + } catch (TTransportException | SocketException e) { + throw new RuntimeException("Exception creating M3Reporter", e); + } + } + + private int calculateFreeBytes(int maxPacketSizeBytes, Set commonTags) { + MetricBatch metricBatch = new MetricBatch(); + metricBatch.setCommonTags(commonTags); + metricBatch.setMetrics(new ArrayList()); + + int size; + + try { + metricBatch.write(calcProtocol); + size = calc.getSizeAndReset(); + } catch (TException e) { + LOG.warn("Unable to calculate metric batch size. Defaulting to: %s", DEFAULT_METRIC_SIZE); + size = DEFAULT_METRIC_SIZE; + } + + int numOverheadBytes = EMIT_METRIC_BATCH_OVERHEAD + size; + + freeBytes = maxPacketSizeBytes - numOverheadBytes; + + if (freeBytes <= 0) { + throw new IllegalArgumentException("Common tags serialized size exceeds packet size"); + } + + return freeBytes; + } + + private static String getHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + LOG.warn("Unable to determine hostname. Defaulting to: %s", DEFAULT_TAG_VALUE); + return DEFAULT_TAG_VALUE; + } + } + + private void addAndRunProcessor(Set commonTags) { + phaser.register(); + + executor.execute(new Processor(commonTags)); + } + + @Override + public Capabilities capabilities() { + return CapableOf.REPORTING_TAGGING; + } + + @Override + public void flush() { + try { + metricQueue.put(SizedMetric.FLUSH); + } catch (InterruptedException e) { + LOG.warn("Interrupted while trying to queue flush sentinel"); + } + } + + private void flush(List metrics, Set commonTags) { + if (metrics.isEmpty()) { + return; + } + + MetricBatch metricBatch = new MetricBatch(); + metricBatch.setCommonTags(commonTags); + metricBatch.setMetrics(metrics); + + try { + client.emitMetricBatch(metricBatch); + + } catch (TException tException) { + LOG.warn("Failed to flush metrics: " + tException.getMessage()); + } + + metricBatch.setMetrics(null); + + metrics.clear(); + } + + @Override + public void close() { + // Put sentinal value in queue so that processors know to disregard anything that comes after it. + queueSizedMetric(SizedMetric.CLOSE); + + // Important to use `shutdownNow` instead of `shutdown` to interrupt processor + // thread(s) or else they will block forever + executor.shutdownNow(); + + // Wait a maximum of `MAX_PROCESSOR_WAIT_ON_CLOSE_MILLIS` for all processors + // to return from flushing + try { + phaser.awaitAdvanceInterruptibly( + phaser.arrive(), + MAX_PROCESSOR_WAIT_ON_CLOSE_MILLIS, + TimeUnit.MILLISECONDS + ); + } catch (TimeoutException e) { + LOG.warn( + "M3Reporter closing before Processors complete after waiting timeout of %dms!", + MAX_PROCESSOR_WAIT_ON_CLOSE_MILLIS + ); + } catch (InterruptedException e) { + LOG.warn("M3Reporter closing before Processors complete due to being interrupted!"); + } + + transport.close(); + } + + private static Set toMetricTagSet(Map tags) { + Set metricTagSet = new HashSet<>(); + + if (tags == null) { + return metricTagSet; + } + + for (Map.Entry tag : tags.entrySet()) { + metricTagSet.add(createMetricTag(tag.getKey(), tag.getValue())); + } + + return metricTagSet; + } + + private static MetricTag createMetricTag(String tagName, String tagValue) { + MetricTag metricTag = new MetricTag(tagName); + + if (tagValue != null && !tagValue.isEmpty()) { + metricTag.setTagValue(tagValue); + } + + return metricTag; + } + + private int calculateSize(Metric metric) { + try { + synchronized (calcLock) { + metric.write(calcProtocol); + + return calc.getSizeAndReset(); + } + } catch (TException e) { + LOG.warn("Unable to calculate metric batch size. Defaulting to: " + DEFAULT_METRIC_SIZE); + return DEFAULT_METRIC_SIZE; + } + } + + private String valueBucketString(double bucketBound) { + if (bucketBound == Double.MAX_VALUE) { + return "infinity"; + } + + if (bucketBound == -Double.MAX_VALUE) { + return "-infinity"; + } + + return String.format(bucketValFmt, bucketBound); + } + + private String durationBucketString(Duration bucketBound) { + if (Duration.ZERO.equals(bucketBound)) { + return "0"; + } + + if (Duration.MAX_VALUE.equals(bucketBound)) { + return "infinity"; + } + + if (Duration.MIN_VALUE.equals(bucketBound)) { + return "-infinity"; + } + + return bucketBound.toString(); + } + + @Override + public void reportCounter(String name, Map tags, long value) { + reportCounterInternal(name, tags, value); + } + + @Override + public void reportGauge(String name, Map tags, double value) { + GaugeValue gaugeValue = new GaugeValue(); + gaugeValue.setDValue(value); + + MetricValue metricValue = new MetricValue(); + metricValue.setGauge(gaugeValue); + + Metric metric = newMetric(name, tags, metricValue); + + queueSizedMetric(new SizedMetric(metric, calculateSize(metric))); + } + + @Override + public void reportTimer(String name, Map tags, Duration interval) { + TimerValue timerValue = new TimerValue(); + timerValue.setI64Value(interval.getNanos()); + + MetricValue metricValue = new MetricValue(); + metricValue.setTimer(timerValue); + + Metric metric = newMetric(name, tags, metricValue); + + queueSizedMetric(new SizedMetric(metric, calculateSize(metric))); + } + + @Override + public void reportHistogramValueSamples( + String name, + Map tags, + Buckets buckets, + double bucketLowerBound, + double bucketUpperBound, + long samples + ) { + // Append histogram bucket-specific tags + int bucketIdLen = String.valueOf(buckets.size()).length(); + bucketIdLen = Math.max(bucketIdLen, MIN_METRIC_BUCKET_ID_TAG_LENGTH); + + String bucketIdFmt = String.format("%%0%sd", bucketIdLen); + + BucketPair[] bucketPairs = BucketPairImpl.bucketPairs(buckets); + + if (tags == null) { + // We know that the HashMap will only contain two items at this point, + // therefore initialCapacity of 2 and loadFactor of 1. + tags = new HashMap<>(2, 1); + } + + for (int i = 0; i < bucketPairs.length; i++) { + // Look for the first pair with an upper bound greater than or equal + // to the given upper bound. + if (bucketPairs[i].upperBoundValue() >= bucketUpperBound) { + String idTagValue = String.format(bucketIdFmt, i); + + tags.put(bucketIdTagName, idTagValue); + tags.put(bucketTagName, + String.format("%s-%s", + valueBucketString(bucketPairs[i].lowerBoundValue()), + valueBucketString(bucketPairs[i].upperBoundValue()) + ) + ); + + break; + } + } + + reportCounterInternal(name, tags, samples); + } + + @Override + public void reportHistogramDurationSamples( + String name, + Map tags, + Buckets buckets, + Duration bucketLowerBound, + Duration bucketUpperBound, + long samples + ) { + // Append histogram bucket-specific tags + int bucketIdLen = String.valueOf(buckets.size()).length(); + bucketIdLen = Math.max(bucketIdLen, MIN_METRIC_BUCKET_ID_TAG_LENGTH); + + String bucketIdFmt = String.format("%%0%sd", bucketIdLen); + + BucketPair[] bucketPairs = BucketPairImpl.bucketPairs(buckets); + + if (tags == null) { + // We know that the HashMap will only contain two items at this point, + // therefore initialCapacity of 2 and loadFactor of 1. + tags = new HashMap<>(2, 1); + } + + for (int i = 0; i < bucketPairs.length; i++) { + // Look for the first pair with an upper bound greater than or equal + // to the given upper bound. + if (bucketPairs[i].upperBoundDuration().compareTo(bucketUpperBound) >= 0) { + String idTagValue = String.format(bucketIdFmt, i); + + tags.put(bucketIdTagName, idTagValue); + tags.put(bucketTagName, + String.format("%s-%s", + durationBucketString(bucketPairs[i].lowerBoundDuration()), + durationBucketString(bucketPairs[i].upperBoundDuration()) + ) + ); + + break; + } + } + + reportCounterInternal(name, tags, samples); + } + + // Relies on the calling function to provide guarantees of the reporter being open + private void reportCounterInternal(String name, Map tags, long value) { + CountValue countValue = new CountValue(); + countValue.setI64Value(value); + + MetricValue metricValue = new MetricValue(); + metricValue.setCount(countValue); + + Metric metric = newMetric(name, tags, metricValue); + + queueSizedMetric(new SizedMetric(metric, calculateSize(metric))); + } + + private Metric newMetric(String name, Map tags, MetricValue metricValue) { + Metric metric = new Metric(name); + metric.setTags(toMetricTagSet(tags)); + metric.setTimestamp(System.currentTimeMillis() * Duration.NANOS_PER_MILLI); + metric.setMetricValue(metricValue); + + return metric; + } + + private void queueSizedMetric(SizedMetric sizedMetric) { + try { + metricQueue.put(sizedMetric); + } catch (InterruptedException e) { + LOG.warn(String.format("Interrupted queueing metric: %s", sizedMetric.getMetric().getName())); + } + } + + private class Processor implements Runnable { + final Set commonTags; + List pendingMetrics = new ArrayList<>(freeBytes / 10); + int metricsSize = 0; + + Processor(Set commonTags) { + this.commonTags = commonTags; + } + + @Override + public void run() { + try { + while (!executor.isShutdown()) { + // This `poll` call will block for at most the specified duration to take an item + // off the queue. If we get an item, we append it to the queue to be flushed, + // otherwise we flush what we have so far. + // When this reporter is closed, shutdownNow will be called on the executor, + // which will interrupt this thread and proceed to the `InterruptedException` + // catch block. + SizedMetric sizedMetric = metricQueue.poll(maxProcessorWaitUntilFlushMillis, TimeUnit.MILLISECONDS); + + // Drop metrics that came in after close + if (sizedMetric == SizedMetric.CLOSE) { + metricQueue.clear(); + break; + } + + if (sizedMetric != null) { + flushMetricIteration(sizedMetric); + continue; + } + + // If we don't get any new metrics after waiting the specified time, + // flush what we have so far. + if (!pendingMetrics.isEmpty()) { + flushMetricIteration(SizedMetric.FLUSH); + } + } + } catch (InterruptedException e) { + // Don't care if we get interrupted - the finally block will clean up + } finally { + flushRemainingMetrics(); + + // Always arrive at phaser to prevent deadlock + phaser.arrive(); + } + } + + private void flushMetricIteration(SizedMetric sizedMetric) { + Metric metric = sizedMetric.getMetric(); + + if (sizedMetric == SizedMetric.FLUSH) { + flush(pendingMetrics, commonTags); + return; + } + + int size = sizedMetric.getSize(); + + if (metricsSize + size > freeBytes) { + flush(pendingMetrics, commonTags); + metricsSize = 0; + } + + pendingMetrics.add(metric); + + metricsSize += size; + } + + private void flushRemainingMetrics() { + while (!metricQueue.isEmpty()) { + SizedMetric sizedMetric = metricQueue.remove(); + + // Don't care about metrics that came in after close + if (sizedMetric == SizedMetric.CLOSE) { + break; + } + + flushMetricIteration(sizedMetric); + } + + flush(pendingMetrics, commonTags); + } + } + + /** + * Builder pattern to construct an {@link M3Reporter}. + */ + public static class Builder { + private SocketAddress[] socketAddresses; + private String service; + private String env; + private ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + // Non-generic EMPTY ImmutableMap will never contain any elements + @SuppressWarnings("unchecked") + private ImmutableMap commonTags = ImmutableMap.EMPTY; + private Set metricTagSet; + private boolean includeHost = true; + private int maxQueueSize = DEFAULT_MAX_QUEUE_SIZE; + private int maxPacketSizeBytes = DEFAULT_MAX_PACKET_SIZE; + private int maxProcessorWaitUntilFlushMillis = 10_000; + private String histogramBucketIdName = DEFAULT_HISTOGRAM_BUCKET_ID_NAME; + private String histogramBucketName = DEFAULT_HISTOGRAM_BUCKET_NAME; + private int histogramBucketTagPrecision = DEFAULT_HISTOGRAM_BUCKET_TAG_PRECISION; + + /** + * Constructs a {@link Builder}. Having at least one {@code SocketAddress} is required. + * @param socketAddresses the array of {@code SocketAddress}es for this {@link M3Reporter} + */ + public Builder(SocketAddress[] socketAddresses) { + if (socketAddresses == null || socketAddresses.length == 0) { + throw new IllegalArgumentException("Must specify at least one SocketAddress"); + } + + this.socketAddresses = socketAddresses; + } + + /** + * Constructs a {@link Builder}. Having at least one {@code SocketAddress} is required. + * @param socketAddress the {@code SocketAddress} for this {@link M3Reporter} + */ + public Builder(SocketAddress socketAddress) { + this(new SocketAddress[]{socketAddress}); + } + + /** + * Configures the service of this {@link Builder}. + * @param service the value to set + * @return this {@link Builder} with the new value set + */ + public Builder service(String service) { + this.service = service; + + return this; + } + + /** + * Configures the env of this {@link Builder}. + * @param env the value to set + * @return this {@link Builder} with the new value set + */ + public Builder env(String env) { + this.env = env; + + return this; + } + + /** + * Configures the executor of this {@link Builder}. + * @param executor the value to set + * @return this {@link Builder} with the new value set + */ + public Builder executor(ExecutorService executor) { + this.executor = executor; + + return this; + } + + /** + * Configures the common tags of this {@link Builder}. + * @param commonTags the value to set + * @return this {@link Builder} with the new value set + */ + public Builder commonTags(ImmutableMap commonTags) { + this.commonTags = commonTags; + + return this; + } + + /** + * Configures whether to include the host tag of this {@link Builder}. + * @param includeHost the value to set + * @return this {@link Builder} with the new value set + */ + public Builder includeHost(boolean includeHost) { + this.includeHost = includeHost; + + return this; + } + + /** + * Configures the maximum queue size of this {@link Builder}. + * @param maxQueueSize the value to set + * @return this {@link Builder} with the new value set + */ + public Builder maxQueueSize(int maxQueueSize) { + this.maxQueueSize = maxQueueSize; + + return this; + } + + /** + * Configures the maximum packet size in bytes of this {@link Builder}. + * @param maxPacketSizeBytes the value to set + * @return this {@link Builder} with the new value set + */ + public Builder maxPacketSizeBytes(int maxPacketSizeBytes) { + this.maxPacketSizeBytes = maxPacketSizeBytes; + + return this; + } + + /** + * Configures the maximum wait time in milliseconds size in bytes of this {@link Builder}. + * @param maxProcessorWaitUntilFlushMillis the value to set + * @return this {@link Builder} with the new value set + */ + public Builder maxProcessorWaitUntilFlushMillis(int maxProcessorWaitUntilFlushMillis) { + this.maxProcessorWaitUntilFlushMillis = maxProcessorWaitUntilFlushMillis; + + return this; + } + + /** + * Configures the histogram bucket ID name of this {@link Builder}. + * @param histogramBucketIdName the value to set + * @return this {@link Builder} with the new value set + */ + public Builder histogramBucketIdName(String histogramBucketIdName) { + this.histogramBucketIdName = histogramBucketIdName; + + return this; + } + + /** + * Configures the histogram bucket name of this {@link Builder}. + * @param histogramBucketName the value to set + * @return this {@link Builder} with the new value set + */ + public Builder histogramBucketName(String histogramBucketName) { + this.histogramBucketName = histogramBucketName; + + return this; + } + + /** + * Configures the histogram bucket tag precision of this {@link Builder}. + * @param histogramBucketTagPrecision the value to set + * @return this {@link Builder} with the new value set + */ + public Builder histogramBucketTagPrecision(int histogramBucketTagPrecision) { + this.histogramBucketTagPrecision = histogramBucketTagPrecision; + + return this; + } + + /** + * Builds and returns an {@link M3Reporter} with the configured paramters. + * @return a new {@link M3Reporter} instance with the configured paramters + */ + public M3Reporter build() { + metricTagSet = toMetricTagSet(commonTags); + + // Set and ensure required tags + if (!commonTags.containsKey(SERVICE_TAG)) { + if (service == null || service.isEmpty()) { + throw new IllegalArgumentException(String.format("Common tag [%s] is required", SERVICE_TAG)); + } + + metricTagSet.add(createMetricTag(SERVICE_TAG, service)); + } + if (!commonTags.containsKey(ENV_TAG)) { + if (env == null || env.isEmpty()) { + throw new IllegalArgumentException(String.format("Common tag [%s] is required", ENV_TAG)); + } + + metricTagSet.add(createMetricTag(ENV_TAG, env)); + } + if (includeHost && !commonTags.containsKey(HOST_TAG)) { + metricTagSet.add(createMetricTag(HOST_TAG, getHostName())); + } + + return new M3Reporter(this); + } + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/SizedMetric.java b/m3/src/main/java/com/uber/m3/tally/m3/SizedMetric.java new file mode 100644 index 0000000..e3a1075 --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/SizedMetric.java @@ -0,0 +1,89 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3; + +import com.uber.m3.thrift.generated.Metric; + +/** + * A metric along with its associated size. + */ +public class SizedMetric extends Metric { + public static final SizedMetric FLUSH = new SizedMetric(null, -1); + public static final SizedMetric CLOSE = new SizedMetric(null, -2); + + private Metric metric; + private int size; + + /** + * Creates a new {@link SizedMetric} with the given metric and size. + * @param metric the metric + * @param size the size of this metric + */ + public SizedMetric(Metric metric, int size) { + this.metric = metric; + this.size = size; + } + + /** + * Creates a default (empty) {@link SizedMetric}. + */ + public SizedMetric() { + this(null, 0); + } + + /** + * Sets the underlying metric. + * @param metric the metric to set + * @return this {@link SizedMetric} after setting the metric + */ + public SizedMetric setMetric(Metric metric) { + this.metric = metric; + + return this; + } + + /** + * Sets the underlying metric's size. + * @param size the size to set + * @return this {@link SizedMetric} after setting the size + */ + public SizedMetric setSize(int size) { + this.size = size; + + return this; + } + + /** + * Returns the metric. + * @return the metric + */ + public Metric getMetric() { + return metric; + } + + /** + * Returns the size of this metric. + * @return the size of this metric + */ + public int getSize() { + return size; + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/thrift/TCalcTransport.java b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TCalcTransport.java new file mode 100644 index 0000000..1bbf532 --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TCalcTransport.java @@ -0,0 +1,106 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3.thrift; + +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Dummy transport used for calculating size of metrics only. + */ +public class TCalcTransport extends TTransport { + private AtomicInteger size = new AtomicInteger(0); + + /** + * Dummy override to satisfy interface. Not used for our purposes. + * @return not used for our purposes + */ + @Override + public boolean isOpen() { + return true; + } + + /** + * Dummy override to satisfy interface. Not used for our purposes. + * @throws TTransportException not used for our purposes + */ + @Override + public void open() throws TTransportException { + } + + /** + * Dummy override to satisfy interface. Not used for our purposes. + */ + @Override + public void close() { + } + + /** + * Dummy override to satisfy interface. Not used for our purposes. + * @param bytes not used for our purposes + * @param offset not used for our purposes + * @param length not used for our purposes + * @return not used for our purposes + * @throws TTransportException not used for our purposes + */ + @Override + public int read(byte[] bytes, int offset, int length) throws TTransportException { + return 0; + } + + /** + * Record the number of bytes being written to this transport. + * @param bytes not used for our purposes + * @param offset not used for our purposes + * @param length the length of bytes being written + * @throws TTransportException this will never throw + */ + @Override + public void write(byte[] bytes, int offset, int length) throws TTransportException { + size.getAndAdd(length); + } + + /** + * Returns the size that has been written to this transport since the last reset + * and resets the size. + * @return the size that has been written to this transport since the last reset + */ + public int getSizeAndReset() { + return size.getAndSet(0); + } + + /** + * Returns the size that has been written to this transport since the last reset. + * @return the size that has been written to this transport since the last reset + */ + public int getSize() { + return size.get(); + } + + /** + * Resets the size that has been written to this transport since the last reset. + */ + public void resetSize() { + size.set(0); + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/thrift/TMultiUdpClient.java b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TMultiUdpClient.java new file mode 100644 index 0000000..daa30e2 --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TMultiUdpClient.java @@ -0,0 +1,90 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3.thrift; + +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +import java.net.SocketAddress; +import java.net.SocketException; + +/** + * A Thrift transport that sends to multiple connections + */ +public class TMultiUdpClient extends TTransport implements AutoCloseable { + private TTransport[] transports; + + public TMultiUdpClient(SocketAddress[] socketAddresses) throws SocketException { + if (socketAddresses == null || socketAddresses.length == 0) { + throw new IllegalArgumentException("Must provide at least one SocketAddress"); + } + + transports = new TTransport[socketAddresses.length]; + + for (int i = 0; i < socketAddresses.length; i++) { + transports[i] = new TUdpClient(socketAddresses[i]); + } + } + + @Override + public boolean isOpen() { + for (TTransport transport : transports) { + if (!transport.isOpen()) { + return false; + } + } + + return true; + } + + @Override + public void open() throws TTransportException { + for (TTransport transport : transports) { + transport.open(); + } + } + + @Override + public void close() { + for (TTransport transport : transports) { + transport.close(); + } + } + + @Override + public int read(byte[] bytes, int offset, int length) throws TTransportException { + throw new UnsupportedOperationException("Reading from multiple transports is not supported"); + } + + @Override + public void write(byte[] bytes, int offset, int length) throws TTransportException { + for (TTransport transport : transports) { + transport.write(bytes, offset, length); + } + } + + @Override + public void flush() throws TTransportException { + for (TTransport transport : transports) { + transport.flush(); + } + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpClient.java b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpClient.java new file mode 100644 index 0000000..f23834b --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpClient.java @@ -0,0 +1,70 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3.thrift; + +import org.apache.thrift.transport.TTransportException; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.SocketAddress; +import java.net.SocketException; + +/** + * A client for sending data via Thrift UDP. + */ +public class TUdpClient extends TUdpTransport implements AutoCloseable { + /** + * Constructs a UDP client with the given host and port. + * @param socketAddress the {@code SocketAddress} for this transport + * @throws SocketException if the underlying socket cannot be opened + */ + public TUdpClient(SocketAddress socketAddress) throws SocketException { + super(socketAddress); + } + + @Override + public void open() throws TTransportException { + try { + socket.connect(socketAddress); + } catch (SocketException e) { + throw new TTransportException("Error opening transport", e); + } + } + + @Override + public void flush() throws TTransportException { + synchronized (sendLock) { + byte[] bytes = new byte[MAX_BUFFER_SIZE]; + int length = writeBuffer.position(); + + writeBuffer.flip(); + writeBuffer.get(bytes, 0, length); + + try { + socket.send(new DatagramPacket(bytes, length)); + } catch (IOException e) { + throw new TTransportException(e); + } finally { + writeBuffer.clear(); + } + } + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpServer.java b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpServer.java new file mode 100644 index 0000000..0e6ca72 --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpServer.java @@ -0,0 +1,69 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3.thrift; + +import org.apache.thrift.transport.TTransportException; + +import java.net.SocketAddress; +import java.net.SocketException; + +/** + * A server for receiving data via Thrift UDP. + */ +public class TUdpServer extends TUdpTransport implements AutoCloseable { + private int timeoutMillis; + + /** + * Constructs a UDP server with the given host and port. Defaults to zero timeout. + * @param socketAddress the {@code SocketAddress} for this transport + * @throws SocketException if the underlying socket cannot be opened + */ + public TUdpServer(SocketAddress socketAddress) throws SocketException { + this(socketAddress, 0); + } + + /** + * Constructs a UDP server with the given host and port. + * @param socketAddress the {@code SocketAddress} for this transport + * @param timeoutMillis the timeout in milliseconds + * @throws SocketException if the underlying socket cannot be opened + */ + public TUdpServer(SocketAddress socketAddress, int timeoutMillis) throws SocketException { + super(socketAddress); + + this.timeoutMillis = timeoutMillis; + } + + @Override + public void open() throws TTransportException { + try { + socket.bind(socketAddress); + socket.setSoTimeout(timeoutMillis); + } catch (SocketException e) { + throw new TTransportException("Error opening transport", e); + } + } + + @Override + public void flush() throws TTransportException { + // No-op -- UDP server does not write responses back + } +} diff --git a/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpTransport.java b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpTransport.java new file mode 100644 index 0000000..a51f56d --- /dev/null +++ b/m3/src/main/java/com/uber/m3/tally/m3/thrift/TUdpTransport.java @@ -0,0 +1,142 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.uber.m3.tally.m3.thrift; + +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.SocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; + +/** + * Abstract class that supports Thrift UDP functionality. + */ +public abstract class TUdpTransport extends TTransport implements AutoCloseable { + public static final int MAX_BUFFER_SIZE = 65536; + + public final Object receiveLock = new Object(); + public final Object sendLock = new Object(); + + protected final DatagramSocket socket = new DatagramSocket(null); + protected ByteBuffer receiveBuffer; + protected ByteBuffer writeBuffer; + + protected SocketAddress socketAddress; + + protected TUdpTransport(SocketAddress socketAddress) throws SocketException { + this.socketAddress = socketAddress; + + writeBuffer = ByteBuffer.allocate(MAX_BUFFER_SIZE); + + receiveBuffer = ByteBuffer.allocate(MAX_BUFFER_SIZE); + receiveBuffer.flip(); + } + + @Override + public boolean isOpen() { + return !socket.isClosed(); + } + + @Override + public abstract void open() throws TTransportException; + + @Override + public void close() { + socket.close(); + } + + @Override + public int read(byte[] bytes, int offset, int length) throws TTransportException { + if (!isOpen()) { + throw new TTransportException(TTransportException.NOT_OPEN); + } + + synchronized (receiveLock) { + if (!receiveBuffer.hasRemaining()) { + // Use ByteBuffer's backing array and manually set the position and limit to + // avoid having to re-copy contents to a new array via `get` + DatagramPacket packet = new DatagramPacket(receiveBuffer.array(), MAX_BUFFER_SIZE); + + try { + socket.receive(packet); + } catch (IOException e) { + throw new TTransportException("Error from underlying socket", e); + } + + receiveBuffer.position(0); + receiveBuffer.limit(packet.getLength()); + } + + length = Math.min(length, receiveBuffer.remaining()); + + receiveBuffer.get(bytes, offset, length); + + return length; + } + } + + @Override + public void write(byte[] bytes, int offset, int length) throws TTransportException { + if (!isOpen()) { + throw new TTransportException(TTransportException.NOT_OPEN); + } + + synchronized (sendLock) { + if (writeBuffer.position() + length > MAX_BUFFER_SIZE) { + throw new TTransportException( + String.format("Message size too large: %d is greater than available size %d", + length, + MAX_BUFFER_SIZE - writeBuffer.position() + ) + ); + } + + writeBuffer.put(bytes, offset, length); + } + } + + @Override + public abstract void flush() throws TTransportException; + + @Override + public int getBytesRemainingInBuffer() { + return receiveBuffer.remaining(); + } + + @Override + public byte[] getBuffer() { + return receiveBuffer.array(); + } + + @Override + public int getBufferPosition() { + return receiveBuffer.position(); + } + + @Override + public void consumeBuffer(int length) { + receiveBuffer.position(receiveBuffer.position() + length); + } +} diff --git a/m3/src/main/thrift/m3.thrift b/m3/src/main/thrift/m3.thrift new file mode 100644 index 0000000..294a371 --- /dev/null +++ b/m3/src/main/thrift/m3.thrift @@ -0,0 +1,72 @@ +namespace java com.uber.m3.thrift.generated + +/** +* Different types of count values +*/ +struct CountValue { + 1: optional i64 i64Value +} + +/** +* Different types of gauge values +*/ +struct GaugeValue { + 1: optional i64 i64Value + 2: optional double dValue +} + +/** +* Different types of timer values +*/ +struct TimerValue { + 1: optional i64 i64Value + 2: optional double dValue +} + +/** +* Different types of values that m3 emits. Each metric +* must contain one of these values +*/ +struct MetricValue { + 1: optional CountValue count + 2: optional GaugeValue gauge + 3: optional TimerValue timer +} + +/** +* Tags that can be applied to a metric +*/ +struct MetricTag { + 1: string tagName, + 2: optional string tagValue +} + +/** +* The metric that is being emitted +*/ +struct Metric { + 1: string name, + 2: optional MetricValue metricValue, + 3: optional i64 timestamp, + 4: optional set tags +} + +/** +* Structure that holds a group of metrics which share +* common properties like the cluster and service. +*/ +struct MetricBatch { + 1: list metrics + 2: optional set commonTags +} + +/** +* M3 Metrics Service +*/ +service M3 { + + /** + * Emits a batch of metrics. + */ + oneway void emitMetricBatch(1: MetricBatch batch) +} diff --git a/core/src/main/java/com/uber/m3/tally/CachedHistogram.java b/m3/src/test/java/com/uber/m3/tally/m3/SizedMetricTest.java similarity index 51% rename from core/src/main/java/com/uber/m3/tally/CachedHistogram.java rename to m3/src/test/java/com/uber/m3/tally/m3/SizedMetricTest.java index 4d1d780..0f8e175 100644 --- a/core/src/main/java/com/uber/m3/tally/CachedHistogram.java +++ b/m3/src/test/java/com/uber/m3/tally/m3/SizedMetricTest.java @@ -18,27 +18,48 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package com.uber.m3.tally; - -import com.uber.m3.util.Duration; - -/** - * Interface for reporting cached histogram samples to buckets. - */ -public interface CachedHistogram { - /** - * Returns a {@link CachedHistogramBucket} with the specificed bounds. - * @param bucketLowerBound the {@link CachedHistogramBucket}'s lower bound - * @param bucketUpperBound the {@link CachedHistogramBucket}'s upper bound - * @return a {@link CachedHistogramBucket} with the specificed bounds - */ - CachedHistogramBucket valueBucket(double bucketLowerBound, double bucketUpperBound); - - /** - * Returns a {@link CachedHistogramBucket} with the specificed bounds. - * @param bucketLowerBound the {@link CachedHistogramBucket}'s lower bound {@link Duration} - * @param bucketUpperBound the {@link CachedHistogramBucket}'s upper bound {@link Duration} - * @return a {@link CachedHistogramBucket} with the specificed bounds - */ - CachedHistogramBucket durationBucket(Duration bucketLowerBound, Duration bucketUpperBound); +package com.uber.m3.tally.m3; + +import com.uber.m3.thrift.generated.Metric; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SizedMetricTest { + @Test + public void simpleSizedMetric() { + Metric metric = new Metric(); + + SizedMetric sizedMetric = new SizedMetric(metric, 1); + + assertEquals(sizedMetric.getMetric(), metric); + assertEquals(sizedMetric.getSize(), 1); + } + + @Test + public void nullSizedMetric() { + SizedMetric sizedMetric = new SizedMetric(null, 9); + + assertEquals(sizedMetric.getMetric(), null); + assertEquals(sizedMetric.getSize(), 9); + } + + @Test + public void setters() { + SizedMetric sizedMetric = new SizedMetric(); + + sizedMetric.setSize(9); + + assertEquals(9, sizedMetric.getSize()); + + sizedMetric.setSize(11); + sizedMetric.setSize(12); + + assertEquals(12, sizedMetric.getSize()); + + Metric metric1 = new Metric(); + sizedMetric.setMetric(metric1); + + assertEquals(metric1, sizedMetric.getMetric()); + } } diff --git a/settings.gradle b/settings.gradle index 2042209..cffc174 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -include 'core', 'example', 'statsd' +include 'core', 'example', 'statsd', 'm3' rootProject.name = 'tally'