-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Set default_metric for time series on the index level #133464
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -647,6 +647,26 @@ public Iterator<Setting<?>> settings() { | |
Property.Final | ||
); | ||
|
||
public enum AggregateMetricDoubleDefaultMetric { | ||
MIN, | ||
MAX, | ||
SUM, | ||
VALUE_COUNT; | ||
} | ||
Comment on lines
+650
to
+655
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. nit: It feels a bit smelly to have this enum duplicate the other enum 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. Yeah we have a few of these enums....there's similarly one in the ES|QL side too and I would love to have just one enum but I'm not sure where it would live |
||
|
||
public static final Setting<AggregateMetricDoubleDefaultMetric> TIME_SERIES_DEFAULT_METRIC = Setting.enumSetting( | ||
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. Can this setting be moved to the xpack downsample module? We can just parse it in If that works then there is no need to define the enum that Jordan added a comment about, given that I think we can just use 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. I will try it out..! |
||
AggregateMetricDoubleDefaultMetric.class, | ||
"index.time_series.default_metric", | ||
AggregateMetricDoubleDefaultMetric.MAX, | ||
Property.IndexScope, | ||
Property.Final, | ||
Property.ServerlessPublic | ||
); | ||
|
||
public AggregateMetricDoubleDefaultMetric getDefaultMetric() { | ||
return defaultMetric; | ||
} | ||
|
||
/** | ||
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code> | ||
*/ | ||
|
@@ -896,6 +916,7 @@ private static String getIgnoreAboveDefaultValue(final Settings settings) { | |
private final boolean softDeleteEnabled; | ||
private volatile long softDeleteRetentionOperations; | ||
private final boolean es87TSDBCodecEnabled; | ||
private final AggregateMetricDoubleDefaultMetric defaultMetric; | ||
private final boolean logsdbRouteOnSortFields; | ||
private final boolean logsdbSortOnHostName; | ||
private final boolean logsdbAddHostNameField; | ||
|
@@ -1116,6 +1137,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti | |
indexRouting = IndexRouting.fromIndexMetadata(indexMetadata); | ||
sourceKeepMode = scopedSettings.get(Mapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING); | ||
es87TSDBCodecEnabled = scopedSettings.get(TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING); | ||
defaultMetric = scopedSettings.get(TIME_SERIES_DEFAULT_METRIC); | ||
logsdbRouteOnSortFields = scopedSettings.get(LOGSDB_ROUTE_ON_SORT_FIELDS); | ||
logsdbSortOnHostName = scopedSettings.get(LOGSDB_SORT_ON_HOST_NAME); | ||
logsdbAddHostNameField = scopedSettings.get(LOGSDB_ADD_HOST_NAME_FIELD); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ | |
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
@@ -712,7 +713,7 @@ private static void addMetricFields( | |
MappingVisitor.visitMapping(sourceIndexMappings, (field, mapping) -> { | ||
if (helper.isTimeSeriesMetric(field, mapping)) { | ||
try { | ||
addMetricFieldMapping(builder, field, mapping); | ||
addMetricFieldMapping(builder, field, mapping, helper.getDefaultMetric()); | ||
} catch (IOException e) { | ||
throw new ElasticsearchException("Error while adding metric for field [" + field + "]"); | ||
} | ||
|
@@ -761,7 +762,8 @@ public record AggregateMetricDoubleFieldSupportedMetrics(String defaultMetric, L | |
// public for testing | ||
public static AggregateMetricDoubleFieldSupportedMetrics getSupportedMetrics( | ||
final TimeSeriesParams.MetricType metricType, | ||
final Map<String, ?> fieldProperties | ||
final Map<String, ?> fieldProperties, | ||
final IndexSettings.AggregateMetricDoubleDefaultMetric indexLevelDefaultMetric | ||
) { | ||
boolean sourceIsAggregate = fieldProperties.get("type").equals(AggregateMetricDoubleFieldMapper.CONTENT_TYPE); | ||
List<String> supportedAggs = List.of(metricType.supportedAggs()); | ||
|
@@ -783,13 +785,19 @@ public static AggregateMetricDoubleFieldSupportedMetrics getSupportedMetrics( | |
(String) fieldProperties.get(AggregateMetricDoubleFieldMapper.Names.DEFAULT_METRIC), | ||
defaultMetric | ||
); | ||
} else { | ||
defaultMetric = indexLevelDefaultMetric.name().toLowerCase(Locale.ROOT); | ||
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. If I'm reading this correctly, Would it makes sense to instead have 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. I think this does make sense. Maybe the 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. I think I'm not entirely sure I understand the situation 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. I think you're right--in most cases, there will already be a default metric specified on the aggregate metric, since aggregate metrics are usually created by downsampling which adds a default metric using this logic. But it is technically possible to manually create an aggregate metric field that has no default metric specified. In this case, the logic here is hard-coded to default to using "max" as the default metric. But it might make more sense to instead use the new index-level |
||
} | ||
|
||
return new AggregateMetricDoubleFieldSupportedMetrics(defaultMetric, supportedAggs); | ||
} | ||
|
||
private static void addMetricFieldMapping(final XContentBuilder builder, final String field, final Map<String, ?> fieldProperties) | ||
throws IOException { | ||
private static void addMetricFieldMapping( | ||
final XContentBuilder builder, | ||
final String field, | ||
final Map<String, ?> fieldProperties, | ||
IndexSettings.AggregateMetricDoubleDefaultMetric defaultMetric | ||
) throws IOException { | ||
final TimeSeriesParams.MetricType metricType = TimeSeriesParams.MetricType.fromString( | ||
fieldProperties.get(TIME_SERIES_METRIC_PARAM).toString() | ||
); | ||
|
@@ -801,7 +809,7 @@ private static void addMetricFieldMapping(final XContentBuilder builder, final S | |
builder.field(fieldProperty, fieldProperties.get(fieldProperty)); | ||
} | ||
} else { | ||
var supported = getSupportedMetrics(metricType, fieldProperties); | ||
var supported = getSupportedMetrics(metricType, fieldProperties, defaultMetric); | ||
|
||
builder.field("type", AggregateMetricDoubleFieldMapper.CONTENT_TYPE) | ||
.stringListField(AggregateMetricDoubleFieldMapper.Names.METRICS, supported.supportedMetrics) | ||
|
@@ -942,6 +950,10 @@ private void createDownsampleIndex( | |
.put( | ||
IndexSettings.TIME_SERIES_END_TIME.getKey(), | ||
sourceIndexMetadata.getSettings().get(IndexSettings.TIME_SERIES_END_TIME.getKey()) | ||
) | ||
.put( | ||
IndexSettings.TIME_SERIES_DEFAULT_METRIC.getKey(), | ||
sourceIndexMetadata.getSettings().get(IndexSettings.TIME_SERIES_DEFAULT_METRIC.getKey()) | ||
); | ||
if (sourceIndexMetadata.getSettings().hasValue(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey())) { | ||
builder.put( | ||
|
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.
Given that this is a downsample feature. I think we should add this feature to the downsample module? It doesn't seem to have a class extending
FeatureSpecification
yet, but I think we can add that.