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

Library split #747

Merged
merged 42 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9e70aa8
Move `config` to `internal/config`
lippserd May 21, 2024
7b53766
Move `icingadb/objectpacker` to `objectpacker`
lippserd May 21, 2024
43685e4
Move `internal#CantPerformQuery()` to `database#CantPerformQuery()`
lippserd May 21, 2024
75501e1
Move database related contracts to `database/contracts`
lippserd May 21, 2024
e2b4f02
Introduce `strcase` for converting string cases
lippserd May 21, 2024
ed69f42
Move `utils#TableName()` to `database#TableName()`
lippserd May 21, 2024
b2a43fd
`types#Binary`: Assert `fmt.Stringer` interface compliance
lippserd May 21, 2024
2f3bf49
Move `utils#Name()` to `types#Name()`
lippserd May 21, 2024
77ccdfc
Move type related utility functions from `internal` to `types`
lippserd May 21, 2024
1e32978
Use `google/go-cmp` to determine equality of checksums
lippserd May 21, 2024
aec0bda
Introduce `icingadb#RetryConnectorCallbacks`
lippserd May 21, 2024
490c18f
Move `database#DB.CheckSchema()` to `icingadb#CheckSchema()`
lippserd May 21, 2024
9f432e4
Make `com#CopyFirst()` generic
lippserd May 21, 2024
a62c7e7
Move `com#SplitOnDupId()` to `database#SplitOnDupId()`
lippserd May 21, 2024
aa3c008
Move `contracts#Waiter{,Func}` to `com#Waiter{,Func}`
lippserd May 21, 2024
f54a142
Move `icingadb#DB` to `database#DB`
lippserd May 21, 2024
9eddcac
`icingadb-migrate`: Don't alias `types` import
lippserd May 21, 2024
1ddaa70
Move special types to `icingadb/types`
lippserd May 21, 2024
1d9dc74
Add `utils#IsUnixAddr()`
lippserd May 21, 2024
563045c
Add `logging#Config`
lippserd May 21, 2024
c41cbf2
Move `TLS` config options to `config#TLS`
lippserd May 21, 2024
8beb861
Move database related code from `internal` to `database`
lippserd May 21, 2024
e5a830c
Move `internal/config#ParseFlags()` to `config#ParseFlags()`
lippserd May 21, 2024
3072a10
Move `internal/config#FromYAMLFile()` to `config#FromYAMLFile()`
lippserd May 21, 2024
3e63bbd
Move `internal/config#Retention` to `internal/config#RetentionConfig`
lippserd May 21, 2024
c070615
Move Redis related code to `redis`
lippserd May 21, 2024
43115e7
Don't set default port in `redis`
lippserd May 21, 2024
7b73b87
Introduce `logging#NewLoggingFromConfig()`
lippserd May 21, 2024
647220c
Decouple `structify` from `contracts`
lippserd May 21, 2024
f3eeb61
Introduce `contracts#SafeInit()`
lippserd May 21, 2024
3569b35
Fix `types#UnixMilli.UnmarshalText()` crashing on empty strings
lippserd May 21, 2024
7f43a81
`types#UnixMilli.Scan()`: Support `[]byte`
lippserd May 21, 2024
5525c20
`types#UnixMilli.Scan()`: Support `uint64`
lippserd May 21, 2024
1e221e4
Refine `types#UnixMilli` tests
lippserd May 21, 2024
957e610
Replace `utils.Fatal()` with `utils.PrintErrorThenExit()`
lippserd May 21, 2024
9f83544
`config#ParseFlags()`: Parse result into value pointed to by the pass…
lippserd May 21, 2024
b396a36
`config#FromYAMLFile()`: Parse result into value pointed to by the pa…
lippserd May 21, 2024
a73940e
Introduce `GetAddr()` for `database#DB` and `redis#Client`
lippserd May 21, 2024
cf90a39
database: Introduce `ColumnMap`
lippserd May 21, 2024
a016cc2
Allow to dynamically define type constraint name
yhabteab May 21, 2024
7c068d4
Use `icinga-go-library`
lippserd May 22, 2024
be4b450
Remove library code
lippserd May 22, 2024
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
67 changes: 34 additions & 33 deletions cmd/icingadb-migrate/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"database/sql"
_ "embed"
"github.com/icinga/icingadb/pkg/contracts"
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-go-library/types"
"github.com/icinga/icinga-go-library/utils"
icingadbTypes "github.com/icinga/icingadb/pkg/icingadb/types"
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
"github.com/icinga/icingadb/pkg/icingadb/v1/history"
icingadbTypes "github.com/icinga/icingadb/pkg/types"
"github.com/icinga/icingadb/pkg/utils"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"strconv"
Expand Down Expand Up @@ -48,10 +49,10 @@ type commentRow = struct {
}

