LakshSingla commented on code in PR #12918: URL: https://github.com/apache/druid/pull/12918#discussion_r951182759
########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/report/MSQTaskReport.java: ########## @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.druid.msq.indexing.report; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import org.apache.druid.indexing.common.TaskReport; + +@JsonTypeName(MSQTaskReport.REPORT_KEY) +public class MSQTaskReport implements TaskReport Review Comment: For this class, I think we would require a `type` field as well for allowing deserialization in the clients. Reference comment for the same: [IngestionStatsAndErrorsTaskReport#L94](https://github.com/apache/druid/blob/a879d91a2059afb63a29c34577b2009f1c83121f/indexing-service/src/main/java/org/apache/druid/indexing/common/IngestionStatsAndErrorsTaskReport.java#L94). ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/report/MSQStatusReport.java: ########## @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.druid.msq.indexing.report; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; +import org.apache.druid.indexer.TaskState; +import org.apache.druid.msq.indexing.error.MSQErrorReport; +import org.joda.time.DateTime; + +import javax.annotation.Nullable; +import java.util.Queue; + +public class MSQStatusReport +{ + private final TaskState status; + + @Nullable + private final MSQErrorReport errorReport; + + private final Queue<MSQErrorReport> warningReports; + + @Nullable + private final DateTime startTime; + + private final long durationMs; + + + @JsonCreator + public MSQStatusReport( + @JsonProperty("status") TaskState status, + @JsonProperty("error") @Nullable MSQErrorReport errorReport, + @JsonProperty("warnings") Queue<MSQErrorReport> warningReports, + @JsonProperty("startTime") @Nullable DateTime startTime, Review Comment: This is annotated as `Nullable,` however, there is a `Preconditions` check for notNull on the same. ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/report/MSQStagesReport.java: ########## @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.druid.msq.indexing.report; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.google.common.base.Preconditions; +import org.apache.druid.msq.kernel.QueryDefinition; +import org.apache.druid.msq.kernel.StageDefinition; +import org.apache.druid.msq.kernel.controller.ControllerStagePhase; +import org.joda.time.DateTime; +import org.joda.time.Interval; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class MSQStagesReport +{ + private final List<Stage> stages; + + @JsonCreator + public MSQStagesReport(@JsonProperty("stages") final List<Stage> stages) + { + this.stages = Preconditions.checkNotNull(stages, "stages"); + } + + public static MSQStagesReport create( + final QueryDefinition queryDef, + final Map<Integer, ControllerStagePhase> stagePhaseMap, + final Map<Integer, Interval> stageRuntimeMap, + final Map<Integer, Integer> stageWorkerCountMap, + final Map<Integer, Integer> stagePartitionCountMap + ) + { + final List<Stage> stages = new ArrayList<>(); + + final int[] stageNumbers = + queryDef.getStageDefinitions().stream().mapToInt(StageDefinition::getStageNumber).toArray(); + Arrays.sort(stageNumbers); + + for (final int stageNumber : stageNumbers) { + final StageDefinition stageDef = queryDef.getStageDefinition(stageNumber); + + final int workerCount = stageWorkerCountMap.getOrDefault(stageNumber, 0); + final int partitionCount = stagePartitionCountMap.getOrDefault(stageNumber, 0); + final Interval stageRuntimeInterval = stageRuntimeMap.get(stageNumber); + final DateTime stageStartTime = stageRuntimeInterval == null ? null : stageRuntimeInterval.getStart(); + final long stageDuration = stageRuntimeInterval == null ? 0 : stageRuntimeInterval.toDurationMillis(); + + final Stage stage = new Stage( + stageNumber, + stageDef, + stagePhaseMap.get(stageNumber), + workerCount, + partitionCount, + stageStartTime, + stageDuration + ); + stages.add(stage); + } + + return new MSQStagesReport(stages); + } + + @JsonValue Review Comment: Having `JsonValue` here causes the `MSQStagesReport` to be serialized as an array, instead of an object. This is causing a serde error in the `MSQTaskReportPayload.` I wrote a simple test case to verify this: ``` MSQTaskReport msqTaskReport = new MSQTaskReport( "test-id", new MSQTaskReportPayload( new MSQStatusReport( TaskState.RUNNING, null, new ArrayDeque<>(), DateTime.now(), 1 ), new MSQStagesReport(ImmutableList.of()), null, null ) ); String serialized = jsonMapper.writeValueAsString(msqTaskReport); MSQTaskReport deserializEd = jsonMapper.readValue(serialized, MSQTaskReport.class); ``` The above snipped is failing. The msqTaskReport serializes as: ``` ......"stages":[{"stageNumber":0,"definition":{"id":...... ``` instead of ``` ......"stages":{stages:[{"stageNumber":0,"definition":{"id":...... ``` If we change the serialization by converting `JsonValue` to `JsonProperty("stages"`) this should work fine, however, the downstream consumers (web-console) might fail, so we can defer this change post the PR merges. Another option would be to change the deserialization instead in the MSQTaskReportPayload/MSQStagesReport (which I am unsure how to achieve). WDYT? Jackson is not my strong suit so LMK in case I missed any obvious way to achieve serde. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
