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

trento-project / agent / 30027720065

23 Jul 2026 05:02PM UTC coverage: 76.219% (+1.3%) from 74.94%
30027720065

push

github

web-flow
Publish v-prefix tag when releasing (#638)

Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>

7301 of 9579 relevant lines covered (76.22%)

16.17 hits per line

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

87.93
/pkg/factsengine/plugininterface/rpc.go
1
// SPDX-FileCopyrightText: SUSE LLC
2
// SPDX-License-Identifier: Apache-2.0
3

4
package plugininterface
5

6
import (
7
        "context"
8
        "log/slog"
9
        "net/rpc"
10
        "sync"
11

12
        "github.com/google/uuid"
13
        "github.com/trento-project/agent/pkg/factsengine/entities"
14
)
15

16
type GathererRPC struct{ client *rpc.Client }
17

18
func (g *GathererRPC) RequestGathering(
19
        ctx context.Context,
20
        factsRequest []entities.FactRequest,
21
) ([]entities.Fact, error) {
1✔
22
        var resp []entities.Fact
1✔
23
        var err error
1✔
24

1✔
25
        requestID := uuid.New().String()
1✔
26
        args := GatheringArgs{
1✔
27
                FactRequests: factsRequest,
1✔
28
                RequestID:    requestID,
1✔
29
        }
1✔
30

1✔
31
        gathering := make(chan error, 1)
1✔
32

1✔
33
        go func() {
2✔
34
                gathering <- g.client.Call("Plugin.ServeGathering", args, &resp)
1✔
35
        }()
1✔
36

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

49
type GathererRPCServer struct {
50
        Impl      Gatherer
51
        cancelMap map[string]context.CancelFunc
52
        mu        sync.Mutex
53
}
54

55
type GatheringArgs struct {
56
        FactRequests []entities.FactRequest
57
        RequestID    string
58
}
59

60
func (s *GathererRPCServer) ServeGathering(args GatheringArgs, resp *[]entities.Fact) error {
51✔
61

51✔
62
        ctx, cancel := context.WithCancel(context.Background())
51✔
63
        defer cancel()
51✔
64

51✔
65
        s.mu.Lock()
51✔
66
        if s.cancelMap == nil {
53✔
67
                s.cancelMap = make(map[string]context.CancelFunc)
2✔
68
        }
2✔
69
        s.cancelMap[args.RequestID] = cancel
51✔
70
        s.mu.Unlock()
51✔
71

51✔
72
        defer func() {
102✔
73
                s.mu.Lock()
51✔
74
                delete(s.cancelMap, args.RequestID)
51✔
75
                s.mu.Unlock()
51✔
76
        }()
51✔
77

78
        var err error
51✔
79
        *resp, err = s.Impl.Gather(ctx, args.FactRequests)
51✔
80
        return err
51✔
81
}
82

83
func (s *GathererRPCServer) Cancel(requestID string, _ *[]entities.Fact) (_ error) {
51✔
84
        s.mu.Lock()
51✔
85
        cancel, ok := s.cancelMap[requestID]
51✔
86
        if ok {
102✔
87
                delete(s.cancelMap, requestID)
51✔
88
        }
51✔
89
        s.mu.Unlock()
51✔
90

51✔
91
        if ok {
102✔
92
                cancel()
51✔
93
        } else {
51✔
94
                slog.Warn("Cannot find cancel function for request", "requestID", requestID)
×
95
        }
×
96

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

© 2026 Coveralls, Inc