forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x][ML] Improve progress reportings for DF analytics (elastic#45856)
Previously, the stats API reports a progress percentage for DF analytics tasks that are running and are in the `reindexing` or `analyzing` state. This means that when the task is `stopped` there is no progress reported. Thus, one cannot distinguish between a task that never run to one that completed. In addition, there are blind spots in the progress reporting. In particular, we do not account for when data is loaded into the process. We also do not account for when results are written. This commit addresses the above issues. It changes progress to being a list of objects, each one describing the phase and its progress as a percentage. We currently have 4 phases: reindexing, loading_data, analyzing, writing_results. When the task stops, progress is persisted as a document in the state index. The stats API now reports progress from in-memory if the task is running, or returns the persisted document (if there is one).
- Loading branch information
1 parent
3bc1494
commit 12162f5
Showing
27 changed files
with
989 additions
and
129 deletions.
There are no files selected for viewing
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
91 changes: 91 additions & 0 deletions
91
...nt/rest-high-level/src/main/java/org/elasticsearch/client/ml/dataframe/PhaseProgress.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,91 @@ | ||
/* | ||
* 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.ml.dataframe; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.inject.internal.ToStringBuilder; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A class that describes a phase and its progress as a percentage | ||
*/ | ||
public class PhaseProgress implements ToXContentObject { | ||
|
||
static final ParseField PHASE = new ParseField("phase"); | ||
static final ParseField PROGRESS_PERCENT = new ParseField("progress_percent"); | ||
|
||
public static final ConstructingObjectParser<PhaseProgress, Void> PARSER = new ConstructingObjectParser<>("phase_progress", | ||
true, a -> new PhaseProgress((String) a[0], (int) a[1])); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), PHASE); | ||
PARSER.declareInt(ConstructingObjectParser.constructorArg(), PROGRESS_PERCENT); | ||
} | ||
|
||
private final String phase; | ||
private final int progressPercent; | ||
|
||
public PhaseProgress(String phase, int progressPercent) { | ||
this.phase = Objects.requireNonNull(phase); | ||
this.progressPercent = progressPercent; | ||
} | ||
|
||
public String getPhase() { | ||
return phase; | ||
} | ||
|
||
public int getProgressPercent() { | ||
return progressPercent; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(phase, progressPercent); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PhaseProgress that = (PhaseProgress) o; | ||
return Objects.equals(phase, that.phase) && progressPercent == that.progressPercent; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(getClass()) | ||
.add(PHASE.getPreferredName(), phase) | ||
.add(PROGRESS_PERCENT.getPreferredName(), progressPercent) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(PhaseProgress.PHASE.getPreferredName(), phase); | ||
builder.field(PhaseProgress.PROGRESS_PERCENT.getPreferredName(), progressPercent); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
...st-high-level/src/test/java/org/elasticsearch/client/ml/dataframe/PhaseProgressTests.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,46 @@ | ||
/* | ||
* 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.ml.dataframe; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractXContentTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class PhaseProgressTests extends AbstractXContentTestCase<PhaseProgress> { | ||
|
||
public static PhaseProgress createRandom() { | ||
return new PhaseProgress(randomAlphaOfLength(20), randomIntBetween(0, 100)); | ||
} | ||
|
||
@Override | ||
protected PhaseProgress createTestInstance() { | ||
return createRandom(); | ||
} | ||
|
||
@Override | ||
protected PhaseProgress doParseInstance(XContentParser parser) throws IOException { | ||
return PhaseProgress.PARSER.apply(parser, null); | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return true; | ||
} | ||
} |
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.