forked from apache/spark
-
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.
[SPARK-24748][SS] Support for reporting custom metrics via StreamingQ…
…uery Progress ## What changes were proposed in this pull request? Currently the Structured Streaming sources and sinks does not have a way to report custom metrics. Providing an option to report custom metrics and making it available via Streaming Query progress can enable sources and sinks to report custom progress information (E.g. the lag metrics for Kafka source). Similar metrics can be reported for Sinks as well, but would like to get initial feedback before proceeding further. ## How was this patch tested? New and existing unit tests. Please review http://spark.apache.org/contributing.html before opening a pull request. Closes apache#21721 from arunmahadevan/SPARK-24748. Authored-by: Arun Mahadevan <[email protected]> Signed-off-by: hyukjinkwon <[email protected]>
- Loading branch information
1 parent
6afe6f3
commit 18b6ec1
Showing
9 changed files
with
306 additions
and
14 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
sql/core/src/main/java/org/apache/spark/sql/sources/v2/CustomMetrics.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,33 @@ | ||
/* | ||
* 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.sources.v2; | ||
|
||
import org.apache.spark.annotation.InterfaceStability; | ||
|
||
/** | ||
* An interface for reporting custom metrics from streaming sources and sinks | ||
*/ | ||
@InterfaceStability.Evolving | ||
public interface CustomMetrics { | ||
/** | ||
* Returns a JSON serialized representation of custom metrics | ||
* | ||
* @return JSON serialized representation of custom metrics | ||
*/ | ||
String json(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...in/java/org/apache/spark/sql/sources/v2/reader/streaming/SupportsCustomReaderMetrics.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,47 @@ | ||
/* | ||
* 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.sources.v2.reader.streaming; | ||
|
||
import org.apache.spark.annotation.InterfaceStability; | ||
import org.apache.spark.sql.sources.v2.CustomMetrics; | ||
import org.apache.spark.sql.sources.v2.reader.DataSourceReader; | ||
|
||
/** | ||
* A mix in interface for {@link DataSourceReader}. Data source readers can implement this | ||
* interface to report custom metrics that gets reported under the | ||
* {@link org.apache.spark.sql.streaming.SourceProgress} | ||
* | ||
*/ | ||
@InterfaceStability.Evolving | ||
public interface SupportsCustomReaderMetrics extends DataSourceReader { | ||
/** | ||
* Returns custom metrics specific to this data source. | ||
*/ | ||
CustomMetrics getCustomMetrics(); | ||
|
||
/** | ||
* Invoked if the custom metrics returned by {@link #getCustomMetrics()} is invalid | ||
* (e.g. Invalid data that cannot be parsed). Throwing an error here would ensure that | ||
* your custom metrics work right and correct values are reported always. The default action | ||
* on invalid metrics is to ignore it. | ||
* | ||
* @param ex the exception | ||
*/ | ||
default void onInvalidMetrics(Exception ex) { | ||
// default is to ignore invalid custom metrics | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...in/java/org/apache/spark/sql/sources/v2/writer/streaming/SupportsCustomWriterMetrics.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,47 @@ | ||
/* | ||
* 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.sources.v2.writer.streaming; | ||
|
||
import org.apache.spark.annotation.InterfaceStability; | ||
import org.apache.spark.sql.sources.v2.CustomMetrics; | ||
import org.apache.spark.sql.sources.v2.writer.DataSourceWriter; | ||
|
||
/** | ||
* A mix in interface for {@link DataSourceWriter}. Data source writers can implement this | ||
* interface to report custom metrics that gets reported under the | ||
* {@link org.apache.spark.sql.streaming.SinkProgress} | ||
* | ||
*/ | ||
@InterfaceStability.Evolving | ||
public interface SupportsCustomWriterMetrics extends DataSourceWriter { | ||
/** | ||
* Returns custom metrics specific to this data source. | ||
*/ | ||
CustomMetrics getCustomMetrics(); | ||
|
||
/** | ||
* Invoked if the custom metrics returned by {@link #getCustomMetrics()} is invalid | ||
* (e.g. Invalid data that cannot be parsed). Throwing an error here would ensure that | ||
* your custom metrics work right and correct values are reported always. The default action | ||
* on invalid metrics is to ignore it. | ||
* | ||
* @param ex the exception | ||
*/ | ||
default void onInvalidMetrics(Exception ex) { | ||
// default is to ignore invalid custom metrics | ||
} | ||
} |
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
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.