-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-52166] [SDP] Add support for PipelineEvents #50906
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aa82378
scaffolding
jon-mio 0f5d4ea
test pass
jon-mio f6c62aa
fmt
jon-mio 0c5311e
Merge branch 'master' into include_event_classes
jon-mio 369fe32
add ci
jon-mio a78ce94
remove core module
jon-mio e71c16c
fix
jon-mio b9c561b
pr comments
jon-mio 236101d
small fixes
jon-mio f2b2821
pr comment
jon-mio 349c704
comment
jon-mio 3ceafd2
fix doc
jon-mio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
53 changes: 53 additions & 0 deletions
53
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/common/GraphStates.scala
This file contains hidden or 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,53 @@ | ||
/* | ||
* 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.spark.sql.pipelines.common | ||
|
||
// The status of the flow. | ||
sealed trait FlowStatus | ||
object FlowStatus { | ||
// Flow is queued and will be started after all its dependencies have been updated. | ||
case object QUEUED extends FlowStatus | ||
// Flow is in the process of starting. | ||
case object STARTING extends FlowStatus | ||
// A task is currently running an update for this flow. | ||
case object RUNNING extends FlowStatus | ||
// This flow's update has completed successfully. | ||
case object COMPLETED extends FlowStatus | ||
// This flow's update has failed. Additional information about the failure is present in the error | ||
// field. | ||
case object FAILED extends FlowStatus | ||
// This flow's update was skipped because an upstream dependency failed. | ||
case object SKIPPED extends FlowStatus | ||
// This flow's query was stopped or canceled by a user action. | ||
case object STOPPED extends FlowStatus | ||
// Flow is in the process of planning. | ||
case object PLANNING extends FlowStatus | ||
// This flow is excluded if it's not selected in the partial graph update API call. | ||
case object EXCLUDED extends FlowStatus | ||
// This flow is idle because there are no updates to be made because all available data has | ||
// already been processed. | ||
case object IDLE extends FlowStatus | ||
} | ||
|
||
// The type of the dataset. | ||
sealed trait DatasetType | ||
object DatasetType { | ||
// Dataset is a materialized view. | ||
case object MATERIALIZED_VIEW extends DatasetType | ||
// Dataset is a streaming table. | ||
case object STREAMING_TABLE extends DatasetType | ||
} |
88 changes: 88 additions & 0 deletions
88
...elines/src/main/scala/org/apache/spark/sql/pipelines/logging/ConstructPipelineEvent.scala
This file contains hidden or 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,88 @@ | ||
/* | ||
* 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.spark.sql.pipelines.logging | ||
|
||
import java.sql.Timestamp | ||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
/** | ||
* A factory object that is used to construct [[PipelineEvent]]s with common fields | ||
* automatically filled in. Developers should always use this factory rather than construct | ||
* an event directly from an empty proto. | ||
*/ | ||
object ConstructPipelineEvent { | ||
|
||
/** | ||
* Converts an exception that was thrown during a pipeline run to a more structured and standard | ||
* internal representation. | ||
*/ | ||
private[pipelines] def serializeException(t: Throwable): Seq[SerializedException] = { | ||
val className = t.getClass.getName | ||
val stacks = Option(t.getStackTrace).map(_.toSeq).getOrElse(Nil).map { f => | ||
StackFrame(declaringClass = f.getClassName, methodName = f.getMethodName) | ||
} | ||
SerializedException(className = className, message = t.getMessage, stack = stacks) +: | ||
Option(t.getCause).map(serializeException).getOrElse(Nil) | ||
} | ||
|
||
def constructErrorDetails(t: Throwable): ErrorDetail = ErrorDetail(serializeException(t)) | ||
|
||
/** | ||
* Returns a new event with the current or provided timestamp and the given origin/message. | ||
*/ | ||
def apply( | ||
origin: PipelineEventOrigin, | ||
message: String, | ||
details: EventDetails, | ||
exception: Throwable = null, | ||
eventTimestamp: Option[Timestamp] = None | ||
): PipelineEvent = { | ||
ConstructPipelineEvent( | ||
origin = origin, | ||
message = message, | ||
details = details, | ||
errorDetails = Option(exception).map(constructErrorDetails), | ||
eventTimestamp = eventTimestamp | ||
) | ||
} | ||
|
||
/** | ||
* Returns a new event with the current or given timestamp and the given origin / message. | ||
*/ | ||
def apply( | ||
origin: PipelineEventOrigin, | ||
message: String, | ||
details: EventDetails, | ||
errorDetails: Option[ErrorDetail], | ||
eventTimestamp: Option[Timestamp] | ||
): PipelineEvent = synchronized { | ||
|
||
val eventUUID = UUID.randomUUID() | ||
val timestamp = Timestamp.from(Instant.now()) | ||
|
||
PipelineEvent( | ||
id = eventUUID.toString, | ||
timestamp = EventHelpers.formatTimestamp(eventTimestamp.getOrElse(timestamp)), | ||
message = message, | ||
details = details, | ||
error = errorDetails, | ||
origin = origin | ||
) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/logging/EventHelpers.scala
This file contains hidden or 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,52 @@ | ||
/* | ||
* 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.spark.sql.pipelines.logging | ||
|
||
import java.sql.Timestamp | ||
import java.time.{Instant, ZoneId} | ||
import java.time.format.DateTimeFormatter | ||
|
||
/** Contains helpers and implicits for working with [[PipelineEvent]]s. */ | ||
object EventHelpers { | ||
|
||
/** A format string that defines how timestamps are serialized in a [[PipelineEvent]]. */ | ||
private val timestampFormat: String = "yyyy-MM-dd'T'HH:mm:ss.SSSXX" | ||
// Currently only the UTC timezone is supported. Eventually we want to allow the user to specify | ||
// the timezone as a pipeline level setting using the SESSION_LOCAL_TIMEZONE key, and it should | ||
// not be possible to change this setting during a pipeline run. | ||
private val zoneId: ZoneId = ZoneId.of("UTC") | ||
|
||
private val formatter: DateTimeFormatter = DateTimeFormatter | ||
.ofPattern(timestampFormat) | ||
.withZone(zoneId) | ||
|
||
/** Converts a timestamp to a string in ISO 8601 format. */ | ||
def formatTimestamp(ts: Timestamp): String = { | ||
val instant = Instant.ofEpochMilli(ts.getTime) | ||
formatter.format(instant) | ||
} | ||
|
||
/** Converts an ISO 8601 formatted timestamp to a {@link java.sql.Timestamp}. */ | ||
def parseTimestamp(timeString: String): Timestamp = { | ||
if (timeString.isEmpty) { | ||
new Timestamp(0L) | ||
} else { | ||
val instant = Instant.from(formatter.parse(timeString)) | ||
new Timestamp(instant.toEpochMilli) | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/logging/PipelineEvent.scala
This file contains hidden or 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,80 @@ | ||
/* | ||
* 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.spark.sql.pipelines.logging | ||
|
||
import org.apache.spark.sql.pipelines.common.FlowStatus | ||
|
||
/** | ||
* An internal event that is emitted during the run of a pipeline. | ||
* @param id A globally unique id | ||
* @param timestamp The time of the event | ||
* @param origin Where the event originated from | ||
* @param message A user friendly description of the event | ||
* @param details The details of the event | ||
* @param error An error that occurred during the event | ||
*/ | ||
case class PipelineEvent( | ||
id: String, | ||
timestamp: String, | ||
origin: PipelineEventOrigin, | ||
message: String, | ||
details: EventDetails, | ||
error: Option[ErrorDetail] | ||
) | ||
|
||
/** | ||
* Describes where the event originated from | ||
* @param datasetName The name of the dataset | ||
* @param flowName The name of the flow | ||
* @param sourceCodeLocation The location of the source code | ||
*/ | ||
case class PipelineEventOrigin( | ||
datasetName: Option[String], | ||
flowName: Option[String], | ||
sourceCodeLocation: Option[SourceCodeLocation] | ||
) | ||
|
||
/** | ||
* Describes the location of the source code | ||
* @param path The path to the source code | ||
* @param lineNumber The line number of the source code | ||
* @param columnNumber The column number of the source code | ||
* @param endingLineNumber The ending line number of the source code | ||
* @param endingColumnNumber The ending column number of the source code | ||
*/ | ||
case class SourceCodeLocation( | ||
path: Option[String], | ||
lineNumber: Option[Int], | ||
columnNumber: Option[Int], | ||
endingLineNumber: Option[Int], | ||
endingColumnNumber: Option[Int] | ||
) | ||
|
||
// Additional details about the PipelineEvent | ||
trait EventDetails | ||
|
||
// An event indicating that a flow has made progress and transitioned to a different state | ||
case class FlowProgress(status: FlowStatus) extends EventDetails | ||
|
||
// Additional details about the error that occurred during the event | ||
case class ErrorDetail(exceptions: Seq[SerializedException]) | ||
|
||
// An exception that was thrown during a pipeline run | ||
case class SerializedException(className: String, message: String, stack: Seq[StackFrame]) | ||
jonmio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// A stack frame of an exception | ||
case class StackFrame(declaringClass: String, methodName: String) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed