Skip to content

Commit 82ac037

Browse files
committed
Icinga DB Source: Address Review
- event.Event: Extend baseEv.Event instead of a pointer. - object: Merge IdTagRow and TagRow. - objects.go: Remove mysterious trailing whitespace.
1 parent 508ea9c commit 82ac037

File tree

8 files changed

+13
-16
lines changed

8 files changed

+13
-16
lines changed

internal/event/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Event struct {
3131
SourceId int64 `json:"-"`
3232
ID int64 `json:"-"`
3333

34-
*baseEv.Event `json:",inline"`
34+
baseEv.Event `json:",inline"`
3535
}
3636

3737
// Validate validates the current event state.

internal/incident/incident.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func (i *Incident) evaluateEscalations(eventTime time.Time) ([]*rule.Escalation,
492492

493493
i.RetriggerEscalations(&event.Event{
494494
Time: nextEvalAt,
495-
Event: &baseEv.Event{
495+
Event: baseEv.Event{
496496
Type: baseEv.TypeIncidentAge,
497497
Message: fmt.Sprintf("Incident reached age %v", nextEvalAt.Sub(i.StartedAt.Time())),
498498
},

internal/incident/incidents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func LoadOpenIncidents(ctx context.Context, db *database.DB, logger *logging.Log
131131

132132
i.RetriggerEscalations(&event.Event{
133133
Time: time.Now(),
134-
Event: &baseEv.Event{
134+
Event: baseEv.Event{
135135
Type: baseEv.TypeIncidentAge,
136136
Message: fmt.Sprintf("Incident reached age %v (daemon was restarted)", time.Since(i.StartedAt.Time())),
137137
},

internal/incident/incidents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func makeIncident(ctx context.Context, db *database.DB, t *testing.T, sourceID i
150150
ev := &event.Event{
151151
Time: time.Time{},
152152
SourceId: sourceID,
153-
Event: &baseEv.Event{
153+
Event: baseEv.Event{
154154
Name: testutils.MakeRandomString(t),
155155
Tags: map[string]string{ // Always generate unique object tags not to produce same object ID!
156156
"host": testutils.MakeRandomString(t),

internal/object/db_types.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ package object
22

33
import "github.com/icinga/icinga-go-library/types"
44

5-
// TagRow is a base type for IdTagRow and ExtraTagRow
6-
type TagRow struct {
5+
// IdTagRow represents a single database object id tag.
6+
type IdTagRow struct {
77
ObjectId types.Binary `db:"object_id"`
88
Tag string `db:"tag"`
99
Value string `db:"value"`
1010
}
1111

12-
// IdTagRow represents a single database object id tag.
13-
type IdTagRow TagRow
14-
1512
// TableName implements the contracts.TableNamer interface.
1613
func (e *IdTagRow) TableName() string {
1714
return "object_id_tag"

internal/object/object.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func FromEvent(ctx context.Context, db *database.DB, ev *event.Event) (*Object,
104104
}
105105

106106
stmt, _ = db.BuildUpsertStmt(&IdTagRow{})
107-
_, err = tx.NamedExecContext(ctx, stmt, mapToTagRows(newObject.ID, ev.Tags))
107+
_, err = tx.NamedExecContext(ctx, stmt, mapToIdTagRows(newObject.ID, ev.Tags))
108108
if err != nil {
109109
return nil, fmt.Errorf("failed to upsert object id tags: %w", err)
110110
}
@@ -193,11 +193,11 @@ func ID(source int64, tags map[string]string) types.Binary {
193193
return h.Sum(nil)
194194
}
195195

196-
// mapToTagRows transforms the object tags map to a slice of TagRow struct.
197-
func mapToTagRows(objectId types.Binary, tags map[string]string) []*TagRow {
198-
var tagRows []*TagRow
196+
// mapToIdTagRows transforms the object tags map to a slice of TagRow struct.
197+
func mapToIdTagRows(objectId types.Binary, tags map[string]string) []*IdTagRow {
198+
var tagRows []*IdTagRow
199199
for key, val := range tags {
200-
tagRows = append(tagRows, &TagRow{
200+
tagRows = append(tagRows, &IdTagRow{
201201
ObjectId: objectId,
202202
Tag: key,
203203
Value: val,

internal/object/objects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func restoreObjectsFromQuery(ctx context.Context, db *database.DB, query string,
9898
if err != nil {
9999
return errors.Wrap(err, "cannot restore objects ID tags")
100100
}
101-
101+
102102
cacheMu.Lock()
103103
defer cacheMu.Unlock()
104104

internal/object/objects_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func makeObject(ctx context.Context, db *database.DB, t *testing.T, sourceID int
8383
ev := &event.Event{
8484
Time: time.Time{},
8585
SourceId: sourceID,
86-
Event: &baseEv.Event{
86+
Event: baseEv.Event{
8787
Name: testutils.MakeRandomString(t),
8888
Mute: types.Bool{Valid: true, Bool: mute},
8989
MuteReason: "Just for testing",

0 commit comments

Comments
 (0)