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

uber / cadence / 01907299-3fb0-4ecc-b0ad-df71b17f5ddc

02 Jul 2024 08:39AM UTC coverage: 71.517% (-0.005%) from 71.522%
01907299-3fb0-4ecc-b0ad-df71b17f5ddc

Pull #5926

buildkite

mantas-sidlauskas
Add peer provider plugin registration
Pull Request #5926: Add peer provider plugin registration

20 of 22 new or added lines in 1 file covered. (90.91%)

36 existing lines in 12 files now uncovered.

105326 of 147274 relevant lines covered (71.52%)

2598.44 hits per line

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

90.91
/common/peerprovider/plugin.go
1
// The MIT License (MIT)
2

3
// Copyright (c) 2017-2020 Uber Technologies Inc.
4

5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22

23
package peerprovider
24

25
import (
26
        "fmt"
27

28
        "go.uber.org/yarpc/transport/tchannel"
29

30
        "github.com/uber/cadence/common/config"
31
        "github.com/uber/cadence/common/log"
32
        "github.com/uber/cadence/common/membership"
33
        "github.com/uber/cadence/common/syncmap"
34
)
35

36
// Container is passed to peer provider plugin
37
type Container struct {
38
        Service string
39
        // Channel is required by ringpop
40
        Channel tchannel.Channel
41
        Logger  log.Logger
42
        Portmap membership.PortMap
43
}
44

45
type constructorFn func(cfg *config.YamlNode, container Container) (membership.PeerProvider, error)
46

47
var plugins = syncmap.New[string, plugin]()
48

49
type plugin struct {
50
        fn        constructorFn
51
        configKey string
52
}
53

54
type Provider struct {
55
        config    config.PeerProvider
56
        container Container
57
}
58

59
func New(config config.PeerProvider, container Container) *Provider {
1✔
60
        return &Provider{
1✔
61
                config:    config,
1✔
62
                container: container,
1✔
63
        }
1✔
64
}
1✔
65

66
func Register(configKey string, constructor constructorFn) error {
3✔
67
        inserted := plugins.Put(configKey, plugin{
3✔
68
                fn:        constructor,
3✔
69
                configKey: configKey,
3✔
70
        })
3✔
71

3✔
72
        if !inserted {
4✔
73
                return fmt.Errorf("peer provider %q is already registered", configKey)
1✔
74
        }
1✔
75

76
        return nil
2✔
77
}
78

79
func (p *Provider) Provider() (membership.PeerProvider, error) {
2✔
80
        for configKey, cfg := range p.config {
3✔
81
                if plugin, found := plugins.Get(configKey); found {
1✔
NEW
82
                        return plugin.fn(cfg, p.container)
×
NEW
83
                }
×
84
        }
85

86
        return nil, fmt.Errorf("no configured peer providers found")
2✔
87
}
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