-
Notifications
You must be signed in to change notification settings - Fork 526
Don't fail on saveMetrics and saveLineage #5718
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
79fe037
8021bdc
ee6b179
92a474e
0ed0cbf
8a6dd18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ import org.apache.beam.sdk.io.fs.{ResolveOptions, ResourceId} | |
| import org.apache.beam.sdk.metrics.{DistributionResult, GaugeResult, Lineage} | ||
| import org.apache.beam.sdk.util.MimeTypes | ||
| import org.apache.beam.sdk.{metrics => beam, PipelineResult} | ||
|
|
||
| import org.joda.time.Instant | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| import java.io.File | ||
| import java.nio.ByteBuffer | ||
|
|
@@ -46,6 +46,7 @@ trait RunnerResult { | |
|
|
||
| /** Represent a Scio pipeline result. */ | ||
| abstract class ScioResult private[scio] (val internal: PipelineResult) { | ||
| private val logger = LoggerFactory.getLogger(this.getClass) | ||
|
shnapz marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** Get a Beam runner specific result. */ | ||
| def as[T <: RunnerResult: ClassTag]: T = { | ||
|
|
@@ -74,6 +75,7 @@ abstract class ScioResult private[scio] (val internal: PipelineResult) { | |
| val isDirectory = path.endsWith(File.separator) | ||
| saveJsonFile( | ||
| getResourceId(path, enforceNewFile = isDirectory, newFilePrefix = "metrics"), | ||
| path, | ||
| getMetrics | ||
| ) | ||
| } | ||
|
|
@@ -83,6 +85,7 @@ abstract class ScioResult private[scio] (val internal: PipelineResult) { | |
| val isDirectory = path.endsWith(File.separator) | ||
| saveJsonFile( | ||
| getResourceId(path, enforceNewFile = isDirectory, newFilePrefix = "lineage"), | ||
| path, | ||
| getBeamLineage | ||
| ) | ||
| } | ||
|
|
@@ -102,18 +105,28 @@ abstract class ScioResult private[scio] (val internal: PipelineResult) { | |
| } | ||
| } | ||
|
|
||
| private def saveJsonFile(resourceId: ResourceId, value: Object): Unit = { | ||
| private def saveJsonFile(resourceId: => ResourceId, path: String, value: Object): Unit = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, where is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the problem is that creation of resourceId can fail if bucket does not exist
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's ok; if we do: logger.info(f"Saved metrics to '$resourceId'")
} catch {
case e: Throwable =>
logger.warn(
f"Failed to save metrics: ${mapper.writeValueAsString(value)}",
e
)in the success case, the resourceID exists so it's safe to log, and in the failure case, the error msg would include the path anyway, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I re-tested it and resourceID is safely created even if bucket does not exist! So I have updated the code and replaced path with resourceId! |
||
| val mapper = ScioUtil.getScalaJsonMapper | ||
| val out = FileSystems.create(resourceId, MimeTypes.TEXT) | ||
| try { | ||
| out.write(ByteBuffer.wrap(mapper.writeValueAsBytes(value))) | ||
| } finally { | ||
| if (out != null) { | ||
| out.close() | ||
| val out = FileSystems.create(resourceId, MimeTypes.TEXT) | ||
| try { | ||
| out.write(ByteBuffer.wrap(mapper.writeValueAsBytes(value))) | ||
| } finally { | ||
| if (out != null) { | ||
| out.close() | ||
| } | ||
| } | ||
| logger.info(f"Saved metrics to '$path'") | ||
| } catch { | ||
| case e: Throwable => | ||
| logger.warn( | ||
| f"Failed to save metrics to '$path': ${mapper.writeValueAsString(value)}", | ||
| e | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** Get lineage metric values. */ | ||
| def getBeamLineage: BeamLineage = { | ||
| def asScalaCrossCompatible(set: java.util.Set[String]): Iterable[String] = { | ||
| val iterator = set.iterator() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.