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

elastic / cloudbeat / 13013465319

28 Jan 2025 03:10PM UTC coverage: 75.703% (+0.06%) from 75.647%
13013465319

push

github

web-flow
[8.17](backport #2936) Use custom logger to downgrade canceled context errors to warnings (#2956)

155 of 184 new or added lines in 122 files covered. (84.24%)

131 existing lines in 44 files now uncovered.

8693 of 11483 relevant lines covered (75.7%)

16.85 hits per line

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

86.84
/internal/vulnerability/replicator.go
1
// Licensed to Elasticsearch B.V. under one or more contributor
2
// license agreements. See the NOTICE file distributed with
3
// this work for additional information regarding copyright
4
// ownership. Elasticsearch B.V. licenses this file to you under
5
// the Apache License, Version 2.0 (the "License"); you may
6
// not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17

18
package vulnerability
19

20
import (
21
        "context"
22

23
        "github.com/elastic/cloudbeat/internal/infra/clog"
24
        "github.com/elastic/cloudbeat/internal/resources/providers/awslib/ec2"
25
)
26

27
type VulnerabilityReplicator struct {
28
        log      *clog.Logger
29
        provider replicatorProvider
30
        ch       chan ec2.EBSSnapshot
31
}
32

33
type replicatorProvider interface {
34
        CreateSnapshots(ctx context.Context, ins *ec2.Ec2Instance) ([]ec2.EBSSnapshot, error)
35
}
36

37
func NewVulnerabilityReplicator(log *clog.Logger, provider replicatorProvider) VulnerabilityReplicator {
4✔
38
        log.Debug("VulnerabilityReplicator: New")
4✔
39
        ch := make(chan ec2.EBSSnapshot)
4✔
40
        return VulnerabilityReplicator{
4✔
41
                log:      log,
4✔
42
                ch:       ch,
4✔
43
                provider: provider,
4✔
44
        }
4✔
45
}
4✔
46

47
func (f VulnerabilityReplicator) SnapshotInstance(ctx context.Context, insCh chan *ec2.Ec2Instance) []ec2.EBSSnapshot {
3✔
48
        f.log.Info("Starting VulnerabilityReplicator.SnapshotInstance")
3✔
49
        defer close(f.ch)
3✔
50
        var snapshots []ec2.EBSSnapshot
3✔
51
        for {
8✔
52
                select {
5✔
UNCOV
53
                case <-ctx.Done():
×
54
                        f.log.Info("VulnerabilityReplicator.SnapshotInstance context canceled")
×
55
                        return snapshots
×
56
                case data, ok := <-insCh:
5✔
57
                        if !ok {
7✔
58
                                f.log.Info("VulnerabilityReplicator.SnapshotInstance channel is closed")
2✔
59
                                return snapshots
2✔
60
                        }
2✔
61
                        sp, err := f.provider.CreateSnapshots(ctx, data)
3✔
62
                        if err != nil {
3✔
UNCOV
63
                                f.log.Errorf("VulnerabilityReplicator.SnapshotInstance.CreateSnapshots failed: %v", err)
×
64
                                continue
×
65
                        }
66

67
                        snapshots = append(snapshots, sp...)
3✔
68
                        for _, s := range sp {
6✔
69
                                f.log.Infof("VulnerabilityReplicator.SnapshotInstance created snapshot: %s of size %d for instance %s", s.SnapshotId, s.VolumeSize, *data.InstanceId)
3✔
70
                                select {
3✔
71
                                case <-ctx.Done():
1✔
72
                                        f.log.Info("VulnerabilityReplicator.SnapshotInstance context canceled")
1✔
73
                                        return snapshots
1✔
74
                                case f.ch <- s:
2✔
75
                                }
76
                        }
77
                }
78
        }
79
}
80

81
func (f VulnerabilityReplicator) GetChan() chan ec2.EBSSnapshot {
3✔
82
        return f.ch
3✔
83
}
3✔
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

© 2026 Coveralls, Inc