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

trento-project / agent / 15555582457

10 Jun 2025 09:16AM UTC coverage: 72.807% (-0.6%) from 73.44%
15555582457

Pull #449

github

balanza
preserve error logs
Pull Request #449: Replace logrus logger with built-in log/slogs

215 of 384 new or added lines in 62 files covered. (55.99%)

5 existing lines in 3 files now uncovered.

4806 of 6601 relevant lines covered (72.81%)

19.34 hits per line

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

0.0
/pkg/factsengine/plugininterface/rpc.go
1
package plugininterface
2

3
import (
4
        "context"
5
        "log/slog"
6
        "net/rpc"
7

8
        "github.com/google/uuid"
9
        "github.com/trento-project/agent/pkg/factsengine/entities"
10
)
11

12
type GathererRPC struct{ client *rpc.Client }
13

14
func (g *GathererRPC) RequestGathering(
15
        ctx context.Context,
16
        factsRequest []entities.FactRequest,
17
) ([]entities.Fact, error) {
×
18
        var resp []entities.Fact
×
19
        var err error
×
20

×
21
        requestID := uuid.New().String()
×
22
        args := GatheringArgs{
×
23
                FactRequests: factsRequest,
×
24
                RequestID:    requestID,
×
25
        }
×
26

×
27
        gathering := make(chan error)
×
28

×
29
        go func() {
×
30
                gathering <- g.client.Call("Plugin.ServeGathering", args, &resp)
×
31
        }()
×
32

33
        select {
×
34
        case <-ctx.Done():
×
35
                err = g.client.Call("Plugin.Cancel", requestID, &resp)
×
36
                return []entities.Fact{}, err
×
37
        case err = <-gathering:
×
38
                if err != nil {
×
39
                        return nil, err
×
40
                }
×
41
                return resp, nil
×
42
        }
43
}
44

45
type GathererRPCServer struct {
46
        Impl      Gatherer
47
        cancelMap map[string]context.CancelFunc
48
}
49

50
type GatheringArgs struct {
51
        FactRequests []entities.FactRequest
52
        RequestID    string
53
}
54

55
func (s *GathererRPCServer) ServeGathering(args GatheringArgs, resp *[]entities.Fact) error {
×
56

×
57
        ctx, cancel := context.WithCancel(context.Background())
×
58
        if s.cancelMap == nil {
×
59
                s.cancelMap = make(map[string]context.CancelFunc)
×
60
        }
×
61
        s.cancelMap[args.RequestID] = cancel
×
62
        defer delete(s.cancelMap, args.RequestID)
×
63

×
64
        var err error
×
65
        *resp, err = s.Impl.Gather(ctx, args.FactRequests)
×
66
        return err
×
67
}
68

69
func (s *GathererRPCServer) Cancel(requestID string, _ *[]entities.Fact) (_ error) {
×
70
        cancel, ok := s.cancelMap[requestID]
×
71
        if ok {
×
72
                cancel()
×
73
                delete(s.cancelMap, requestID)
×
74
        } else {
×
NEW
75
                slog.Warn("Cannot find cancel function for request", "requestID", requestID)
×
76
        }
×
77

78
        return nil
×
79
}
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