func convertCommentRows(
env string, envId icingadbTypes.Binary,
env string, envId types.Binary,
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []commentRow,
) (stages []icingaDbOutputStage, checkpoint any) {
var commentHistory, acknowledgementHistory, allHistoryComment, allHistoryAck []contracts.Entity
var commentHistory, acknowledgementHistory, allHistoryComment, allHistoryAck []database.Entity

for _, row := range idoRows {
checkpoint = row.CommenthistoryId
Expand Down Expand Up @@ -81,14 +82,14 @@ func convertCommentRows(
},
CommentHistoryUpserter: history.CommentHistoryUpserter{
RemoveTime: removeTime,
HasBeenRemoved: icingadbTypes.Bool{Bool: !removeTime.Time().IsZero(), Valid: true},
HasBeenRemoved: types.Bool{Bool: !removeTime.Time().IsZero(), Valid: true},
},
EntryTime: entryTime,
Author: row.AuthorName,
Comment: row.CommentData,
EntryType: icingadbTypes.CommentType(row.EntryType),
IsPersistent: icingadbTypes.Bool{Bool: row.IsPersistent != 0, Valid: true},
IsSticky: icingadbTypes.Bool{Bool: false, Valid: true},
IsPersistent: types.Bool{Bool: row.IsPersistent != 0, Valid: true},
IsSticky: types.Bool{Bool: false, Valid: true},
ExpireTime: expireTime,
})

