Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icingadb-migrate: handle NULL event time columns #551

Merged
merged 1 commit into from
Jul 25, 2023
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
42 changes: 31 additions & 11 deletions cmd/icingadb-migrate/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var stateMigrationQuery string

type commentRow = struct {
CommenthistoryId uint64
EntryTime int64
EntryTime sql.NullInt64
EntryTimeUsec uint32
EntryType uint8
AuthorName string
Expand All @@ -56,14 +56,18 @@ func convertCommentRows(
for _, row := range idoRows {
checkpoint = row.CommenthistoryId

if !row.EntryTime.Valid {
continue
}

typ := objectTypes[row.ObjecttypeId]
hostId := calcObjectId(env, row.Name1)
serviceId := calcServiceId(env, row.Name1, row.Name2)

switch row.EntryType {
case 1: // user
id := calcObjectId(env, row.Name)
entryTime := convertTime(row.EntryTime, row.EntryTimeUsec)
entryTime := convertTime(row.EntryTime.Int64, row.EntryTimeUsec)
removeTime := convertTime(row.DeletionTime, row.DeletionTimeUsec)
expireTime := convertTime(row.ExpirationTime, 0)

Expand Down Expand Up @@ -129,7 +133,7 @@ func convertCommentRows(
name += "!" + row.Name2
}

setTime := convertTime(row.EntryTime, row.EntryTimeUsec)
setTime := convertTime(row.EntryTime.Int64, row.EntryTimeUsec)
setTs := float64(setTime.Time().UnixMilli())
clearTime := convertTime(row.DeletionTime, row.DeletionTimeUsec)
acknowledgementHistoryId := hashAny([]any{env, name, setTs})
Expand Down Expand Up @@ -218,7 +222,7 @@ type downtimeRow = struct {
CommentData string
IsFixed uint8
Duration int64
ScheduledStartTime int64
ScheduledStartTime sql.NullInt64
ScheduledEndTime int64
ActualStartTime int64
Comment on lines -221 to 227
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to #550 (comment), actual_start_time also was NULL. Might be worth looking at the schema which columns are allowed to be NULL an handle all these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't worth it IMAO. Everything that has a reason to be NULL is already handled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a reason to be NULL" may also be "there was an old icinga2 version that had a bug that didn't populate that column"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*rolling eyes* s/reason/actual reason/

I'd rather wait for that bug also arriving here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't worth it IMAO. Everything that has a reason to be NULL is already handled.

It's worth it. This bug report is proof of that.

I'd rather wait for that bug also arriving here.

I would rather fix them before. We know that almost everyone had or has an Icinga 2 version that has bugs 😆.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid there could be NULL literally everywhere ex. IDs.

$ grep -Fwie 'NOT NULL' <lib/db_ido_mysql/schema/mysql.sql |grep -vFe _id
$

On the other hand there's only 1 report yet.

Still sure about the effort/gain ratio?

ActualStartTimeUsec uint32
Expand All @@ -242,11 +246,15 @@ func convertDowntimeRows(
for _, row := range idoRows {
checkpoint = row.DowntimehistoryId

if !row.ScheduledStartTime.Valid {
continue
}

id := calcObjectId(env, row.Name)
typ := objectTypes[row.ObjecttypeId]
hostId := calcObjectId(env, row.Name1)
serviceId := calcServiceId(env, row.Name1, row.Name2)
scheduledStart := convertTime(row.ScheduledStartTime, 0)
scheduledStart := convertTime(row.ScheduledStartTime.Int64, 0)
scheduledEnd := convertTime(row.ScheduledEndTime, 0)
triggerTime := convertTime(row.TriggerTime, 0)
actualStart := convertTime(row.ActualStartTime, row.ActualStartTimeUsec)
Expand Down Expand Up @@ -363,7 +371,7 @@ func convertDowntimeRows(

type flappingRow = struct {
FlappinghistoryId uint64
EventTime int64
EventTime sql.NullInt64
EventTimeUsec uint32
EventType uint16
PercentStateChange sql.NullFloat64
Expand Down Expand Up @@ -402,7 +410,11 @@ func convertFlappingRows(
for _, row := range idoRows {
checkpoint = row.FlappinghistoryId

ts := convertTime(row.EventTime, row.EventTimeUsec)
if !row.EventTime.Valid {
continue
}

ts := convertTime(row.EventTime.Int64, row.EventTimeUsec)

// Needed for ID (see below).
var start icingadbTypes.UnixMilli
Expand Down Expand Up @@ -514,7 +526,7 @@ func convertFlappingRows(
type notificationRow = struct {
NotificationId uint64
NotificationReason uint8
EndTime int64
EndTime sql.NullInt64
EndTimeUsec uint32
State uint8
Output string
Expand Down Expand Up @@ -579,6 +591,10 @@ func convertNotificationRows(
for _, row := range idoRows {
checkpoint = row.NotificationId

if !row.EndTime.Valid {
continue
}

previousHardState, ok := cachedById[row.NotificationId]
if !ok {
continue
Expand All @@ -597,7 +613,7 @@ func convertNotificationRows(
continue
}

ts := convertTime(row.EndTime, row.EndTimeUsec)
ts := convertTime(row.EndTime.Int64, row.EndTimeUsec)
tsMilli := float64(ts.Time().UnixMilli())
notificationHistoryId := hashAny([]interface{}{env, name, ntEnum, tsMilli})
id := hashAny([]interface{}{env, "notification", name, ntEnum, tsMilli})
Expand Down Expand Up @@ -702,7 +718,7 @@ func convertNotificationType(notificationReason, state uint8) icingadbTypes.Noti

type stateRow = struct {
StatehistoryId uint64
StateTime int64
StateTime sql.NullInt64
StateTimeUsec uint32
State uint8
StateType uint8
Expand Down Expand Up @@ -744,13 +760,17 @@ func convertStateRows(
for _, row := range idoRows {
checkpoint = row.StatehistoryId

if !row.StateTime.Valid {
continue
}

previousHardState, ok := cachedById[row.StatehistoryId]
if !ok {
continue
}

name := strings.Join([]string{row.Name1, row.Name2}, "!")
ts := convertTime(row.StateTime, row.StateTimeUsec)
ts := convertTime(row.StateTime.Int64, row.StateTimeUsec)
tsMilli := float64(ts.Time().UnixMilli())
stateHistoryId := hashAny([]interface{}{env, name, tsMilli})
id := hashAny([]interface{}{env, "state_change", name, tsMilli})
Expand Down