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

fixes for various null values #613

Closed
wants to merge 2 commits into from
Closed
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
58 changes: 39 additions & 19 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 @@ -213,16 +217,16 @@ func convertCommentRows(

type downtimeRow = struct {
DowntimehistoryId uint64
EntryTime int64
EntryTime sql.NullInt64
AuthorName string
CommentData string
IsFixed uint8
Duration int64
ScheduledStartTime int64
ScheduledEndTime int64
ActualStartTime int64
ScheduledStartTime sql.NullInt64
ScheduledEndTime sql.NullInt64
ActualStartTime sql.NullInt64
ActualStartTimeUsec uint32
ActualEndTime int64
ActualEndTime sql.NullInt64
ActualEndTimeUsec uint32
WasCancelled uint8
TriggerTime int64
Expand All @@ -242,15 +246,19 @@ 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)
scheduledEnd := convertTime(row.ScheduledEndTime, 0)
scheduledStart := convertTime(row.ScheduledStartTime.Int64, 0)
scheduledEnd := convertTime(row.ScheduledEndTime.Int64, 0)
triggerTime := convertTime(row.TriggerTime, 0)
actualStart := convertTime(row.ActualStartTime, row.ActualStartTimeUsec)
actualEnd := convertTime(row.ActualEndTime, row.ActualEndTimeUsec)
actualStart := convertTime(row.ActualStartTime.Int64, row.ActualStartTimeUsec)
actualEnd := convertTime(row.ActualEndTime.Int64, row.ActualEndTimeUsec)
var startTime, endTime, cancelTime icingadbTypes.UnixMilli

if scheduledEnd.Time().IsZero() {
Expand Down Expand Up @@ -290,7 +298,7 @@ func convertDowntimeRows(
CancelTime: cancelTime,
},
TriggeredById: calcObjectId(env, row.TriggeredBy),
EntryTime: convertTime(row.EntryTime, 0),
EntryTime: convertTime(row.EntryTime.Int64, 0),
Author: row.AuthorName,
Comment: row.CommentData,
IsFlexible: icingadbTypes.Bool{Bool: row.IsFixed == 0, Valid: true},
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