-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Webservice to Configure Metric Long Name #492
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import com.yahoo.bard.webservice.data.config.metric.makers.MetricMaker; | ||
import com.yahoo.bard.webservice.data.config.names.FieldName; | ||
import com.yahoo.bard.webservice.data.metric.LogicalMetric; | ||
import com.yahoo.bard.webservice.data.metric.LogicalMetricInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -23,7 +24,7 @@ | |
*/ | ||
public class MetricInstance { | ||
|
||
private final String metricName; | ||
private final LogicalMetricInfo logicalMetricInfo; | ||
private final List<String> dependencyMetricNames; | ||
private final MetricMaker maker; | ||
|
||
|
@@ -34,9 +35,27 @@ public class MetricInstance { | |
* @param maker The Metric Maker that creates the actual Logical Metric | ||
* @param dependencyMetricNames The names of metrics either in the dictionary or raw druid metrics that this | ||
* Logical Metric depends on | ||
* | ||
* @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long | ||
* name, description, etc. Use {@link #MetricInstance(LogicalMetricInfo, MetricMaker, String...)} instead. | ||
*/ | ||
@Deprecated | ||
public MetricInstance(String metricName, MetricMaker maker, String... dependencyMetricNames) { | ||
this.metricName = metricName; | ||
this.logicalMetricInfo = new LogicalMetricInfo(metricName); | ||
this.maker = maker; | ||
this.dependencyMetricNames = Arrays.asList(dependencyMetricNames); | ||
} | ||
|
||
/** | ||
* Construct a MetricInstance from Strings with a list of dependencyMetricNames. | ||
* | ||
* @param logicalMetricInfo Logical metric info provider | ||
* @param maker The Metric Maker that creates the actual Logical Metric | ||
* @param dependencyMetricNames The names of metrics either in the dictionary or raw druid metrics that this | ||
* Logical Metric depends on | ||
*/ | ||
public MetricInstance(LogicalMetricInfo logicalMetricInfo, MetricMaker maker, String... dependencyMetricNames) { | ||
this.logicalMetricInfo = logicalMetricInfo; | ||
this.maker = maker; | ||
this.dependencyMetricNames = Arrays.asList(dependencyMetricNames); | ||
} | ||
|
@@ -47,9 +66,29 @@ public MetricInstance(String metricName, MetricMaker maker, String... dependency | |
* @param metricName The name of the Logical Metric when it's in the metric dictionary | ||
* @param maker The Metric Maker that creates the actual Logical Metric | ||
* @param dependencyFields The field names that this Logical Metric depends on | ||
* | ||
* @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long | ||
* name, description, etc. Use {@link #MetricInstance(LogicalMetricInfo, MetricMaker, FieldName...)} instead. | ||
*/ | ||
@Deprecated | ||
public MetricInstance(FieldName metricName, MetricMaker maker, FieldName... dependencyFields) { | ||
this.metricName = metricName.asName(); | ||
this.logicalMetricInfo = new LogicalMetricInfo(metricName.asName()); | ||
this.maker = maker; | ||
this.dependencyMetricNames = new ArrayList<>(); | ||
for (FieldName fieldName : dependencyFields) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make this streamy using |
||
this.dependencyMetricNames.add(fieldName.asName()); | ||
} | ||
} | ||
|
||
/** | ||
* Construct a MetricInstance from FieldNames with a list of dependencyFields. | ||
* | ||
* @param logicalMetricInfo Logical metric info provider | ||
* @param maker The Metric Maker that creates the actual Logical Metric | ||
* @param dependencyFields The field names that this Logical Metric depends on | ||
*/ | ||
public MetricInstance(LogicalMetricInfo logicalMetricInfo, MetricMaker maker, FieldName... dependencyFields) { | ||
this.logicalMetricInfo = logicalMetricInfo; | ||
this.maker = maker; | ||
this.dependencyMetricNames = new ArrayList<>(); | ||
for (FieldName fieldName : dependencyFields) { | ||
|
@@ -58,7 +97,7 @@ public MetricInstance(FieldName metricName, MetricMaker maker, FieldName... depe | |
} | ||
|
||
public String getMetricName() { | ||
return metricName; | ||
return logicalMetricInfo.getName(); | ||
} | ||
|
||
public List<String> getDependencyMetricNames() { | ||
|
@@ -77,7 +116,7 @@ public MetricMaker getMaker() { | |
*/ | ||
public MetricInstance withName(String metricName) { | ||
return new MetricInstance( | ||
metricName, | ||
logicalMetricInfo, | ||
maker, | ||
dependencyMetricNames.toArray(new String[dependencyMetricNames.size()]) | ||
); | ||
|
@@ -91,7 +130,7 @@ public MetricInstance withName(String metricName) { | |
*/ | ||
public MetricInstance withMaker(MetricMaker maker) { | ||
return new MetricInstance( | ||
metricName, | ||
logicalMetricInfo, | ||
maker, | ||
dependencyMetricNames.toArray(new String[dependencyMetricNames.size()]) | ||
); | ||
|
@@ -105,7 +144,7 @@ public MetricInstance withMaker(MetricMaker maker) { | |
*/ | ||
public MetricInstance withDependencyMetricNames(List<String> dependencyMetricNames) { | ||
return new MetricInstance( | ||
metricName, | ||
logicalMetricInfo, | ||
maker, | ||
dependencyMetricNames.toArray(new String[dependencyMetricNames.size()]) | ||
); | ||
|
@@ -117,6 +156,6 @@ public MetricInstance withDependencyMetricNames(List<String> dependencyMetricNam | |
* @return The LogicalMetric with the provided name, using the given maker, that depends on the given metrics. | ||
*/ | ||
public LogicalMetric make() { | ||
return maker.make(metricName, dependencyMetricNames); | ||
return maker.make(logicalMetricInfo, dependencyMetricNames); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import static com.yahoo.bard.webservice.druid.util.FieldConverterSupplier.sketchConverter; | ||
|
||
import com.yahoo.bard.webservice.data.metric.LogicalMetric; | ||
import com.yahoo.bard.webservice.data.metric.LogicalMetricInfo; | ||
import com.yahoo.bard.webservice.data.metric.MetricDictionary; | ||
import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; | ||
import com.yahoo.bard.webservice.data.time.ZonelessTimeGrain; | ||
|
@@ -71,7 +72,7 @@ public AggregationAverageMaker(MetricDictionary metrics, ZonelessTimeGrain inner | |
} | ||
|
||
@Override | ||
protected LogicalMetric makeInner(String metricName, List<String> dependentMetrics) { | ||
protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { | ||
// Get the Metric that is being averaged over | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to proxy the other method into this one by building a default LogicalMetricInfo that is more or less backwards compatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michael-mclawhorn Yes! This is be a brilliant idea! 👍 |
||
LogicalMetric dependentMetric = metrics.get(dependentMetrics.get(0)); | ||
|
||
|
@@ -80,9 +81,9 @@ protected LogicalMetric makeInner(String metricName, List<String> dependentMetri | |
|
||
// Build the TemplateDruidQuery for the metric | ||
TemplateDruidQuery innerQuery = buildInnerQuery(sourceMetric, dependentMetric.getTemplateDruidQuery()); | ||
TemplateDruidQuery outerQuery = buildOuterQuery(metricName, sourceMetric, innerQuery); | ||
TemplateDruidQuery outerQuery = buildOuterQuery(logicalMetricInfo.getName(), sourceMetric, innerQuery); | ||
|
||
return new LogicalMetric(outerQuery, NO_OP_MAPPER, metricName); | ||
return new LogicalMetric(outerQuery, NO_OP_MAPPER, logicalMetricInfo); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
package com.yahoo.bard.webservice.data.config.metric.makers; | ||
|
||
import com.yahoo.bard.webservice.data.metric.LogicalMetric; | ||
import com.yahoo.bard.webservice.data.metric.LogicalMetricInfo; | ||
import com.yahoo.bard.webservice.data.metric.MetricDictionary; | ||
import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; | ||
import com.yahoo.bard.webservice.data.metric.mappers.NoOpResultSetMapper; | ||
|
@@ -63,16 +64,37 @@ public MetricMaker(MetricDictionary metrics) { | |
* @param dependentMetrics Metrics this metric depends on | ||
* | ||
* @return The new logicalMetric | ||
* | ||
* @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long | ||
* name, description, etc. Use {@link #make(LogicalMetricInfo, List)} instead. | ||
*/ | ||
@Deprecated | ||
public LogicalMetric make(String metricName, List<String> dependentMetrics) { | ||
return make(new LogicalMetricInfo(metricName), dependentMetrics); | ||
} | ||
|
||
/** | ||
* Make the metric. | ||
* <p> | ||
* This method also sanity-checks the dependent metrics to make sure that they | ||
* are metrics we have built and are in the metric dictionary. | ||
* <p> | ||
* Also sanity-checks that the number of dependent metrics are correct for the maker. | ||
* | ||
* @param logicalMetricInfo Logical metric info provider | ||
* @param dependentMetrics Metrics this metric depends on | ||
* | ||
* @return The new logicalMetric | ||
*/ | ||
public LogicalMetric make(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { | ||
// Check that all of the dependent metrics are in the dictionary | ||
assertDependentMetricsExist(dependentMetrics); | ||
|
||
// Check that we have the right number of metrics | ||
assertRequiredDependentMetricCount(metricName, dependentMetrics); | ||
assertRequiredDependentMetricCount(logicalMetricInfo.getName(), dependentMetrics); | ||
|
||
// Have the subclass actually build the metric | ||
return this.makeInner(metricName, dependentMetrics); | ||
return this.makeInner(logicalMetricInfo, dependentMetrics); | ||
} | ||
|
||
/** | ||
|
@@ -132,9 +154,32 @@ public LogicalMetric make(String metricName, String dependentMetric) { | |
* @param metricName Name for the metric we're making | ||
* @param dependentMetrics Metrics this metric depends on | ||
* | ||
* @return The new logicalMetric | ||
* @return the new logicalMetric | ||
* | ||
* @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long | ||
* name, description, etc. Use {@link #makeInner(LogicalMetricInfo, List)} instead. | ||
*/ | ||
@Deprecated | ||
protected LogicalMetric makeInner(String metricName, List<String> dependentMetrics) { | ||
return makeInner(new LogicalMetricInfo(metricName), dependentMetrics); | ||
} | ||
|
||
/** | ||
* Delegated to for actually making the metric. | ||
* | ||
* @param logicalMetricInfo Logical metric info provider | ||
* @param dependentMetrics Metrics this metric depends on | ||
* | ||
* @return the new logicalMetric | ||
*/ | ||
protected abstract LogicalMetric makeInner(String metricName, List<String> dependentMetrics); | ||
protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this was only implemented for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
String message = String.format( | ||
"Current implementation of MetricMaker '%s' does not support makeInner operation", | ||
this.getClass().getSimpleName() | ||
); | ||
LoggerFactory.getLogger(MetricMaker.class).error(message); | ||
throw new UnsupportedOperationException(message); | ||
} | ||
|
||
/** | ||
* Get the number of dependent metrics the maker requires for making the metric. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which contains all these fields in addition to metric name.