mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
cmd/icingadb-migrate: avoid unnecessary config option
for columns which are NULLable anyway.
This commit is contained in:
parent
833c935b35
commit
cfaee2e3d4
4 changed files with 20 additions and 48 deletions
|
|
@ -48,7 +48,7 @@ type commentRow = struct {
|
|||
}
|
||||
|
||||
func convertCommentRows(
|
||||
env string, envId, endpointId icingadbTypes.Binary,
|
||||
env string, envId icingadbTypes.Binary,
|
||||
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []commentRow,
|
||||
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
|
||||
var commentHistory, acknowledgementHistory, allHistoryComment, allHistoryAck []contracts.Entity
|
||||
|
|
@ -71,7 +71,6 @@ func convertCommentRows(
|
|||
CommentHistoryEntity: history.CommentHistoryEntity{CommentId: id},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -93,7 +92,6 @@ func convertCommentRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "comment_add", row.Name})},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -111,7 +109,6 @@ func convertCommentRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "comment_remove", row.Name})},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -143,7 +140,6 @@ func convertCommentRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -175,7 +171,6 @@ func convertCommentRows(
|
|||
Id: hashAny([]any{env, "ack_set", name, setTs}),
|
||||
},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -196,7 +191,6 @@ func convertCommentRows(
|
|||
Id: hashAny([]any{env, "ack_clear", name, setTs}),
|
||||
},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -240,7 +234,7 @@ type downtimeRow = struct {
|
|||
}
|
||||
|
||||
func convertDowntimeRows(
|
||||
env string, envId, endpointId icingadbTypes.Binary,
|
||||
env string, envId icingadbTypes.Binary,
|
||||
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []downtimeRow,
|
||||
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
|
||||
var downtimeHistory, allHistory, sla []contracts.Entity
|
||||
|
|
@ -287,7 +281,6 @@ func convertDowntimeRows(
|
|||
DowntimeHistoryEntity: history.DowntimeHistoryEntity{DowntimeId: id},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -313,7 +306,6 @@ func convertDowntimeRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "downtime_start", row.Name})},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -331,7 +323,6 @@ func convertDowntimeRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "downtime_end", row.Name})},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -352,7 +343,6 @@ func convertDowntimeRows(
|
|||
DowntimeHistoryEntity: history.DowntimeHistoryEntity{DowntimeId: id},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -385,7 +375,7 @@ type flappingRow = struct {
|
|||
}
|
||||
|
||||
func convertFlappingRows(
|
||||
env string, envId, endpointId icingadbTypes.Binary,
|
||||
env string, envId icingadbTypes.Binary,
|
||||
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []flappingRow,
|
||||
) (icingaDbInserts, icingaDbUpserts [][]contracts.Entity, checkpoint any) {
|
||||
if len(idoRows) < 1 {
|
||||
|
|
@ -446,7 +436,6 @@ func convertFlappingRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -466,7 +455,6 @@ func convertFlappingRows(
|
|||
Id: hashAny([]interface{}{env, "flapping_end", name, startTime}),
|
||||
},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -486,7 +474,6 @@ func convertFlappingRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -505,7 +492,6 @@ func convertFlappingRows(
|
|||
Id: hashAny([]interface{}{env, "flapping_start", name, startTime}),
|
||||
},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -540,7 +526,7 @@ type notificationRow = struct {
|
|||
}
|
||||
|
||||
func convertNotificationRows(
|
||||
env string, envId, endpointId icingadbTypes.Binary,
|
||||
env string, envId icingadbTypes.Binary,
|
||||
selectCache func(dest interface{}, query string, args ...interface{}), ido *sqlx.Tx, idoRows []notificationRow,
|
||||
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
|
||||
if len(idoRows) < 1 {
|
||||
|
|
@ -632,7 +618,6 @@ func convertNotificationRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -655,7 +640,6 @@ func convertNotificationRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: id},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -735,7 +719,7 @@ type stateRow = struct {
|
|||
}
|
||||
|
||||
func convertStateRows(
|
||||
env string, envId, endpointId icingadbTypes.Binary,
|
||||
env string, envId icingadbTypes.Binary,
|
||||
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []stateRow,
|
||||
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
|
||||
if len(idoRows) < 1 {
|
||||
|
|
@ -782,7 +766,6 @@ func convertStateRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -804,7 +787,6 @@ func convertStateRows(
|
|||
HistoryMeta: history.HistoryMeta{
|
||||
HistoryEntity: history.HistoryEntity{Id: id},
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
@ -825,7 +807,6 @@ func convertStateRows(
|
|||
},
|
||||
HistoryTableMeta: history.HistoryTableMeta{
|
||||
EnvironmentId: envId,
|
||||
EndpointId: endpointId,
|
||||
ObjectType: typ,
|
||||
HostId: hostId,
|
||||
ServiceId: serviceId,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"database/sql"
|
||||
_ "embed"
|
||||
"encoding/hex"
|
||||
|
|
@ -52,8 +51,6 @@ type Config struct {
|
|||
Icinga2 struct {
|
||||
// Env specifies the environment ID, hex.
|
||||
Env string `yaml:"env"`
|
||||
// Endpoint specifies the name on the main endpoint writing to IDO.
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
} `yaml:"icinga2"`
|
||||
}
|
||||
|
||||
|
|
@ -354,15 +351,13 @@ func fillCache() {
|
|||
|
||||
// migrate does the actual migration.
|
||||
func migrate(c *Config, idb *icingadb.DB, envId []byte) {
|
||||
endpointId := sha1.Sum([]byte(c.Icinga2.Endpoint))
|
||||
|
||||
progress := mpb.New()
|
||||
for _, ht := range types {
|
||||
ht.setupBar(progress, ht.total)
|
||||
}
|
||||
|
||||
types.forEach(func(ht *historyType) {
|
||||
ht.migrate(c, idb, envId, endpointId, ht)
|
||||
ht.migrate(c, idb, envId, ht)
|
||||
})
|
||||
|
||||
progress.Wait()
|
||||
|
|
@ -370,8 +365,8 @@ func migrate(c *Config, idb *icingadb.DB, envId []byte) {
|
|||
|
||||
// migrate does the actual migration for one history type.
|
||||
func migrateOneType[IdoRow any](
|
||||
c *Config, idb *icingadb.DB, envId []byte, endpointId [sha1.Size]byte, ht *historyType,
|
||||
convertRows func(env string, envId, endpointId icingadbTypes.Binary,
|
||||
c *Config, idb *icingadb.DB, envId []byte, ht *historyType,
|
||||
convertRows func(env string, envId icingadbTypes.Binary,
|
||||
selectCache func(dest interface{}, query string, args ...interface{}), ido *sqlx.Tx,
|
||||
idoRows []IdoRow) (icingaDbInserts, icingaDbUpserts [][]contracts.Entity, checkpoint any),
|
||||
) {
|
||||
|
|
@ -428,9 +423,7 @@ func migrateOneType[IdoRow any](
|
|||
ht, ht.migrationQuery, args, ht.lastId,
|
||||
func(idoRows []IdoRow) (checkpoint interface{}) {
|
||||
// ... convert them, ...
|
||||
inserts, upserts, lastIdoId := convertRows(
|
||||
c.Icinga2.Env, envId, endpointId[:], selectCache, ht.snapshot, idoRows,
|
||||
)
|
||||
inserts, upserts, lastIdoId := convertRows(c.Icinga2.Env, envId, selectCache, ht.snapshot, idoRows)
|
||||
|
||||
// ... and insert them:
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ type historyType struct {
|
|||
// migrationQuery SELECTs source data for actual migration.
|
||||
migrationQuery string
|
||||
// migrate does the actual migration.
|
||||
migrate func(c *Config, idb *icingadb.DB, envId []byte, endpointId [sha1.Size]byte, ht *historyType)
|
||||
migrate func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType)
|
||||
|
||||
// cacheFile locates <name>.sqlite3.
|
||||
cacheFile string
|
||||
|
|
@ -246,8 +246,8 @@ var types = historyTypes{
|
|||
// Manual deletion time wins vs. time of expiration which never happens due to manual deletion.
|
||||
idoEndColumns: []string{"deletion_time", "expiration_time"},
|
||||
migrationQuery: commentMigrationQuery,
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, endpId, ht, convertCommentRows)
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, ht, convertCommentRows)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -258,8 +258,8 @@ var types = historyTypes{
|
|||
idoStartColumns: []string{"actual_start_time", "scheduled_start_time"},
|
||||
idoEndColumns: []string{"actual_end_time", "scheduled_end_time"},
|
||||
migrationQuery: downtimeMigrationQuery,
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, endpId, ht, convertDowntimeRows)
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, ht, convertDowntimeRows)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -276,8 +276,8 @@ var types = historyTypes{
|
|||
})
|
||||
},
|
||||
migrationQuery: flappingMigrationQuery,
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, endpId, ht, convertFlappingRows)
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, ht, convertFlappingRows)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -294,8 +294,8 @@ var types = historyTypes{
|
|||
},
|
||||
cacheLimitQuery: "SELECT MAX(history_id) FROM previous_hard_state",
|
||||
migrationQuery: notificationMigrationQuery,
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, endpId, ht, convertNotificationRows)
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, ht, convertNotificationRows)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -310,8 +310,8 @@ var types = historyTypes{
|
|||
},
|
||||
cacheLimitQuery: "SELECT MAX(history_id) FROM previous_hard_state",
|
||||
migrationQuery: stateMigrationQuery,
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, endpId, ht, convertStateRows)
|
||||
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
|
||||
migrateOneType(c, idb, envId, ht, convertStateRows)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ Create a YAML file like this somewhere:
|
|||
icinga2:
|
||||
# Content of /var/lib/icinga2/icingadb.env
|
||||
env: "da39a3ee5e6b4b0d3255bfef95601890afBADHEX"
|
||||
# Name of the main Icinga 2 endpoint writing to IDO
|
||||
endpoint: master-1
|
||||
# IDO database
|
||||
ido:
|
||||
type: pgsql
|
||||
|
|
|
|||
Loading…
Reference in a new issue