Skip to content

Commit fd7cadc

Browse files
author
Hendrik Muhs
committed
remove extra constructor and always calculate exponential averages
1 parent e57690a commit fd7cadc

File tree

6 files changed

+36
-61
lines changed

6 files changed

+36
-61
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformIndexerStats.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,35 +125,6 @@ public TransformIndexerStats(
125125
this.expAvgDocumentsProcessed = expAvgDocumentsProcessed == null ? 0.0 : expAvgDocumentsProcessed;
126126
}
127127

128-
public TransformIndexerStats(
129-
long numPages,
130-
long numInputDocuments,
131-
long numOutputDocuments,
132-
long numInvocations,
133-
long indexTime,
134-
long searchTime,
135-
long indexTotal,
136-
long searchTotal,
137-
long indexFailures,
138-
long searchFailures
139-
) {
140-
this(
141-
numPages,
142-
numInputDocuments,
143-
numOutputDocuments,
144-
numInvocations,
145-
indexTime,
146-
searchTime,
147-
indexTotal,
148-
searchTotal,
149-
indexFailures,
150-
searchFailures,
151-
0.0,
152-
0.0,
153-
0.0
154-
);
155-
}
156-
157128
public TransformIndexerStats(TransformIndexerStats other) {
158129
this(
159130
other.numPages,
@@ -165,11 +136,11 @@ public TransformIndexerStats(TransformIndexerStats other) {
165136
other.indexTotal,
166137
other.searchTotal,
167138
other.indexFailures,
168-
other.searchFailures
139+
other.searchFailures,
140+
other.expAvgCheckpointDurationMs,
141+
other.expAvgDocumentsIndexed,
142+
other.expAvgDocumentsProcessed
169143
);
170-
this.expAvgCheckpointDurationMs = other.expAvgCheckpointDurationMs;
171-
this.expAvgDocumentsIndexed = other.expAvgDocumentsIndexed;
172-
this.expAvgDocumentsProcessed = other.expAvgDocumentsProcessed;
173144
}
174145

175146
public TransformIndexerStats(StreamInput in) throws IOException {
@@ -295,6 +266,11 @@ public int hashCode() {
295266
);
296267
}
297268

269+
@Override
270+
public String toString() {
271+
return Strings.toString(this);
272+
}
273+
298274
public static TransformIndexerStats fromXContent(XContentParser parser) {
299275
try {
300276
return LENIENT_PARSER.parse(parser, null);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformIndexerStatsTests.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@
66

77
package org.elasticsearch.xpack.core.transform.transforms;
88

9-
import org.elasticsearch.common.bytes.BytesReference;
109
import org.elasticsearch.common.io.stream.Writeable;
11-
import org.elasticsearch.common.xcontent.ToXContent;
12-
import org.elasticsearch.common.xcontent.XContentBuilder;
13-
import org.elasticsearch.common.xcontent.XContentFactory;
14-
import org.elasticsearch.common.xcontent.XContentHelper;
1510
import org.elasticsearch.common.xcontent.XContentParser;
16-
import org.elasticsearch.common.xcontent.XContentType;
1711
import org.elasticsearch.test.AbstractSerializingTestCase;
1812

19-
import java.io.IOException;
20-
import java.util.Map;
21-
2213
import static org.hamcrest.Matchers.closeTo;
2314
import static org.hamcrest.Matchers.equalTo;
2415

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformStatsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testBwcWith73() throws IOException {
6969
STARTED,
7070
randomBoolean() ? null : randomAlphaOfLength(100),
7171
randomBoolean() ? null : NodeAttributeTests.randomNodeAttributes(),
72-
new TransformIndexerStats(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
72+
new TransformIndexerStats(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.0, 12.0, 13.0),
7373
new TransformCheckpointingInfo(
7474
new TransformCheckpointStats(0, null, null, 10, 100),
7575
new TransformCheckpointStats(0, null, null, 100, 1000),

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformInfoTransportAction.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class TransformInfoTransportAction extends XPackInfoFeatureTransportActio
5656
TransformIndexerStats.SEARCH_TOTAL.getPreferredName(),
5757
TransformIndexerStats.INDEX_FAILURES.getPreferredName(),
5858
TransformIndexerStats.SEARCH_FAILURES.getPreferredName(),
59+
TransformIndexerStats.EXPONENTIAL_AVG_CHECKPOINT_DURATION_MS.getPreferredName(),
60+
TransformIndexerStats.EXPONENTIAL_AVG_DOCUMENTS_INDEXED.getPreferredName(),
61+
TransformIndexerStats.EXPONENTIAL_AVG_DOCUMENTS_PROCESSED.getPreferredName(),
5962
};
6063

6164
@Inject
@@ -82,27 +85,30 @@ public boolean enabled() {
8285
}
8386

8487
static TransformIndexerStats parseSearchAggs(SearchResponse searchResponse) {
85-
List<Long> statisticsList = new ArrayList<>(PROVIDED_STATS.length);
88+
List<Double> statisticsList = new ArrayList<>(PROVIDED_STATS.length);
8689

8790
for(String statName : PROVIDED_STATS) {
8891
Aggregation agg = searchResponse.getAggregations().get(statName);
8992

9093
if (agg instanceof NumericMetricsAggregation.SingleValue) {
91-
statisticsList.add((long)((NumericMetricsAggregation.SingleValue)agg).value());
94+
statisticsList.add(((NumericMetricsAggregation.SingleValue)agg).value());
9295
} else {
93-
statisticsList.add(0L);
96+
statisticsList.add(0.0);
9497
}
9598
}
96-
return new TransformIndexerStats(statisticsList.get(0), // numPages
97-
statisticsList.get(1), // numInputDocuments
98-
statisticsList.get(2), // numOutputDocuments
99-
statisticsList.get(3), // numInvocations
100-
statisticsList.get(4), // indexTime
101-
statisticsList.get(5), // searchTime
102-
statisticsList.get(6), // indexTotal
103-
statisticsList.get(7), // searchTotal
104-
statisticsList.get(8), // indexFailures
105-
statisticsList.get(9)); // searchFailures
99+
return new TransformIndexerStats(statisticsList.get(0).longValue(), // numPages
100+
statisticsList.get(1).longValue(), // numInputDocuments
101+
statisticsList.get(2).longValue(), // numOutputDocuments
102+
statisticsList.get(3).longValue(), // numInvocations
103+
statisticsList.get(4).longValue(), // indexTime
104+
statisticsList.get(5).longValue(), // searchTime
105+
statisticsList.get(6).longValue(), // indexTotal
106+
statisticsList.get(7).longValue(), // searchTotal
107+
statisticsList.get(8).longValue(), // indexFailures
108+
statisticsList.get(9).longValue(), // searchFailures
109+
statisticsList.get(10), // exponential_avg_checkpoint_duration_ms
110+
statisticsList.get(11), // exponential_avg_documents_indexed
111+
statisticsList.get(12)); // exponential_avg_documents_processed
106112
}
107113

108114
static void getStatisticSummations(Client client, ActionListener<TransformIndexerStats> statsListener) {

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformIndexer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ protected void onFinish(ActionListener<Void> listener) {
361361
if (progress != null && progress.getPercentComplete() != null && progress.getPercentComplete() < 100.0) {
362362
progress.incrementDocsProcessed(progress.getTotalDocs() - progress.getDocumentsProcessed());
363363
}
364-
// If the last checkpoint is now greater than 1, that means that we have just processed the first
365-
// continuous checkpoint and should start recording the exponential averages
366-
if (lastCheckpoint != null && lastCheckpoint.getCheckpoint() > 1) {
364+
365+
if (lastCheckpoint != null) {
367366
long docsIndexed = 0;
368367
long docsProcessed = 0;
369368
// This should not happen as we simply create a new one when we reach continuous checkpoints

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ public void testParseSearchAggs() {
9090
7, // indexTotal
9191
8, // searchTotal
9292
9, // indexFailures
93-
10); // searchFailures
93+
10, // searchFailures
94+
11.0, // exponential_avg_checkpoint_duration_ms
95+
12.0, // exponential_avg_documents_indexed
96+
13.0); // exponential_avg_documents_processed
9497

9598
int currentStat = 1;
9699
List<Aggregation> aggs = new ArrayList<>(PROVIDED_STATS.length);
97100
for (String statName : PROVIDED_STATS) {
98-
aggs.add(buildAgg(statName, (double) currentStat++));
101+
aggs.add(buildAgg(statName, currentStat++));
99102
}
100103
Aggregations aggregations = new Aggregations(aggs);
101104
SearchResponse withAggs = mock(SearchResponse.class);

0 commit comments

Comments
 (0)