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 #654

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4848c7b
Move `config` to `internal/config`
lippserd Oct 5, 2023
1f87f9e
Move `icingadb/objectpacker` to `objectpacker`
lippserd Oct 5, 2023
10ce1f0
Move `internal#CantPerformQuery()` to `database#CantPerformQuery()`
lippserd Oct 5, 2023
62fa5d5
Move database related contracts to `database/contracts`
lippserd Oct 5, 2023
96ff875
Introduce `strcase` for converting string cases
lippserd Oct 5, 2023
baf0e11
Move `utils#TableName()` to `database#TableName()`
lippserd Oct 5, 2023
09dfc22
`types#Binary`: Assert `fmt.Stringer` interface compliance
lippserd Oct 6, 2023
fabcd93
Move `utils#Name()` to `types#Name()`
lippserd Oct 6, 2023
38f5ce6
Move type related utility functions from `internal` to `types`
lippserd Oct 6, 2023
40fb51d
Use `google/go-cmp` to determine equality of checksums
lippserd Oct 6, 2023
574f9e5
Introduce `driver#Option`
lippserd Oct 6, 2023
2c4218c
Move `database#DB.CheckSchema()` to `icingadb#CheckSchema()`
lippserd Oct 6, 2023
6054c65
Move `com#SplitOnDupId()` to `database#SplitOnDupId()`
lippserd Oct 6, 2023
8a78df4
Move `contracts#Waiter{,Func}` to `com#Waiter{,Func}`
lippserd Oct 6, 2023
0873fb7
Make `com#CopyFirst()` generic
lippserd Oct 6, 2023
cdbee83
Add `context` to `com#WaitAsync()`
lippserd Oct 6, 2023
e63095e
Add `context` to `com#ErrgroupReceive()`
lippserd Oct 6, 2023
e7a7eac
Move `icingadb#DB` to `database#DB`
lippserd Oct 6, 2023
8a3fc48
`icingadb-migrate`: Don't alias `types` import
lippserd Oct 6, 2023
ff1b310
Move special types to `icingadb/types`
lippserd Oct 6, 2023
d360bf1
Decouple `structify` from `contracts`
lippserd Oct 7, 2023
a3b1e94
Add `utils#IsUnixAddr()`
lippserd Oct 9, 2023
547fb66
Add `logging#Config`
lippserd Oct 9, 2023
f0a99b5
Move database related code from `internal` to `database`
lippserd Oct 9, 2023
7ef33ac
Move `TLS` config options to `config#TLS`
lippserd Oct 9, 2023
9f0693e
Move `internal/config#ParseFlags()` to `config#ParseFlags()`
lippserd Oct 9, 2023
d7f6da7
Move `internal/config#FromYAMLFile()` to `config#FromYAMLFile()`
lippserd Oct 9, 2023
7425a41
Move `internal/config#Retention` to `internal/config#RetentionConfig`
lippserd Oct 9, 2023
582739f
Move Redis related code to `redis`
lippserd Oct 9, 2023
867cdf4
Don't set default port in `redis`
lippserd Oct 9, 2023
dddd055
Add `redis#Config.Database`
lippserd Oct 9, 2023
21f9f07
Use `icinga-go-library`
lippserd Nov 21, 2023
0b226ee
Remove library code
lippserd Nov 21, 2023
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,20 +151,20 @@ func convertCommentRows(
},
AckHistoryUpserter: history.AckHistoryUpserter{ClearTime: clearTime},
SetTime: setTime,
Author: icingadbTypes.String{
Author: types.String{
NullString: sql.NullString{
String: row.AuthorName,
Valid: true,
},
},
Comment: icingadbTypes.String{
Comment: types.String{
NullString: sql.NullString{
String: row.CommentData,
Valid: true,
},
},
ExpireTime: convertTime(row.ExpirationTime, 0),
IsPersistent: icingadbTypes.Bool{
IsPersistent: types.Bool{
Bool: row.IsPersistent != 0,
Valid: true,
},
Expand Down Expand Up @@ -244,10 +245,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 @@ -265,10 +266,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 @@ -300,14 +301,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 @@ -346,7 +347,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 @@ -362,7 +363,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 @@ -393,7 +394,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 @@ -411,12 +412,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 @@ -427,7 +428,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 @@ -464,7 +465,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 @@ -505,7 +506,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 @@ -551,7 +552,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 @@ -600,7 +601,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 @@ -656,7 +657,7 @@ func convertNotificationRows(
SendTime: ts,
State: row.State,
PreviousHardState: previousHardState,
Text: icingadbTypes.String{
Text: types.String{
NullString: sql.NullString{
String: text,
Valid: true,
Expand Down Expand Up @@ -752,7 +753,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 @@ -773,7 +774,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 @@ -814,10 +815,10 @@ func convertStateRows(
PreviousSoftState: row.LastState,
PreviousHardState: previousHardState,
CheckAttempt: uint8(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: uint32(row.MaxCheckAttempts),
CheckSource: icingadbTypes.String{NullString: row.CheckSource},
CheckSource: types.String{NullString: row.CheckSource},
})

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