Skip to content

Commit 31b9ccf

Browse files
authored
refactor(loki_search_errors): [PPT-2344] extract timestamp from entry object instead of stream labels (#52)
1 parent ed2133b commit 31b9ccf

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/placeos-triggers/loki_search_errrors.cr

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@ module PlaceOS::Triggers
3333
result.response_data.result.as(Loki::Model::Streams).each do |resp_stream|
3434
map = resp_stream.labels.map
3535

36-
# Nil-safe extraction
36+
# Extract module ID from stream labels
3737
mod_id = map["source"]?
38-
time_str = map["time"]?
39-
40-
next unless mod_id && time_str
41-
42-
begin
43-
err_time = Time::Format::RFC_3339.parse(time_str)
44-
# Keep only the latest error per module
45-
if !module_errors.has_key?(mod_id) || err_time > module_errors[mod_id]
46-
module_errors[mod_id] = err_time
38+
next unless mod_id
39+
40+
# Iterate through entries to find the latest error timestamp
41+
resp_stream.entries.each do |entry|
42+
if err_time = entry.timestamp
43+
# Keep only the latest error per module
44+
if !module_errors.has_key?(mod_id) || err_time > module_errors[mod_id]
45+
module_errors[mod_id] = err_time
46+
end
4747
end
48-
rescue ex
49-
Log.error(exception: ex) { {message: "Failed to parse timestamp", module: mod_id, timestamp: time_str} }
5048
end
5149
end
5250

0 commit comments

Comments
 (0)