Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
Revert input variable to 'source' (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuhlha authored Feb 10, 2021
1 parent d7dde9e commit 903382d
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion heroic-component/src/main/java/com/spotify/heroic/Query.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.*

data class Query(
val aggregation: Optional<Aggregation>,
val metricType: Optional<MetricType>, // points or distribution points for testing
val source: Optional<MetricType>, // points or distribution points for testing
val range: Optional<QueryDateRange>,
val filter: Optional<Filter>,
val options: Optional<QueryOptions>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import org.slf4j.LoggerFactory;

public class QueryBuilder {
private Optional<MetricType> source = Optional.empty();
private Optional<Map<String, String>> tags = Optional.empty();
private Optional<String> key = Optional.empty();
private Optional<Filter> filter = Optional.empty();
private Optional<QueryDateRange> range = Optional.empty();
private Optional<MetricType> metricType = Optional.empty();
private Optional<Aggregation> aggregation = Optional.empty();
private Optional<QueryOptions> options = Optional.empty();
private Optional<JsonNode> clientContext = Optional.empty();
Expand Down Expand Up @@ -98,20 +98,19 @@ public QueryBuilder filter(final Optional<Filter> filter) {
}

/**
* Specify a metricType to use, if none are specified it will be determined in CoreQueryManager.
* Specify an aggregation to use.
*/
public QueryBuilder metricType(final Optional<MetricType> metricType) {
checkNotNull(metricType, "metricType must not be null");
this.metricType = pickOptional(this.metricType, metricType);
public QueryBuilder aggregation(final Optional<Aggregation> aggregation) {
checkNotNull(aggregation, "aggregation must not be null");
this.aggregation = pickOptional(this.aggregation, aggregation);
return this;
}

/**
* Specify an aggregation to use.
* Specify a MetricType to use, if none are specified it will be determined in CoreQueryManager.
*/
public QueryBuilder aggregation(final Optional<Aggregation> aggregation) {
checkNotNull(aggregation, "aggregation must not be null");
this.aggregation = pickOptional(this.aggregation, aggregation);
public QueryBuilder source(Optional<MetricType> source) {
this.source = source;
return this;
}

Expand Down Expand Up @@ -150,7 +149,7 @@ public QueryBuilder features(final Optional<FeatureSet> features) {
}

public Query build() {
return new Query(aggregation, metricType, range, legacyFilter(), options, features);
return new Query(aggregation, source, range, legacyFilter(), options, features);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.*
data class QueryExpression(
@JvmField val context: Context,
val select: Optional<Expression>,
val metricType: Optional<MetricType>,
val source: Optional<MetricType>,
val range: Optional<RangeExpression>,
val filter: Optional<Filter>,
val with: Map<String, Expression>,
Expand All @@ -41,7 +41,7 @@ data class QueryExpression(
QueryExpression(
context,
select.map { it.eval(scope) },
metricType,
source,
range.map { it.eval(scope) },
filter,
Expression.evalMap(with, scope),
Expand All @@ -52,6 +52,6 @@ data class QueryExpression(
return visitor.visitQuery(this)
}

override fun toRepr() = """{select: $select metricType: $metricType,
override fun toRepr() = """{select: $select metricType: $source,
range: $range, filter: $filter, with: $with, as: $asExpression}""".trimIndent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data class FetchData(
}

data class Request(
val metricType: MetricType,
val type: MetricType,
val series: Series,
val range: DateRange,
val options: QueryOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,45 +158,44 @@ static Summary create(
public abstract static class Request {
@JsonCreator
public static Request create(
@JsonProperty("source") MetricType source,
@JsonProperty("filter") Filter filter,
@JsonProperty("range") DateRange range,
@JsonProperty("aggregation") AggregationInstance aggregation,
@JsonProperty("metricType") MetricType metricType,
@JsonProperty("options") QueryOptions options,
@JsonProperty("context") QueryContext context,
@JsonProperty("features") Features features
) {
return new AutoValue_FullQuery_Request(
filter, range, aggregation, metricType, options, context, features);
source, filter, range, aggregation, options, context, features);
}


@JsonProperty
public abstract MetricType source();
@JsonProperty
public abstract Filter filter();
@JsonProperty
public abstract DateRange range();
@JsonProperty
public abstract AggregationInstance aggregation();
@JsonProperty
public abstract MetricType metricType();
@JsonProperty
public abstract QueryOptions options();
@JsonProperty
public abstract QueryContext context();
@JsonProperty
public abstract Features features();

public Summary summarize() {
return Summary.create(filter(), range(), aggregation(), metricType(), options());
return Summary.create(source(), filter(), range(), aggregation(), options());
}

public void hashTo(final ObjectHasher hasher) {
hasher.putObject(getClass(), () -> {
hasher.putField("source", source(), hasher.enumValue());
hasher.putField("filter", filter(), hasher.with(Filter::hashTo));
hasher.putField("range", range(), hasher.with(DateRange::hashTo));
hasher.putField("aggregation", aggregation(),
hasher.with(AggregationInstance::hashTo));
hasher.putField("metricType", metricType(), hasher.enumValue());
hasher.putField("options", options(), hasher.with(QueryOptions::hashTo));
hasher.putField("features", features(), hasher.with(Features::hashTo));
});
Expand All @@ -206,25 +205,25 @@ public void hashTo(final ObjectHasher hasher) {
public abstract static class Summary {
@JsonCreator
public static Summary create(
@JsonProperty("source") MetricType source,
@JsonProperty("filter") Filter filter,
@JsonProperty("range") DateRange range,
@JsonProperty("aggregation") AggregationInstance aggregation,
@JsonProperty("metricType") MetricType metricType,
@JsonProperty("options") QueryOptions options
) {
return new AutoValue_FullQuery_Request_Summary(
filter, range, aggregation, metricType, options);
source, filter, range, aggregation, options);
}

@JsonProperty
abstract MetricType source();
@JsonProperty
abstract Filter filter();
@JsonProperty
abstract DateRange range();
@JsonProperty
abstract AggregationInstance aggregation();
@JsonProperty
abstract MetricType metricType();
@JsonProperty
abstract QueryOptions options();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public abstract class QueryMetrics {
public static QueryMetrics create(
Optional<String> query,
Optional<Aggregation> aggregation,
Optional<MetricType> metricType,
Optional<String> source,
Optional<QueryDateRange> range,
Optional<Filter> filter,
Optional<QueryOptions> options,
Optional<JsonNode> clientContext
) {
return legacyCreate(query, aggregation, metricType, range, filter, options, clientContext,
return legacyCreate(query, aggregation, source, range, filter, options, clientContext,
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), false);
}
Expand All @@ -60,7 +60,7 @@ public static QueryMetrics create(
public static QueryMetrics legacyCreate(
@JsonProperty("query") Optional<String> query,
@JsonProperty("aggregation") Optional<Aggregation> aggregation,
@JsonProperty("metricType") Optional<MetricType> metricType,
@JsonProperty("source") Optional<String> source,
@JsonProperty("range") Optional<QueryDateRange> range,
@JsonProperty("filter") Optional<Filter> filter,
@JsonProperty("options") Optional<QueryOptions> options,
Expand All @@ -75,17 +75,18 @@ public static QueryMetrics legacyCreate(

final Optional<Aggregation> legitAggregation = firstPresent(aggregation,
aggregators.filter(c -> !c.isEmpty()).map(Chain::fromList));
final Optional<MetricType> sourceMetric = source.flatMap(MetricType::fromIdentifier);

return new AutoValue_QueryMetrics(query, legitAggregation, metricType, range, filter,
return new AutoValue_QueryMetrics(query, legitAggregation, sourceMetric, range, filter,
options, clientContext, key, tags, features);
}

@JsonProperty("query")
public abstract Optional<String> query();
@JsonProperty("aggregation")
public abstract Optional<Aggregation> aggregation();
@JsonProperty("metricType")
public abstract Optional<MetricType> metricType();
@JsonProperty("source")
public abstract Optional<MetricType> source();
@JsonProperty("range")
public abstract Optional<QueryDateRange> range();
@JsonProperty("filter")
Expand All @@ -110,7 +111,7 @@ public QueryBuilder toQueryBuilder(final Function<String, QueryBuilder> stringTo
.filter(filter())
.range(range())
.aggregation(aggregation())
.metricType(metricType())
.source(source())
.options(options())
.clientContext(clientContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testAccessors() {
final QueryExpression e = build();

assertEquals(select, e.getSelect());
assertEquals(source, e.getMetricType());
assertEquals(source, e.getSource());
assertEquals(range, e.getRange());
assertEquals(filter, e.getFilter());
assertEquals(with, e.getWith());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public QueryBuilder newQueryFromString(final String queryString) {
return expressions.get(0).eval(scope).visit(new Expression.Visitor<QueryBuilder>() {
@Override
public QueryBuilder visitQuery(final QueryExpression e) {
final Optional<MetricType> metricType = e.getMetricType();
final Optional<MetricType> source = e.getSource();

final Optional<QueryDateRange> range =
e.getRange().map(expr -> expr.visit(new Expression.Visitor<QueryDateRange>() {
Expand Down Expand Up @@ -207,7 +207,7 @@ public Aggregation visitString(final StringExpression e) {
return new QueryBuilder()
.range(range)
.aggregation(aggregation)
.metricType(metricType)
.source(source)
.filter(filter);
}
});
Expand Down Expand Up @@ -242,7 +242,7 @@ public AsyncFuture<QueryResult> query(

final Aggregation aggregation = q.getAggregation().orElse(Empty.INSTANCE);

MetricType metricType = q.getMetricType().orElse(MetricType.POINT);
MetricType source = q.getSource().orElse(MetricType.POINT);

final DateRange rawRange = buildRange(q);

Expand Down Expand Up @@ -285,21 +285,21 @@ public AsyncFuture<QueryResult> query(

if (aggregationInstance instanceof GroupInstance) {
if (((GroupInstance) aggregationInstance).getEach() instanceof TdigestInstance) {
metricType = MetricType.DISTRIBUTION_POINTS;
source = MetricType.DISTRIBUTION_POINTS;
}
}

if (isDistributed) {
combiner = (metricType.equals(MetricType.POINT)) ?
combiner = (source.equals(MetricType.POINT)) ?
DistributedAggregationCombiner.create(root, range, bucketStrategy) :
TDigestAggregationCombiner.create(root, range, bucketStrategy);
} else {
combiner = (metricType.equals(MetricType.DISTRIBUTION_POINTS)) ?
combiner = (source.equals(MetricType.DISTRIBUTION_POINTS)) ?
AggregationCombiner.TDIGEST_DEFAULT : AggregationCombiner.DEFAULT;
}

final FullQuery.Request request =
FullQuery.Request.create(filter, range, aggregationInstance, metricType, options,
FullQuery.Request.create(source, filter, range, aggregationInstance, options,
queryContext, features);

queryLogger.logOutgoingRequestToShards(queryContext, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public String toString() {
private class Transform implements LazyTransform<FindSeries, FullQuery> {

private final AggregationInstance aggregation;
private final MetricType metricType;
private final MetricType source;
private final boolean failOnLimits;
private final OptionalLimit seriesLimit;
private final OptionalLimit groupLimit;
Expand All @@ -213,9 +213,9 @@ private Transform(
final Span parentSpan
) {
this.aggregation = request.aggregation();
this.metricType = request.metricType();
this.range = request.range();
this.options = request.options();
this.source = request.source();

this.failOnLimits = failOnLimits;
this.seriesLimit = seriesLimit;
Expand Down Expand Up @@ -322,7 +322,7 @@ public QueryTrace buildTrace() {

fetchSeries.addAnnotation(series.toString());
fetches.add(() -> metricBackend.fetch(
new FetchData.Request(metricType, series, range, options),
new FetchData.Request(source, series, range, options),
quotaWatcher,
mcr -> collector.acceptMetricsCollection(series, mcr),
fetchSeries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws

final MetricBackendGroup readGroup = metrics.useOptionalGroup(params.group);

final MetricType metricType = params.metricType.orElse(MetricType.POINT);
final MetricType source = params.source.orElse(MetricType.POINT);

final QueryOptions.Builder optionsBuilder =
QueryOptions.builder().tracing(Tracing.fromBoolean(params.tracing));
Expand Down Expand Up @@ -136,7 +136,7 @@ public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws
};

return readGroup
.fetch(new FetchData.Request(metricType, series, range, options),
.fetch(new FetchData.Request(source, series, range, options),
FetchQuotaWatcher.NO_QUOTA, printMetricsCollection, BlankSpan.INSTANCE)
.lazyTransform(handleResult);
}
Expand Down Expand Up @@ -173,9 +173,9 @@ private static class Parameters extends AbstractShellTaskParams {
@Option(name = "-s", aliases = {"--series"}, usage = "Series to fetch", metaVar = "<json>")
private Optional<String> series = Optional.empty();

@Option(name = "--metricType", aliases = {"--metricType"}, usage = "MetricType to fetch",
@Option(name = "--source", aliases = {"--source"}, usage = "MetricType to fetch",
metaVar = "<MetricType.POINT|MetricType.DISTRIBUTION_POINTS>")
private Optional<MetricType> metricType = Optional.empty();
private Optional<MetricType> source = Optional.empty();

@Option(name = "--start", usage = "Start date", metaVar = "<datetime>")
private Optional<String> start = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ public QueryResult query(final String queryString,

public QueryResult query(final QueryBuilder builder,
final Consumer<QueryBuilder> modifier,
final MetricType metricType,
final MetricType source,
final boolean isDistributed)
throws Exception {
queryCount += 1;

builder
.metricType(Optional.of(metricType))
.source(Optional.of(source))
.rangeIfAbsent(Optional.of(new QueryDateRange.Absolute(0, 40)));

if (isDistributed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public AsyncFuture<FetchData.Result> fetch(
final Span parentSpan
) {
return connection.doto(c -> {
final MetricType type = request.getMetricType();
final MetricType type = request.getType();

if (!watcher.mayReadData()) {
throw new IllegalArgumentException("query violated data limit");
Expand All @@ -286,7 +286,7 @@ public AsyncFuture<FetchData.Result> fetch(
consumer, parentSpan);
default:
return async.resolved(new FetchData.Result(QueryTrace.of(FETCH),
new QueryError("unsupported source: " + request.getMetricType())));
new QueryError("unsupported source: " + request.getType())));
}
});
}
Expand Down
Loading

0 comments on commit 903382d

Please sign in to comment.