Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/placeos-triggers/loki_search_errrors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,18 @@
result.response_data.result.as(Loki::Model::Streams).each do |resp_stream|
map = resp_stream.labels.map

# Nil-safe extraction
# Extract module ID from stream labels
mod_id = map["source"]?
time_str = map["time"]?

next unless mod_id && time_str

begin
err_time = Time::Format::RFC_3339.parse(time_str)
# Keep only the latest error per module
if !module_errors.has_key?(mod_id) || err_time > module_errors[mod_id]
module_errors[mod_id] = err_time
next unless mod_id

# Iterate through entries to find the latest error timestamp
resp_stream.entries.each do |entry|
if err_time = entry.timestamp
# Keep only the latest error per module
if !module_errors.has_key?(mod_id) || err_time > module_errors[mod_id]
module_errors[mod_id] = err_time
end
end
rescue ex
Log.error(exception: ex) { {message: "Failed to parse timestamp", module: mod_id, timestamp: time_str} }
end
end

Expand Down Expand Up @@ -83,7 +81,7 @@
WHERE #{PlaceOS::Model::Module.table_name}.id = data.id
SQL

PgORM::Database.connection do |db|

Check notice on line 84 in src/placeos-triggers/loki_search_errrors.cr

View workflow job for this annotation

GitHub Actions / Ameba

Naming/BlockParameterName

Disallowed block parameter name found
Raw output
> PgORM::Database.connection do |db|
                                 ^
db.exec(sql, mod_ids, timestamps)
end
Log.info { {message: "Bulk updated modules with runtime errors", count: updates.size} }
Expand Down
Loading