I'm trying to add logging to my pyspark structured streaming application in order see the progress and statistics about each micro-batch processed. The writestream method uses a foreach writer to write the rows from the dataframe to a postgres database. I'm using .lastProgress and other standard metrics offered by pyspark for logging. The writestream method and my attempt to log are shown below.
query_1 = eventsDF \
.writeStream \
.foreach(writer) \
.outputMode("append") \
.option("checkpointLocation", "/tmp/checkpoint_a/") \
.trigger(processingTime="5 seconds") \
.start()
query_progress = query_1.lastProgress
print("progress ", query_progress)
print("status ", query_1.status)
print("active ", query_1.isActive)
query_1.awaitTermination()
The results from my first loop are:
progress None
status {'message': 'Initializing sources', 'isDataAvailable': False, 'isTriggerActive': False}
active True
However, further batches processed as event data arrives do not result in any more logging messages. I would expect that the logging messages would be emitted after each micro-batch processed in the streaming job.
I appreciate any advice or guidance. Thanks.