Expand Down Expand Up @@ -150,10 +151,10 @@ func convertCommentRows(
},
AckHistoryUpserter: history.AckHistoryUpserter{ClearTime: clearTime},
SetTime: setTime,
Author: icingadbTypes.MakeString(row.AuthorName),
Comment: icingadbTypes.MakeString(row.CommentData),
Author: types.MakeString(row.AuthorName),
Comment: types.MakeString(row.CommentData),
ExpireTime: convertTime(row.ExpirationTime, 0),
IsPersistent: icingadbTypes.Bool{
IsPersistent: types.Bool{
Bool: row.IsPersistent != 0,
Valid: true,
},
Expand Down Expand Up @@ -234,10 +235,10 @@ type downtimeRow = struct {
}

func convertDowntimeRows(
env string, envId icingadbTypes.Binary,
env string, envId types.Binary,
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []downtimeRow,
) (stages []icingaDbOutputStage, checkpoint any) {
var downtimeHistory, allHistory, sla []contracts.Entity
var downtimeHistory, allHistory, sla []database.Entity

for _, row := range idoRows {
checkpoint = row.DowntimehistoryId
Expand All @@ -255,10 +256,10 @@ func convertDowntimeRows(
triggerTime := convertTime(row.TriggerTime, 0)
actualStart := convertTime(row.ActualStartTime, row.ActualStartTimeUsec)
actualEnd := convertTime(row.ActualEndTime, row.ActualEndTimeUsec)
var startTime, endTime, cancelTime icingadbTypes.UnixMilli
var startTime, endTime, cancelTime types.UnixMilli

if scheduledEnd.Time().IsZero() {
scheduledEnd = icingadbTypes.UnixMilli(scheduledStart.Time().Add(time.Duration(row.Duration) * time.Second))
scheduledEnd = types.UnixMilli(scheduledStart.Time().Add(time.Duration(row.Duration) * time.Second))
}

if actualStart.Time().IsZero() {
Expand Down Expand Up @@ -290,14 +291,14 @@ func convertDowntimeRows(
ServiceId: serviceId,
},
DowntimeHistoryUpserter: history.DowntimeHistoryUpserter{
HasBeenCancelled: icingadbTypes.Bool{Bool: row.WasCancelled != 0, Valid: true},
HasBeenCancelled: types.Bool{Bool: row.WasCancelled != 0, Valid: true},
CancelTime: cancelTime,
},
TriggeredById: calcObjectId(env, row.TriggeredBy),
EntryTime: convertTime(row.EntryTime, 0),
Author: row.AuthorName,
Comment: row.CommentData,
IsFlexible: icingadbTypes.Bool{Bool: row.IsFixed == 0, Valid: true},
IsFlexible: types.Bool{Bool: row.IsFixed == 0, Valid: true},
FlexibleDuration: uint64(row.Duration) * 1000,
ScheduledStartTime: scheduledStart,
ScheduledEndTime: scheduledEnd,
Expand Down Expand Up @@ -336,7 +337,7 @@ func convertDowntimeRows(
StartTime: startTime,
CancelTime: cancelTime,
EndTime: endTime,
HasBeenCancelled: icingadbTypes.Bool{Bool: row.WasCancelled != 0, Valid: true},
HasBeenCancelled: types.Bool{Bool: row.WasCancelled != 0, Valid: true},
}

h2.EventTime.History = h2
Expand All @@ -352,7 +353,7 @@ func convertDowntimeRows(
ServiceId: serviceId,
},
DowntimeStart: startTime,
HasBeenCancelled: icingadbTypes.Bool{Bool: row.WasCancelled != 0, Valid: true},
HasBeenCancelled: types.Bool{Bool: row.WasCancelled != 0, Valid: true},
CancelTime: cancelTime,
EndTime: endTime,
}
Expand Down Expand Up @@ -383,7 +384,7 @@ type flappingRow = struct {
}

func convertFlappingRows(
env string, envId icingadbTypes.Binary,
env string, envId types.Binary,
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []flappingRow,
) (stages []icingaDbOutputStage, checkpoint any) {
if len(idoRows) < 1 {
Expand All @@ -401,12 +402,12 @@ func convertFlappingRows(
)

// Needed for start time (see below).
cachedById := make(map[uint64]icingadbTypes.UnixMilli, len(cached))
cachedById := make(map[uint64]types.UnixMilli, len(cached))
for _, c := range cached {
cachedById[c.HistoryId] = convertTime(c.EventTime, c.EventTimeUsec)
}

var flappingHistory, flappingHistoryUpserts, allHistory []contracts.Entity
var flappingHistory, flappingHistoryUpserts, allHistory []database.Entity
for _, row := range idoRows {
checkpoint = row.FlappinghistoryId

Expand All @@ -417,7 +418,7 @@ func convertFlappingRows(
ts := convertTime(row.EventTime.Int64, row.EventTimeUsec)

// Needed for ID (see below).
var start icingadbTypes.UnixMilli
var start types.UnixMilli
if row.EventType == 1001 { // end
var ok bool
start, ok = cachedById[row.FlappinghistoryId]
Expand Down Expand Up @@ -454,7 +455,7 @@ func convertFlappingRows(
},
FlappingHistoryUpserter: history.FlappingHistoryUpserter{
EndTime: ts,
PercentStateChangeEnd: icingadbTypes.Float{NullFloat64: row.PercentStateChange},
PercentStateChangeEnd: types.Float{NullFloat64: row.PercentStateChange},
FlappingThresholdLow: float32(row.LowThreshold),
FlappingThresholdHigh: float32(row.HighThreshold),
},
Expand Down Expand Up @@ -495,7 +496,7 @@ func convertFlappingRows(
FlappingThresholdHigh: float32(row.HighThreshold),
},
StartTime: start,
PercentStateChangeStart: icingadbTypes.Float{NullFloat64: row.PercentStateChange},
PercentStateChangeStart: types.Float{NullFloat64: row.PercentStateChange},
})

h := &history.HistoryFlapping{
Expand Down Expand Up @@ -541,7 +542,7 @@ type notificationRow = struct {
}

func convertNotificationRows(
env string, envId icingadbTypes.Binary,
env string, envId types.Binary,
selectCache func(dest interface{}, query string, args ...interface{}), ido *sqlx.Tx, idoRows []notificationRow,
) (stages []icingaDbOutputStage, checkpoint any) {
if len(idoRows) < 1 {
Expand Down Expand Up @@ -590,7 +591,7 @@ func convertNotificationRows(
perId[contact.Name1] = struct{}{}
}

var notificationHistory, userNotificationHistory, allHistory []contracts.Entity
var notificationHistory, userNotificationHistory, allHistory []database.Entity
for _, row := range idoRows {
checkpoint = row.NotificationId

Expand Down Expand Up @@ -646,7 +647,7 @@ func convertNotificationRows(
SendTime: ts,
State: row.State,
PreviousHardState: previousHardState,
Text: icingadbTypes.MakeString(text),
Text: types.MakeString(text),
UsersNotified: row.ContactsNotified,
})

Expand Down Expand Up @@ -737,7 +738,7 @@ type stateRow = struct {
}

func convertStateRows(
env string, envId icingadbTypes.Binary,
env string, envId types.Binary,
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []stateRow,
) (stages []icingaDbOutputStage, checkpoint any) {
if len(idoRows) < 1 {
Expand All @@ -758,7 +759,7 @@ func convertStateRows(
cachedById[c.HistoryId] = c.PreviousHardState
}

var stateHistory, allHistory, sla []contracts.Entity
var stateHistory, allHistory, sla []database.Entity
for _, row := range idoRows {
checkpoint = row.StatehistoryId

Expand Down Expand Up @@ -799,10 +800,10 @@ func convertStateRows(
PreviousSoftState: row.LastState,
PreviousHardState: previousHardState,
CheckAttempt: row.CurrentCheckAttempt,
Output: icingadbTypes.String{NullString: row.Output},
LongOutput: icingadbTypes.String{NullString: row.LongOutput},
Output: types.String{NullString: row.Output},
LongOutput: types.String{NullString: row.LongOutput},
MaxCheckAttempts: row.MaxCheckAttempts,
CheckSource: icingadbTypes.String{NullString: row.CheckSource},
CheckSource: types.String{NullString: row.CheckSource},
})

allHistory = append(allHistory, &history.HistoryState{
Expand Down
Loading
Loading