Skip to content
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

Implement aggregate_metric field mapper #49830

Merged
merged 31 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
92ccb70
Implemented aggregate_metric field type for storing pre-computed aggr…
csoulios Dec 4, 2019
3f41428
Addressing code review comments
csoulios Dec 5, 2019
556e086
Moved AggregateMetricFieldMapper to its own module
csoulios Dec 5, 2019
6d50c75
Fix broken doc test
csoulios Dec 11, 2019
527097e
Fixes to address code review comments
csoulios Dec 11, 2019
0eed690
Merge branch 'master' into rollups
csoulios Dec 16, 2019
29a1eb3
Fixes to address code review comments.
csoulios Dec 17, 2019
471f23b
Fix broken integration tests
csoulios Dec 17, 2019
5ef5e84
Added delegate field mappers of NumberFieldType
csoulios Dec 20, 2019
4fb0b1c
Merge branch 'master' into rollups
csoulios Jan 3, 2020
7a1f776
Delegate queries to NumberFieldType fields
csoulios Jan 7, 2020
6ae9c1b
Merge branch 'master' into rollups
csoulios Jan 7, 2020
c8390cd
Style fixes
csoulios Jan 7, 2020
1fb227c
Nit: removed blank line
csoulios Jan 10, 2020
8ba840c
Addressed reviewer comments
csoulios Jan 10, 2020
8f10a26
Fixed NPE issue when "metrics" field is missing
csoulios Jan 10, 2020
dee09e3
Added integration test
csoulios Jan 10, 2020
37f1a4a
Merge branch 'master' into rollups
csoulios Jan 10, 2020
8528f29
Override AggregateDoubleMetricFieldMapper methods
csoulios Jan 13, 2020
0de6269
Merge branch 'feature/aggregate-metrics' into rollups
csoulios Jan 16, 2020
c8849c2
Ensure that a metric field cannot be an array
csoulios Jan 16, 2020
02d53db
Ensure that merging two fields with different
csoulios Jan 16, 2020
f732059
Merge branch 'master' into rollups
csoulios Feb 17, 2020
86a5e6b
Merge branch 'master' into rollups
csoulios Feb 18, 2020
44652c0
Checkstyle
csoulios Feb 18, 2020
de72c40
Fix typo
csoulios Feb 18, 2020
031cd01
Merge branch 'feature/aggregate-metrics' into rollups
csoulios Mar 27, 2020
866a0e1
Applied "spotless"
csoulios Mar 27, 2020
1984398
Fixed broken doc-test after merge
csoulios Mar 27, 2020
dc86339
Added test for nested aggregate_metric field
csoulios Mar 30, 2020
b5e3322
Merge branch 'feature/aggregate-metrics' into rollups
csoulios Mar 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/reference/rest-api/info.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Example response:
"available" : true,
"enabled" : true
},
"aggregate_metric" : {
"available" : true,
"enabled" : true
},
"analytics" : {
"available" : true,
"enabled" : true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.xpack.ccr.CCRInfoTransportAction;
import org.elasticsearch.xpack.core.action.XPackInfoAction;
import org.elasticsearch.xpack.core.action.XPackUsageAction;
import org.elasticsearch.xpack.core.aggregatemetric.AggregateMetricFeatureSetUsage;
import org.elasticsearch.xpack.core.analytics.AnalyticsFeatureSetUsage;
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata;
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
Expand Down Expand Up @@ -490,8 +491,11 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FROZEN_INDICES, FrozenIndicesFeatureSetUsage::new),
// Spatial
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.SPATIAL, SpatialFeatureSetUsage::new),
// data science
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.ANALYTICS, AnalyticsFeatureSetUsage::new)
// Analytics
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.ANALYTICS, AnalyticsFeatureSetUsage::new),
// Aggregate metric field type
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class,
XPackField.AGGREGATE_METRIC, AggregateMetricFeatureSetUsage::new)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public final class XPackField {
public static final String ANALYTICS = "analytics";
/** Name constant for the enrich plugin. */
public static final String ENRICH = "enrich";
/** Name constant for the aggregate_metric plugin. */
public static final String AGGREGATE_METRIC = "aggregate_metric";

private XPackField() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public class XPackInfoFeatureAction extends ActionType<XPackInfoFeatureResponse>
public static final XPackInfoFeatureAction SPATIAL = new XPackInfoFeatureAction(XPackField.SPATIAL);
public static final XPackInfoFeatureAction ANALYTICS = new XPackInfoFeatureAction(XPackField.ANALYTICS);
public static final XPackInfoFeatureAction ENRICH = new XPackInfoFeatureAction(XPackField.ENRICH);
public static final XPackInfoFeatureAction AGGREGATE_METRIC = new XPackInfoFeatureAction(XPackField.AGGREGATE_METRIC);

public static final List<XPackInfoFeatureAction> ALL = Arrays.asList(
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, EQL, SQL, ROLLUP, INDEX_LIFECYCLE, SNAPSHOT_LIFECYCLE, CCR,
TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS, ENRICH
TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS, ENRICH, AGGREGATE_METRIC
);

private XPackInfoFeatureAction(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public class XPackUsageFeatureAction extends ActionType<XPackUsageFeatureRespons
public static final XPackUsageFeatureAction FROZEN_INDICES = new XPackUsageFeatureAction(XPackField.FROZEN_INDICES);
public static final XPackUsageFeatureAction SPATIAL = new XPackUsageFeatureAction(XPackField.SPATIAL);
public static final XPackUsageFeatureAction ANALYTICS = new XPackUsageFeatureAction(XPackField.ANALYTICS);
public static final XPackUsageFeatureAction AGGREGATE_METRIC = new XPackUsageFeatureAction(XPackField.AGGREGATE_METRIC);

public static final List<XPackUsageFeatureAction> ALL = Arrays.asList(
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, EQL, SQL, ROLLUP, INDEX_LIFECYCLE, SNAPSHOT_LIFECYCLE, CCR,
TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS
TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS, AGGREGATE_METRIC
);

private XPackUsageFeatureAction(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.aggregatemetric;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;

import java.io.IOException;
import java.util.Objects;

public class AggregateMetricFeatureSetUsage extends XPackFeatureSet.Usage {

public AggregateMetricFeatureSetUsage(StreamInput input) throws IOException {
super(input);
}

public AggregateMetricFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.AGGREGATE_METRIC, available, enabled);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AggregateMetricFeatureSetUsage other = (AggregateMetricFeatureSetUsage) obj;
return Objects.equals(available, other.available) &&
Objects.equals(enabled, other.enabled);
}

@Override
public int hashCode() {
return Objects.hash(available, enabled);
}
}
24 changes: 24 additions & 0 deletions x-pack/plugin/mapper-aggregate-metric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

evaluationDependsOn(xpackModule('core'))

apply plugin: 'elasticsearch.esplugin'

esplugin {
name 'x-pack-aggregate-metric'
description 'Module for the aggregate_metric field type, which allows pre-aggregated fields to be stored a single field.'
classname 'org.elasticsearch.xpack.aggregatemetric.AggregateMetricMapperPlugin'
extendedPlugins = ['x-pack-core']
}
archivesBaseName = 'x-pack-aggregate-metric'

dependencies {
compileOnly project(path: xpackModule('core'), configuration: 'default')
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
}

integTest.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.aggregatemetric;

import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction;

public class AggregateMetricInfoTransportAction extends XPackInfoFeatureTransportAction {

@Inject
public AggregateMetricInfoTransportAction(
TransportService transportService,
ActionFilters actionFilters,
Settings settings,
XPackLicenseState licenseState
) {
super(XPackInfoFeatureAction.AGGREGATE_METRIC.name(), transportService, actionFilters);
}

@Override
public String name() {
return XPackField.AGGREGATE_METRIC;
}

@Override
public boolean available() {
return true;
}

@Override
public boolean enabled() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.aggregatemetric;

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.aggregatemetric.mapper.AggregateDoubleMetricFieldMapper;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonMap;

public class AggregateMetricMapperPlugin extends Plugin implements MapperPlugin, ActionPlugin {

@Override
public Map<String, Mapper.TypeParser> getMappers() {
return singletonMap(AggregateDoubleMetricFieldMapper.CONTENT_TYPE, new AggregateDoubleMetricFieldMapper.TypeParser());
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
new ActionHandler<>(XPackUsageFeatureAction.AGGREGATE_METRIC, AggregateMetricUsageTransportAction.class),
new ActionHandler<>(XPackInfoFeatureAction.AGGREGATE_METRIC, AggregateMetricInfoTransportAction.class)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.aggregatemetric;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureTransportAction;
import org.elasticsearch.xpack.core.aggregatemetric.AggregateMetricFeatureSetUsage;

public class AggregateMetricUsageTransportAction extends XPackUsageFeatureTransportAction {

@Inject
public AggregateMetricUsageTransportAction(
TransportService transportService,
ClusterService clusterService,
ThreadPool threadPool,
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
Settings settings,
XPackLicenseState licenseState
) {
super(
XPackUsageFeatureAction.AGGREGATE_METRIC.name(),
transportService,
clusterService,
threadPool,
actionFilters,
indexNameExpressionResolver
);
}

@Override
protected void masterOperation(
Task task,
XPackUsageRequest request,
ClusterState state,
ActionListener<XPackUsageFeatureResponse> listener
) {
AggregateMetricFeatureSetUsage usage = new AggregateMetricFeatureSetUsage(true, true);
listener.onResponse(new XPackUsageFeatureResponse(usage));
}
}
Loading