Skip to content

Commit 5326cb3

Browse files
authored
Merge pull request #541 from Icinga/migrate-endpoint
cmd/icingadb-migrate: avoid unnecessary config option
2 parents e6795f4 + cfaee2e commit 5326cb3

File tree

4 files changed

+20
-48
lines changed

4 files changed

+20
-48
lines changed

cmd/icingadb-migrate/convert.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type commentRow = struct {
4848
}
4949

5050
func convertCommentRows(
51-
env string, envId, endpointId icingadbTypes.Binary,
51+
env string, envId icingadbTypes.Binary,
5252
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []commentRow,
5353
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
5454
var commentHistory, acknowledgementHistory, allHistoryComment, allHistoryAck []contracts.Entity
@@ -71,7 +71,6 @@ func convertCommentRows(
7171
CommentHistoryEntity: history.CommentHistoryEntity{CommentId: id},
7272
HistoryTableMeta: history.HistoryTableMeta{
7373
EnvironmentId: envId,
74-
EndpointId: endpointId,
7574
ObjectType: typ,
7675
HostId: hostId,
7776
ServiceId: serviceId,
@@ -93,7 +92,6 @@ func convertCommentRows(
9392
HistoryMeta: history.HistoryMeta{
9493
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "comment_add", row.Name})},
9594
EnvironmentId: envId,
96-
EndpointId: endpointId,
9795
ObjectType: typ,
9896
HostId: hostId,
9997
ServiceId: serviceId,
@@ -111,7 +109,6 @@ func convertCommentRows(
111109
HistoryMeta: history.HistoryMeta{
112110
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "comment_remove", row.Name})},
113111
EnvironmentId: envId,
114-
EndpointId: endpointId,
115112
ObjectType: typ,
116113
HostId: hostId,
117114
ServiceId: serviceId,
@@ -143,7 +140,6 @@ func convertCommentRows(
143140
},
144141
HistoryTableMeta: history.HistoryTableMeta{
145142
EnvironmentId: envId,
146-
EndpointId: endpointId,
147143
ObjectType: typ,
148144
HostId: hostId,
149145
ServiceId: serviceId,
@@ -175,7 +171,6 @@ func convertCommentRows(
175171
Id: hashAny([]any{env, "ack_set", name, setTs}),
176172
},
177173
EnvironmentId: envId,
178-
EndpointId: endpointId,
179174
ObjectType: typ,
180175
HostId: hostId,
181176
ServiceId: serviceId,
@@ -196,7 +191,6 @@ func convertCommentRows(
196191
Id: hashAny([]any{env, "ack_clear", name, setTs}),
197192
},
198193
EnvironmentId: envId,
199-
EndpointId: endpointId,
200194
ObjectType: typ,
201195
HostId: hostId,
202196
ServiceId: serviceId,
@@ -240,7 +234,7 @@ type downtimeRow = struct {
240234
}
241235

242236
func convertDowntimeRows(
243-
env string, envId, endpointId icingadbTypes.Binary,
237+
env string, envId icingadbTypes.Binary,
244238
_ func(interface{}, string, ...interface{}), _ *sqlx.Tx, idoRows []downtimeRow,
245239
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
246240
var downtimeHistory, allHistory, sla []contracts.Entity
@@ -287,7 +281,6 @@ func convertDowntimeRows(
287281
DowntimeHistoryEntity: history.DowntimeHistoryEntity{DowntimeId: id},
288282
HistoryTableMeta: history.HistoryTableMeta{
289283
EnvironmentId: envId,
290-
EndpointId: endpointId,
291284
ObjectType: typ,
292285
HostId: hostId,
293286
ServiceId: serviceId,
@@ -313,7 +306,6 @@ func convertDowntimeRows(
313306
HistoryMeta: history.HistoryMeta{
314307
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "downtime_start", row.Name})},
315308
EnvironmentId: envId,
316-
EndpointId: endpointId,
317309
ObjectType: typ,
318310
HostId: hostId,
319311
ServiceId: serviceId,
@@ -331,7 +323,6 @@ func convertDowntimeRows(
331323
HistoryMeta: history.HistoryMeta{
332324
HistoryEntity: history.HistoryEntity{Id: hashAny([]string{env, "downtime_end", row.Name})},
333325
EnvironmentId: envId,
334-
EndpointId: endpointId,
335326
ObjectType: typ,
336327
HostId: hostId,
337328
ServiceId: serviceId,
@@ -352,7 +343,6 @@ func convertDowntimeRows(
352343
DowntimeHistoryEntity: history.DowntimeHistoryEntity{DowntimeId: id},
353344
HistoryTableMeta: history.HistoryTableMeta{
354345
EnvironmentId: envId,
355-
EndpointId: endpointId,
356346
ObjectType: typ,
357347
HostId: hostId,
358348
ServiceId: serviceId,
@@ -385,7 +375,7 @@ type flappingRow = struct {
385375
}
386376

387377
func convertFlappingRows(
388-
env string, envId, endpointId icingadbTypes.Binary,
378+
env string, envId icingadbTypes.Binary,
389379
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []flappingRow,
390380
) (icingaDbInserts, icingaDbUpserts [][]contracts.Entity, checkpoint any) {
391381
if len(idoRows) < 1 {
@@ -446,7 +436,6 @@ func convertFlappingRows(
446436
},
447437
HistoryTableMeta: history.HistoryTableMeta{
448438
EnvironmentId: envId,
449-
EndpointId: endpointId,
450439
ObjectType: typ,
451440
HostId: hostId,
452441
ServiceId: serviceId,
@@ -466,7 +455,6 @@ func convertFlappingRows(
466455
Id: hashAny([]interface{}{env, "flapping_end", name, startTime}),
467456
},
468457
EnvironmentId: envId,
469-
EndpointId: endpointId,
470458
ObjectType: typ,
471459
HostId: hostId,
472460
ServiceId: serviceId,
@@ -486,7 +474,6 @@ func convertFlappingRows(
486474
},
487475
HistoryTableMeta: history.HistoryTableMeta{
488476
EnvironmentId: envId,
489-
EndpointId: endpointId,
490477
ObjectType: typ,
491478
HostId: hostId,
492479
ServiceId: serviceId,
@@ -505,7 +492,6 @@ func convertFlappingRows(
505492
Id: hashAny([]interface{}{env, "flapping_start", name, startTime}),
506493
},
507494
EnvironmentId: envId,
508-
EndpointId: endpointId,
509495
ObjectType: typ,
510496
HostId: hostId,
511497
ServiceId: serviceId,
@@ -540,7 +526,7 @@ type notificationRow = struct {
540526
}
541527

542528
func convertNotificationRows(
543-
env string, envId, endpointId icingadbTypes.Binary,
529+
env string, envId icingadbTypes.Binary,
544530
selectCache func(dest interface{}, query string, args ...interface{}), ido *sqlx.Tx, idoRows []notificationRow,
545531
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
546532
if len(idoRows) < 1 {
@@ -632,7 +618,6 @@ func convertNotificationRows(
632618
},
633619
HistoryTableMeta: history.HistoryTableMeta{
634620
EnvironmentId: envId,
635-
EndpointId: endpointId,
636621
ObjectType: typ,
637622
HostId: hostId,
638623
ServiceId: serviceId,
@@ -655,7 +640,6 @@ func convertNotificationRows(
655640
HistoryMeta: history.HistoryMeta{
656641
HistoryEntity: history.HistoryEntity{Id: id},
657642
EnvironmentId: envId,
658-
EndpointId: endpointId,
659643
ObjectType: typ,
660644
HostId: hostId,
661645
ServiceId: serviceId,
@@ -735,7 +719,7 @@ type stateRow = struct {
735719
}
736720

737721
func convertStateRows(
738-
env string, envId, endpointId icingadbTypes.Binary,
722+
env string, envId icingadbTypes.Binary,
739723
selectCache func(dest interface{}, query string, args ...interface{}), _ *sqlx.Tx, idoRows []stateRow,
740724
) (icingaDbInserts, _ [][]contracts.Entity, checkpoint any) {
741725
if len(idoRows) < 1 {
@@ -782,7 +766,6 @@ func convertStateRows(
782766
},
783767
HistoryTableMeta: history.HistoryTableMeta{
784768
EnvironmentId: envId,
785-
EndpointId: endpointId,
786769
ObjectType: typ,
787770
HostId: hostId,
788771
ServiceId: serviceId,
@@ -804,7 +787,6 @@ func convertStateRows(
804787
HistoryMeta: history.HistoryMeta{
805788
HistoryEntity: history.HistoryEntity{Id: id},
806789
EnvironmentId: envId,
807-
EndpointId: endpointId,
808790
ObjectType: typ,
809791
HostId: hostId,
810792
ServiceId: serviceId,
@@ -825,7 +807,6 @@ func convertStateRows(
825807
},
826808
HistoryTableMeta: history.HistoryTableMeta{
827809
EnvironmentId: envId,
828-
EndpointId: endpointId,
829810
ObjectType: typ,
830811
HostId: hostId,
831812
ServiceId: serviceId,

cmd/icingadb-migrate/main.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"crypto/sha1"
65
"database/sql"
76
_ "embed"
87
"encoding/hex"
@@ -52,8 +51,6 @@ type Config struct {
5251
Icinga2 struct {
5352
// Env specifies the environment ID, hex.
5453
Env string `yaml:"env"`
55-
// Endpoint specifies the name on the main endpoint writing to IDO.
56-
Endpoint string `yaml:"endpoint"`
5754
} `yaml:"icinga2"`
5855
}
5956

@@ -354,24 +351,22 @@ func fillCache() {
354351

355352
// migrate does the actual migration.
356353
func migrate(c *Config, idb *icingadb.DB, envId []byte) {
357-
endpointId := sha1.Sum([]byte(c.Icinga2.Endpoint))
358-
359354
progress := mpb.New()
360355
for _, ht := range types {
361356
ht.setupBar(progress, ht.total)
362357
}
363358

364359
types.forEach(func(ht *historyType) {
365-
ht.migrate(c, idb, envId, endpointId, ht)
360+
ht.migrate(c, idb, envId, ht)
366361
})
367362

368363
progress.Wait()
369364
}
370365

371366
// migrate does the actual migration for one history type.
372367
func migrateOneType[IdoRow any](
373-
c *Config, idb *icingadb.DB, envId []byte, endpointId [sha1.Size]byte, ht *historyType,
374-
convertRows func(env string, envId, endpointId icingadbTypes.Binary,
368+
c *Config, idb *icingadb.DB, envId []byte, ht *historyType,
369+
convertRows func(env string, envId icingadbTypes.Binary,
375370
selectCache func(dest interface{}, query string, args ...interface{}), ido *sqlx.Tx,
376371
idoRows []IdoRow) (icingaDbInserts, icingaDbUpserts [][]contracts.Entity, checkpoint any),
377372
) {
@@ -428,9 +423,7 @@ func migrateOneType[IdoRow any](
428423
ht, ht.migrationQuery, args, ht.lastId,
429424
func(idoRows []IdoRow) (checkpoint interface{}) {
430425
// ... convert them, ...
431-
inserts, upserts, lastIdoId := convertRows(
432-
c.Icinga2.Env, envId, endpointId[:], selectCache, ht.snapshot, idoRows,
433-
)
426+
inserts, upserts, lastIdoId := convertRows(c.Icinga2.Env, envId, selectCache, ht.snapshot, idoRows)
434427

435428
// ... and insert them:
436429

cmd/icingadb-migrate/misc.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ type historyType struct {
180180
// migrationQuery SELECTs source data for actual migration.
181181
migrationQuery string
182182
// migrate does the actual migration.
183-
migrate func(c *Config, idb *icingadb.DB, envId []byte, endpointId [sha1.Size]byte, ht *historyType)
183+
migrate func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType)
184184

185185
// cacheFile locates <name>.sqlite3.
186186
cacheFile string
@@ -246,8 +246,8 @@ var types = historyTypes{
246246
// Manual deletion time wins vs. time of expiration which never happens due to manual deletion.
247247
idoEndColumns: []string{"deletion_time", "expiration_time"},
248248
migrationQuery: commentMigrationQuery,
249-
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
250-
migrateOneType(c, idb, envId, endpId, ht, convertCommentRows)
249+
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
250+
migrateOneType(c, idb, envId, ht, convertCommentRows)
251251
},
252252
},
253253
{
@@ -258,8 +258,8 @@ var types = historyTypes{
258258
idoStartColumns: []string{"actual_start_time", "scheduled_start_time"},
259259
idoEndColumns: []string{"actual_end_time", "scheduled_end_time"},
260260
migrationQuery: downtimeMigrationQuery,
261-
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
262-
migrateOneType(c, idb, envId, endpId, ht, convertDowntimeRows)
261+
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
262+
migrateOneType(c, idb, envId, ht, convertDowntimeRows)
263263
},
264264
},
265265
{
@@ -276,8 +276,8 @@ var types = historyTypes{
276276
})
277277
},
278278
migrationQuery: flappingMigrationQuery,
279-
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
280-
migrateOneType(c, idb, envId, endpId, ht, convertFlappingRows)
279+
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
280+
migrateOneType(c, idb, envId, ht, convertFlappingRows)
281281
},
282282
},
283283
{
@@ -294,8 +294,8 @@ var types = historyTypes{
294294
},
295295
cacheLimitQuery: "SELECT MAX(history_id) FROM previous_hard_state",
296296
migrationQuery: notificationMigrationQuery,
297-
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
298-
migrateOneType(c, idb, envId, endpId, ht, convertNotificationRows)
297+
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
298+
migrateOneType(c, idb, envId, ht, convertNotificationRows)
299299
},
300300
},
301301
{
@@ -310,8 +310,8 @@ var types = historyTypes{
310310
},
311311
cacheLimitQuery: "SELECT MAX(history_id) FROM previous_hard_state",
312312
migrationQuery: stateMigrationQuery,
313-
migrate: func(c *Config, idb *icingadb.DB, envId []byte, endpId [20]byte, ht *historyType) {
314-
migrateOneType(c, idb, envId, endpId, ht, convertStateRows)
313+
migrate: func(c *Config, idb *icingadb.DB, envId []byte, ht *historyType) {
314+
migrateOneType(c, idb, envId, ht, convertStateRows)
315315
},
316316
},
317317
}

doc/06-Migration.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Create a YAML file like this somewhere:
2828
icinga2:
2929
# Content of /var/lib/icinga2/icingadb.env
3030
env: "da39a3ee5e6b4b0d3255bfef95601890afBADHEX"
31-
# Name of the main Icinga 2 endpoint writing to IDO
32-
endpoint: master-1
3331
# IDO database
3432
ido:
3533
type: pgsql

0 commit comments

Comments
 (0)