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

mendersoftware / mender-server / 1622978334

13 Jan 2025 03:51PM UTC coverage: 72.802% (-3.8%) from 76.608%
1622978334

Pull #300

gitlab-ci

alfrunes
fix: Deployment device count should not exceed max devices

Added a condition to skip deployments when the device count reaches max
devices.

Changelog: Title
Ticket: MEN-7847
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #300: fix: Deployment device count should not exceed max devices

4251 of 6164 branches covered (68.96%)

Branch coverage included in aggregate %.

0 of 18 new or added lines in 1 file covered. (0.0%)

2544 existing lines in 83 files now uncovered.

42741 of 58384 relevant lines covered (73.21%)

21.49 hits per line

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

23.53
/backend/pkg/accesslog/context.go
1
// Copyright 2024 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 accesslog
16

17
import (
18
        "context"
19
        "strings"
20
        "sync"
21
)
22

23
const (
24
        DefaultMaxErrors = 5
25
)
26

27
type AccessLogFormat string
28

29
type LogContext interface {
30
        PushError(err error) bool
31
        SetField(key string, value interface{})
32
}
33

34
type logContext struct {
35
        errors    []error
36
        mu        sync.Mutex
37
        maxErrors int
38
        fields    map[string]interface{}
39
}
40

41
func (c *logContext) SetField(key string, value interface{}) {
×
42
        c.mu.Lock()
×
43
        defer c.mu.Unlock()
×
44
        if c.fields == nil {
×
45
                c.fields = make(map[string]interface{})
×
46
        }
×
47
        c.fields[key] = value
×
48
}
49

UNCOV
50
func (c *logContext) PushError(err error) bool {
×
UNCOV
51
        if c.maxErrors > 0 {
×
UNCOV
52
                c.mu.Lock()
×
UNCOV
53
                defer c.mu.Unlock()
×
UNCOV
54
                if len(c.errors) > c.maxErrors {
×
55
                        return false
×
56
                }
×
57
        }
UNCOV
58
        c.errors = append(c.errors, err)
×
UNCOV
59
        return true
×
60
}
61

62
func (c *logContext) addFields(fields map[string]interface{}) {
4✔
63
        if c == nil {
4✔
64
                return
×
65
        }
×
66
        switch len(c.errors) {
4✔
67
        case 0:
4✔
UNCOV
68
        case 1:
×
UNCOV
69
                if c.errors[0] != nil {
×
UNCOV
70
                        fields["error"] = c.errors[0].Error()
×
UNCOV
71
                }
×
72
        default:
×
73
                var s strings.Builder
×
74
                for i, err := range c.errors {
×
75
                        if err != nil {
×
76
                                s.WriteString(err.Error())
×
77
                                if i < len(c.errors)-1 {
×
78
                                        s.WriteString("; ")
×
79
                                }
×
80
                        }
81
                }
82
                fields["error"] = s.String()
×
83
        }
84
        for key, value := range c.fields {
4✔
85
                fields[key] = value
×
86
        }
×
87
}
88

89
type logContextKey struct{}
90

91
func withContext(ctx context.Context, c *logContext) context.Context {
4✔
92
        return context.WithValue(ctx, logContextKey{}, c)
4✔
93
}
4✔
94

95
func fromContext(ctx context.Context) *logContext {
4✔
96
        if c, ok := ctx.Value(logContextKey{}).(*logContext); ok && c != nil {
8✔
97
                return c
4✔
98
        }
4✔
99
        return nil
×
100
}
101

UNCOV
102
func GetContext(ctx context.Context) LogContext {
×
UNCOV
103
        if lc := fromContext(ctx); lc != nil {
×
UNCOV
104
                return lc
×
UNCOV
105
        }
×
106
        return nil
×
107
}
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