为什么 Stackdriver 日志中会间歇性出现空行?
Why do empty lines appear intermittently in Stackdriver logs?
我每分钟 运行 一个云函数。
Stackdriver 日志中间歇性出现空白行(请参阅下面的日志)。
我不相信这是因为我写的功能代码。
可以用这个 main.py 重新创建错误:
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info(f"Logging {__name__}")
def main(event, context):
logger.info("Message 1")
logger.info("Message 2")
logger.info("Message 3")
当 Cloud Scheduler 每分钟触发一次时,此函数会在几个小时内发出空白行。
如何预防这个问题?
更新:添加了两个扩展日志
{
insertId: "000001-redacted-but-identical"
labels: {
execution_id: "894004659398898"
}
logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2019-12-13T23:05:01.545007423Z"
resource: {
labels: {
function_name: "recreate_blank_lines"
project_id: "redacted"
region: "us-central1"
}
type: "cloud_function"
}
severity: "INFO"
timestamp: "2019-12-13T23:05:00.344Z"
trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"
}
{
insertId: "000000-redacted-but-identical"
labels: {
execution_id: "894004659398898"
}
logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2019-12-13T23:05:01.545007423Z"
resource: {
labels: {
function_name: "recreate_blank_lines"
project_id: "redacted"
region: "us-central1"
}
type: "cloud_function"
}
severity: "INFO"
textPayload: "Message 2"
timestamp: "2019-12-13T23:05:00.345Z"
trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"
同时,您可以向 stackdriver 添加过滤器以跳过包含空字符串的日志。
一种可能是您的代码 - 或您导入的库 - print()
是 stdout 或 stderr 的空行,如 this is also soent to logs。
从 2020 年 2 月 3 日开始,这个问题对我们来说似乎已经消失了 13:44:20.476 PST
来自 issuetracker.google.com
的支持工程师
It seems like stackdriver is logging twice with one of the two logs
having empty textpayload.
I also learnt that stackdriver will update their log delivery
mechanism in Q1 2020, which will likely address this problem.
I will leave this isuee tracker as is for now. You will be notified
when the issue is fixed in Q1 2020.
我每分钟 运行 一个云函数。
Stackdriver 日志中间歇性出现空白行(请参阅下面的日志)。
我不相信这是因为我写的功能代码。
可以用这个 main.py 重新创建错误:
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info(f"Logging {__name__}")
def main(event, context):
logger.info("Message 1")
logger.info("Message 2")
logger.info("Message 3")
当 Cloud Scheduler 每分钟触发一次时,此函数会在几个小时内发出空白行。
如何预防这个问题?
更新:添加了两个扩展日志
{
insertId: "000001-redacted-but-identical"
labels: {
execution_id: "894004659398898"
}
logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2019-12-13T23:05:01.545007423Z"
resource: {
labels: {
function_name: "recreate_blank_lines"
project_id: "redacted"
region: "us-central1"
}
type: "cloud_function"
}
severity: "INFO"
timestamp: "2019-12-13T23:05:00.344Z"
trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"
}
{
insertId: "000000-redacted-but-identical"
labels: {
execution_id: "894004659398898"
}
logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2019-12-13T23:05:01.545007423Z"
resource: {
labels: {
function_name: "recreate_blank_lines"
project_id: "redacted"
region: "us-central1"
}
type: "cloud_function"
}
severity: "INFO"
textPayload: "Message 2"
timestamp: "2019-12-13T23:05:00.345Z"
trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"
同时,您可以向 stackdriver 添加过滤器以跳过包含空字符串的日志。
一种可能是您的代码 - 或您导入的库 - print()
是 stdout 或 stderr 的空行,如 this is also soent to logs。
从 2020 年 2 月 3 日开始,这个问题对我们来说似乎已经消失了 13:44:20.476 PST
来自 issuetracker.google.com
的支持工程师It seems like stackdriver is logging twice with one of the two logs having empty textpayload.
I also learnt that stackdriver will update their log delivery mechanism in Q1 2020, which will likely address this problem.
I will leave this isuee tracker as is for now. You will be notified when the issue is fixed in Q1 2020.