Skip to content

Commit

Permalink
Merge branch 'main' into tst/trace-event-migration-backward-compatibi…
Browse files Browse the repository at this point in the history
…lity-e2e-tests

Signed-off-by: Qi Chen <[email protected]>
  • Loading branch information
chenqi0805 committed Apr 6, 2022
2 parents 4564080 + 5d3ff6d commit 456fdeb
Show file tree
Hide file tree
Showing 51 changed files with 4,481 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ This library is licensed under the [Apache 2.0 License](LICENSE)

## Copyright

Copyright OpenSearch Contributors. See [NOTICE](NOTICE.txt) for details.
Copyright OpenSearch Contributors. See [NOTICE](NOTICE) for details.
2 changes: 1 addition & 1 deletion build-resources.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ext.versionMap = [
junitJupiter : '5.8.2',
mockito : '3.11.2',
opentelemetryProto : '1.0.1-alpha',
opentelemetryProto : '1.7.1-alpha',
opensearchVersion : '1.1.0'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
public enum EventType {

LOG("LOG"),
TRACE("TRACE");
TRACE("TRACE"),
METRIC("METRIC");

private static final Map<String, EventType> NAMES_MAP = Arrays.stream(EventType.values())
.collect(Collectors.toMap(EventType::toString, Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

/**
* Represents a bucket of a {@link Histogram}.
* .
* @since 1.4
*/
public interface Bucket {

/**
* Gets the lower bound of the bucket
* @return the min
* @since 1.4
*/
Double getMin();

/**
* Gets the upper bound of the bucket
* @return the max
* @since 1.4
*/
Double getMax();

/**
* Gets the number of events in a bucket
* @return the count
* @since 1.4
*/
Long getCount();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

/**
* The default implementation of {@link Bucket}, measurement within a {@link Histogram}
*
* @since 1.4
*/
public class DefaultBucket implements Bucket {

private Double min;
private Double max;
private Long count;

// required for serialization
DefaultBucket() {}

public DefaultBucket(Double min, Double max, Long count) {
this.min = min;
this.max = max;
this.count = count;
}

@Override
public Double getMin() {
return min;
}

@Override
public Double getMax() {
return max;
}

@Override
public Long getCount() {
return count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

/**
* The default implementation of {@link Quantile}, measurement within a {@link Summary}
*
* @since 1.4
*/
public class DefaultQuantile implements Quantile {
private Double quantile;
private Double value;

// required for serialization
DefaultQuantile() {}

public DefaultQuantile(Double quantile, Double value) {
this.quantile = quantile;
this.value = value;
}

@Override
public Double getValue() {
return value;
}

@Override
public Double getQuantile() {
return quantile;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

/**
* A gauge event in Data Prepper represents a metric event.
* @since 1.4
*/
public interface Gauge extends Metric {

/**
* Gets the value for a gauge
* @return the value
* @since 1.4
*/
Double getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

import java.util.List;

/**
* A Histogram event
*
* @since 1.4
*/
public interface Histogram extends Metric {

/**
* Gets the sum for the histogram
*
* @return the sum of the values in the population
* @since 1.4
*/
Double getSum();


/**
* Gets the count of the histogram
* @return the count, must be equal to the sum of the "count" fields in buckets
* @since 1.4
*/
Long getCount();

/**
* Gets the bucket count for the histogram
*
* @return the bucket count
* @since 1.4
*/
Integer getBucketCount();

/**
* Gets the number of explicit bounds for the histogram
*
* @return the number of bounds
* @since 1.4
*/
Integer getExplicitBoundsCount();

/**
* Gets the aggregation temporality for the histogram
*
* @return the aggregation temporality
* @since 1.4
*/
String getAggregationTemporality();

/**
* Gets the actual buckets for a histogram
*
* @return the buckets
* @since 1.4
*/
List<? extends Bucket> getBuckets();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.model.metric;

import com.amazon.dataprepper.model.event.EventType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;

/**
* A Jackson implementation for {@link Gauge}.
*
* @since 1.4
*/
public class JacksonGauge extends JacksonMetric implements Gauge {

private static final String VALUE_KEY = "value";

private static final List<String> REQUIRED_KEYS = new ArrayList<>();
private static final List<String> REQUIRED_NON_EMPTY_KEYS = Arrays.asList(NAME_KEY, KIND_KEY, TIME_KEY);
private static final List<String> REQUIRED_NON_NULL_KEYS = Collections.singletonList(VALUE_KEY);


protected JacksonGauge(Builder builder) {
super(builder);
checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}

public static Builder builder() {
return new Builder();
}

@Override
public Double getValue() {
return this.get(VALUE_KEY, Double.class);
}

/**
* Builder for creating {@link JacksonGauge}
*
* @since 1.4
*/
public static class Builder extends JacksonMetric.Builder<JacksonGauge.Builder> {

@Override
public Builder getThis() {
return this;
}

/**
* Sets the value of the gauge
* @param value the value of the gauge
* @since 1.4
*/
public Builder withValue(final Double value) {
if (value != null) {
data.put(VALUE_KEY, value);
}
return this;
}

/**
* Returns a newly created {@link JacksonGauge}
* @return a JacksonGauge
* @since 1.4
*/
public JacksonGauge build() {
this.withEventKind(Metric.KIND.GAUGE.toString());
this.withData(data);
this.withEventType(EventType.METRIC.toString());
checkAndSetDefaultValues();
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, data);
return new JacksonGauge(this);
}

private void checkAndSetDefaultValues() {
data.computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
}
}
}
Loading

0 comments on commit 456fdeb

Please sign in to comment.