Skip to content

Commit

Permalink
schema: Fix sla report inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jan 26, 2023
1 parent 4ed4db3 commit e3f9693
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ BEGIN
LEAVE read_loop;
END IF;

IF row_previous_hard_state = 99 THEN
IF last_hard_state = 99 OR row_previous_hard_state = 99 THEN
SET total_time = total_time - (row_event_time - last_event_time);
ELSEIF ((in_service_id IS NULL AND last_hard_state > 0) OR (in_service_id IS NOT NULL AND last_hard_state > 1))
AND last_hard_state != 99
Expand All @@ -156,7 +156,11 @@ BEGIN
END LOOP;
CLOSE cur;

SET result = 100 * (total_time - problem_time) / total_time;
-- prevents division by zero crashes
IF total_time > 0 THEN
SET result = 100 * (total_time - problem_time) / total_time;
END IF; -- else no data available to be reported

RETURN result;
END//
DELIMITER ;
Expand Down
10 changes: 8 additions & 2 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DECLARE
problem_time biguint := 0;
total_time biguint;
row record;
result decimal(7, 4);
BEGIN
IF in_end_time <= in_start_time THEN
RAISE 'end time must be greater than start time';
Expand Down Expand Up @@ -138,7 +139,7 @@ BEGIN
)
ORDER BY event_time, event_prio
LOOP
IF row.previous_hard_state = 99 THEN
IF last_hard_state = 99 OR row.previous_hard_state = 99 THEN
total_time := total_time - (row.event_time - last_event_time);
ELSEIF ((in_service_id IS NULL AND last_hard_state > 0) OR (in_service_id IS NOT NULL AND last_hard_state > 1))
AND last_hard_state != 99
Expand All @@ -157,7 +158,12 @@ BEGIN
END IF;
END LOOP;

RETURN 100 * (total_time - problem_time) / total_time;
-- prevents division by zero crashes
IF total_time > 0 THEN
result := 100 * (total_time - problem_time) / total_time;
END IF; -- else no data available to be reported

RETURN result;
END;
$$;

Expand Down

0 comments on commit e3f9693

Please sign in to comment.