Skip to content
代码片段 群组 项目
未验证 提交 79df54fb 编辑于 作者: Stan Hu's avatar Stan Hu
浏览文件

Avoid division by zero in Elasticsearch rate calculator

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/101693
introduced a bytes per second timing calculation for the indexer
that relied on `Time.current`. However, on some hosts `Time.current`
may only have second precision, which leads to a division by 0 error.
Fix this by using `Process.clock_gettime(Process::CLOCK_MONOTONIC)`
to get a more accurate timestamp.

Relates to
https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/9336
上级 94f870b8
No related branches found
No related tags found
无相关合并请求
......@@ -148,8 +148,12 @@ def execute(shards: SHARDS)
private
def current_time
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
def execute_with_redis(redis, shards:) # rubocop:disable Metrics/AbcSize
start_time = Time.current
start_time = current_time
specs_buffer = []
scores = {}
......@@ -192,7 +196,7 @@ def execute_with_redis(redis, shards:) # rubocop:disable Metrics/AbcSize
@failures = bulk_indexer.flush
end
indexed_bytes_per_second = (total_bytes / (Time.current - start_time)).ceil
indexed_bytes_per_second = (total_bytes / (current_time - start_time)).ceil
logger.info(
'class' => self.class.name,
......@@ -220,7 +224,7 @@ def execute_with_redis(redis, shards:) # rubocop:disable Metrics/AbcSize
'meta.indexing.first_score' => first_score,
'meta.indexing.last_score' => last_score,
'meta.indexing.failures_count' => @failures.count,
'meta.indexing.bulk_execution_duration_s' => Time.current - start_time
'meta.indexing.bulk_execution_duration_s' => current_time - start_time
)
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册