-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Adds progress reporting for transforms (#41278)
* [ML] Adds progress reporting for transforms * fixing after master merge * Addressing PR comments * removing unused imports * Adjusting afterKey handling and percentage to be 100* * Making sure it is a linked hashmap for serialization * removing unused import * addressing PR comments * removing unused import * simplifying code, only storing total docs and decrementing * adjusting for rewrite * removing initial progress gathering from executor
- Loading branch information
Showing
28 changed files
with
1,284 additions
and
264 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...c/main/java/org/elasticsearch/client/dataframe/transforms/DataFrameTransformProgress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.dataframe.transforms; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
public class DataFrameTransformProgress { | ||
|
||
public static final ParseField TOTAL_DOCS = new ParseField("total_docs"); | ||
public static final ParseField DOCS_REMAINING = new ParseField("docs_remaining"); | ||
public static final ParseField PERCENT_COMPLETE = new ParseField("percent_complete"); | ||
|
||
public static final ConstructingObjectParser<DataFrameTransformProgress, Void> PARSER = new ConstructingObjectParser<>( | ||
"data_frame_transform_progress", | ||
true, | ||
a -> new DataFrameTransformProgress((Long) a[0], (Long)a[1], (Double)a[2])); | ||
|
||
static { | ||
PARSER.declareLong(constructorArg(), TOTAL_DOCS); | ||
PARSER.declareLong(optionalConstructorArg(), DOCS_REMAINING); | ||
PARSER.declareDouble(optionalConstructorArg(), PERCENT_COMPLETE); | ||
} | ||
|
||
public static DataFrameTransformProgress fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
private final long totalDocs; | ||
private final long remainingDocs; | ||
private final double percentComplete; | ||
|
||
public DataFrameTransformProgress(long totalDocs, Long remainingDocs, double percentComplete) { | ||
this.totalDocs = totalDocs; | ||
this.remainingDocs = remainingDocs == null ? totalDocs : remainingDocs; | ||
this.percentComplete = percentComplete; | ||
} | ||
|
||
public double getPercentComplete() { | ||
return percentComplete; | ||
} | ||
|
||
public long getTotalDocs() { | ||
return totalDocs; | ||
} | ||
|
||
public long getRemainingDocs() { | ||
return remainingDocs; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (other == null || other.getClass() != getClass()) { | ||
return false; | ||
} | ||
|
||
DataFrameTransformProgress that = (DataFrameTransformProgress) other; | ||
return Objects.equals(this.remainingDocs, that.remainingDocs) | ||
&& Objects.equals(this.totalDocs, that.totalDocs) | ||
&& Objects.equals(this.percentComplete, that.percentComplete); | ||
} | ||
|
||
@Override | ||
public int hashCode(){ | ||
return Objects.hash(remainingDocs, totalDocs, percentComplete); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...t/java/org/elasticsearch/client/dataframe/transforms/DataFrameTransformProgressTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.dataframe.transforms; | ||
|
||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; | ||
|
||
public class DataFrameTransformProgressTests extends ESTestCase { | ||
|
||
public void testFromXContent() throws IOException { | ||
xContentTester(this::createParser, | ||
DataFrameTransformProgressTests::randomInstance, | ||
DataFrameTransformProgressTests::toXContent, | ||
DataFrameTransformProgress::fromXContent) | ||
.supportsUnknownFields(true) | ||
.randomFieldsExcludeFilter(field -> field.startsWith("state")) | ||
.test(); | ||
} | ||
|
||
public static DataFrameTransformProgress randomInstance() { | ||
long totalDocs = randomNonNegativeLong(); | ||
Long docsRemaining = randomBoolean() ? null : randomLongBetween(0, totalDocs); | ||
double percentComplete = totalDocs == 0 ? 1.0 : docsRemaining == null ? 0.0 : 100.0*(double)(totalDocs - docsRemaining)/totalDocs; | ||
return new DataFrameTransformProgress(totalDocs, docsRemaining, percentComplete); | ||
} | ||
|
||
public static void toXContent(DataFrameTransformProgress progress, XContentBuilder builder) throws IOException { | ||
builder.startObject(); | ||
builder.field(DataFrameTransformProgress.TOTAL_DOCS.getPreferredName(), progress.getTotalDocs()); | ||
builder.field(DataFrameTransformProgress.DOCS_REMAINING.getPreferredName(), progress.getRemainingDocs()); | ||
builder.field(DataFrameTransformProgress.PERCENT_COMPLETE.getPreferredName(), progress.getPercentComplete()); | ||
builder.endObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.