• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / iot-manager / 1445709825

09 Sep 2024 11:23AM UTC coverage: 86.917% (-0.3%) from 87.172%
1445709825

Pull #303

gitlab-ci

alfrunes
ci: update gitlab runner

Moving to deprecated docker gitlab public runner, to a self-hosted runner

Ticket: SEC-1133
Changelog: none

Signed-off-by: Roberto Giovanardi <roberto.giovanardi@northern.tech>
(cherry picked from commit bb026f77c)
Pull Request #303: Cherry-pick MEN-7478 to 1.3.x (3.7.x)

42 of 54 new or added lines in 2 files covered. (77.78%)

128 existing lines in 10 files now uncovered.

3169 of 3646 relevant lines covered (86.92%)

9.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.05
/store/mongo/datastore_mongo_events.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package mongo
16

17
import (
18
        "context"
19
        "time"
20

21
        "github.com/google/uuid"
22
        "github.com/pkg/errors"
23
        "go.mongodb.org/mongo-driver/bson"
24
        mopts "go.mongodb.org/mongo-driver/mongo/options"
25

26
        mstore "github.com/mendersoftware/go-lib-micro/store/v2"
27

28
        "github.com/mendersoftware/iot-manager/model"
29
)
30

31
const (
32
        CollNameLog = "log"
33

34
        KeyEventTs = "event_ts"
35
)
36

37
var (
38
        eventExpiration int64
39

40
        ErrFailedToGetEvents = errors.New("failed to get events")
41
)
42

43
func SetEventExpiration(exp int64) {
2✔
44
        eventExpiration = exp
2✔
45
}
2✔
46

47
func (db *DataStoreMongo) GetEvents(
48
        ctx context.Context,
49
        fltr model.EventsFilter,
50
) ([]model.Event, error) {
6✔
51
        var (
6✔
52
                err     error
6✔
53
                results = []model.Event{}
6✔
54
        )
6✔
55

6✔
56
        collEvents := db.Collection(CollNameLog)
6✔
57
        findOpts := mopts.Find().
6✔
58
                SetSort(bson.D{{Key: KeyEventTs, Value: -1}}).
6✔
59
                SetSkip(fltr.Skip)
6✔
60
        if fltr.Limit > 0 {
10✔
61
                findOpts.SetLimit(fltr.Limit)
4✔
62
        }
4✔
63

64
        cur, err := collEvents.Find(ctx,
6✔
65
                mstore.WithTenantID(ctx, bson.D{}),
6✔
66
                findOpts,
6✔
67
        )
6✔
68
        if err != nil {
6✔
UNCOV
69
                return nil, errors.Wrap(err, "error executing log collection request")
×
70
        }
×
71
        if err = cur.All(ctx, &results); err != nil {
6✔
UNCOV
72
                return nil, errors.Wrap(err, "error retrieving log collection results")
×
73
        }
×
74

75
        return results, nil
6✔
76
}
77

78
func (db *DataStoreMongo) SaveEvent(
79
        ctx context.Context,
80
        event model.Event,
81
) error {
7✔
82
        now := time.Now()
7✔
83
        event.EventTS = now
7✔
84
        event.ExpireTS = now.Add(time.Second * time.Duration(eventExpiration))
7✔
85

7✔
86
        if event.ID == uuid.Nil {
9✔
87
                event.ID = uuid.New()
2✔
88
        }
2✔
89

90
        collEvents := db.Collection(CollNameLog)
7✔
91

7✔
92
        _, err := collEvents.
7✔
93
                InsertOne(ctx, mstore.WithTenantID(ctx, event))
7✔
94
        if err != nil {
7✔
UNCOV
95
                return errors.Wrapf(err, "failed to store an event %v", event)
×
96
        }
×
97

98
        return nil
7✔
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc