Skip to content

Commit be64887

Browse files
author
Joonas Bergius
committed
chore(provider): Address linter feedback
Signed-off-by: Joonas Bergius <[email protected]>
1 parent 3721e95 commit be64887

File tree

6 files changed

+99
-96
lines changed

6 files changed

+99
-96
lines changed

provider/host.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ const (
4444

4545
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_endpoint
4646
OtelExporterGrpcEndpoint = "http://localhost:4317"
47-
OtelExporterHttpEndpoint = "http://localhost:4318"
47+
OtelExporterHTTPEndpoint = "http://localhost:4318"
4848

4949
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_traces_endpoint
50-
OtelExporterHttpTracesPath = "/v1/traces"
50+
OtelExporterHTTPTracesPath = "/v1/traces"
5151
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_metrics_endpoint
52-
OtelExporterHttpMetricsPath = "/v1/metrics"
52+
OtelExporterHTTPMetricsPath = "/v1/metrics"
5353
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_logs_endpoint
54-
OtelExporterHttpLogsPath = "/v1/logs"
54+
OtelExporterHTTPLogsPath = "/v1/logs"
5555
)
5656

5757
// OtelProtocol returns the configured OpenTelemetry protocol if one is provided,
@@ -72,7 +72,7 @@ func (config *OtelConfig) TracesURL() string {
7272
return config.TracesEndpoint
7373
}
7474

75-
return config.resolveSignalUrl(traces)
75+
return config.resolveSignalURL(traces)
7676
}
7777

7878
// MetricsURL returns the configured MetricsEndpoint as-is if one is provided,
@@ -83,7 +83,7 @@ func (config *OtelConfig) MetricsURL() string {
8383
return config.MetricsEndpoint
8484
}
8585

86-
return config.resolveSignalUrl(metrics)
86+
return config.resolveSignalURL(metrics)
8787
}
8888

8989
// LogsURL returns the configured LogsEndpoint as-is if one is provided,
@@ -94,7 +94,7 @@ func (config *OtelConfig) LogsURL() string {
9494
return config.LogsEndpoint
9595
}
9696

97-
return config.resolveSignalUrl(logs)
97+
return config.resolveSignalURL(logs)
9898
}
9999

100100
// TracesEnabled returns whether emitting traces has been enabled.
@@ -112,7 +112,7 @@ func (config *OtelConfig) LogsEnabled() bool {
112112
return config.EnableObservability || config.EnableLogs
113113
}
114114

115-
func (config *OtelConfig) resolveSignalUrl(signal otelSignal) string {
115+
func (config *OtelConfig) resolveSignalURL(signal otelSignal) string {
116116
endpoint := config.defaultEndpoint()
117117
if config.ObservabilityEndpoint != "" {
118118
endpoint = config.ObservabilityEndpoint
@@ -127,7 +127,7 @@ func (config *OtelConfig) defaultEndpoint() string {
127127
return OtelExporterGrpcEndpoint
128128
}
129129

130-
return OtelExporterHttpEndpoint
130+
return OtelExporterHTTPEndpoint
131131
}
132132

133133
func (config *OtelConfig) defaultSignalPath(signal otelSignal) string {
@@ -138,11 +138,11 @@ func (config *OtelConfig) defaultSignalPath(signal otelSignal) string {
138138

139139
switch signal {
140140
case traces:
141-
return OtelExporterHttpTracesPath
141+
return OtelExporterHTTPTracesPath
142142
case metrics:
143-
return OtelExporterHttpMetricsPath
143+
return OtelExporterHTTPMetricsPath
144144
case logs:
145-
return OtelExporterHttpLogsPath
145+
return OtelExporterHTTPLogsPath
146146
}
147147
return ""
148148
}

provider/models.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
type Topics struct {
10-
LATTICE_LINK_GET string
11-
LATTICE_LINK_DEL string
12-
LATTICE_LINK_PUT string
13-
LATTICE_SHUTDOWN string
14-
LATTICE_HEALTH string
10+
LatticeLinkGet string
11+
LatticeLinkDel string
12+
LatticeLinkPut string
13+
LatticeHealth string
14+
LatticeShutdown string
1515
}
1616

1717
func LatticeTopics(h HostData, providerXkey nkeys.KeyPair) Topics {
@@ -29,10 +29,10 @@ func LatticeTopics(h HostData, providerXkey nkeys.KeyPair) Topics {
2929
}
3030

3131
return Topics{
32-
LATTICE_LINK_GET: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.get", h.LatticeRPCPrefix, h.ProviderKey),
33-
LATTICE_LINK_DEL: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.del", h.LatticeRPCPrefix, h.ProviderKey),
34-
LATTICE_LINK_PUT: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.put", h.LatticeRPCPrefix, providerLinkPutKey),
35-
LATTICE_HEALTH: fmt.Sprintf("wasmbus.rpc.%s.%s.health", h.LatticeRPCPrefix, h.ProviderKey),
36-
LATTICE_SHUTDOWN: fmt.Sprintf("wasmbus.rpc.%s.%s.default.shutdown", h.LatticeRPCPrefix, h.ProviderKey),
32+
LatticeLinkGet: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.get", h.LatticeRPCPrefix, h.ProviderKey),
33+
LatticeLinkDel: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.del", h.LatticeRPCPrefix, h.ProviderKey),
34+
LatticeLinkPut: fmt.Sprintf("wasmbus.rpc.%s.%s.linkdefs.put", h.LatticeRPCPrefix, providerLinkPutKey),
35+
LatticeHealth: fmt.Sprintf("wasmbus.rpc.%s.%s.health", h.LatticeRPCPrefix, h.ProviderKey),
36+
LatticeShutdown: fmt.Sprintf("wasmbus.rpc.%s.%s.default.shutdown", h.LatticeRPCPrefix, h.ProviderKey),
3737
}
3838
}

provider/models_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,37 @@ func TestLatticeTopics(t *testing.T) {
1616
wasmCloudOneDotZero := HostData{ProviderKey: "providerfoo", LatticeRPCPrefix: "lattice123", ProviderXKeyPrivateKey: RedactedString(""), HostXKeyPublicKey: ""}
1717
OneDotZeroTopics := LatticeTopics(wasmCloudOneDotZero, xkey)
1818

19-
// Test LATTICE_LINK_GET
19+
// Test LatticeLinkGet
2020
expectedLinkGet := "wasmbus.rpc.lattice123.providerfoo.linkdefs.get"
21-
if OneDotZeroTopics.LATTICE_LINK_GET != expectedLinkGet {
22-
t.Errorf("Expected LATTICE_LINK_GET to be %q, got %q", expectedLinkGet, OneDotZeroTopics.LATTICE_LINK_GET)
21+
if OneDotZeroTopics.LatticeLinkGet != expectedLinkGet {
22+
t.Errorf("Expected LatticeLinkGet to be %q, got %q", expectedLinkGet, OneDotZeroTopics.LatticeLinkGet)
2323
}
2424

25-
// Test LATTICE_LINK_DEL
25+
// Test LatticeLinkDel
2626
expectedLinkDel := "wasmbus.rpc.lattice123.providerfoo.linkdefs.del"
27-
if OneDotZeroTopics.LATTICE_LINK_DEL != expectedLinkDel {
28-
t.Errorf("Expected LATTICE_LINK_DEL to be %q, got %q", expectedLinkDel, OneDotZeroTopics.LATTICE_LINK_DEL)
27+
if OneDotZeroTopics.LatticeLinkDel != expectedLinkDel {
28+
t.Errorf("Expected LatticeLinkDel to be %q, got %q", expectedLinkDel, OneDotZeroTopics.LatticeLinkDel)
2929
}
3030

31-
// Test LATTICE_LINK_PUT
31+
// Test LatticeLinkPut
3232
expectedLinkPut := "wasmbus.rpc.lattice123.providerfoo.linkdefs.put"
33-
if OneDotZeroTopics.LATTICE_LINK_PUT != expectedLinkPut {
34-
t.Errorf("Expected LATTICE_LINK_PUT to be %q, got %q", expectedLinkPut, OneDotZeroTopics.LATTICE_LINK_PUT)
33+
if OneDotZeroTopics.LatticeLinkPut != expectedLinkPut {
34+
t.Errorf("Expected LatticeLinkPut to be %q, got %q", expectedLinkPut, OneDotZeroTopics.LatticeLinkPut)
3535
}
3636

37-
// Test LATTICE_SHUTDOWN
37+
// Test LatticeShutdown
3838
expectedShutdown := "wasmbus.rpc.lattice123.providerfoo.default.shutdown"
39-
if OneDotZeroTopics.LATTICE_SHUTDOWN != expectedShutdown {
40-
t.Errorf("Expected LATTICE_SHUTDOWN to be %q, got %q", expectedShutdown, OneDotZeroTopics.LATTICE_SHUTDOWN)
39+
if OneDotZeroTopics.LatticeShutdown != expectedShutdown {
40+
t.Errorf("Expected LatticeShutdown to be %q, got %q", expectedShutdown, OneDotZeroTopics.LatticeShutdown)
4141
}
4242

43-
// Test LATTICE_HEALTH
43+
// Test LatticeHealth
4444
expectedHealth := "wasmbus.rpc.lattice123.providerfoo.health"
45-
if OneDotZeroTopics.LATTICE_HEALTH != expectedHealth {
46-
t.Errorf("Expected LATTICE_HEALTH to be %q, got %q", expectedHealth, OneDotZeroTopics.LATTICE_HEALTH)
45+
if OneDotZeroTopics.LatticeHealth != expectedHealth {
46+
t.Errorf("Expected LatticeHealth to be %q, got %q", expectedHealth, OneDotZeroTopics.LatticeHealth)
4747
}
4848

49-
// Test secrets / wasmCloud 1.1 and later topics. All are the same as 1.0 except LATTICE_LINK_PUT
49+
// Test secrets / wasmCloud 1.1 and later topics. All are the same as 1.0 except LatticeLinkPut
5050
xkeyPublicKey, err := xkey.PublicKey()
5151
if err != nil {
5252
t.Errorf("Expected err to be nil, got: %v", err)
@@ -58,32 +58,32 @@ func TestLatticeTopics(t *testing.T) {
5858
wasmCloudOneDotOne := HostData{ProviderKey: "providerfoo", LatticeRPCPrefix: "lattice123", ProviderXKeyPrivateKey: RedactedString(string(xkeyPrivateKey)), HostXKeyPublicKey: xkeyPublicKey}
5959
OneDotOneTopics := LatticeTopics(wasmCloudOneDotOne, xkey)
6060

61-
// Test LATTICE_LINK_GET
62-
if OneDotOneTopics.LATTICE_LINK_GET != expectedLinkGet {
63-
t.Errorf("Expected LATTICE_LINK_GET to be %q, got %q", expectedLinkGet, OneDotOneTopics.LATTICE_LINK_GET)
61+
// Test LatticeLinkGet
62+
if OneDotOneTopics.LatticeLinkGet != expectedLinkGet {
63+
t.Errorf("Expected LatticeLinkGet to be %q, got %q", expectedLinkGet, OneDotOneTopics.LatticeLinkGet)
6464
}
6565

66-
// Test LATTICE_LINK_DEL
67-
if OneDotOneTopics.LATTICE_LINK_DEL != expectedLinkDel {
68-
t.Errorf("Expected LATTICE_LINK_DEL to be %q, got %q", expectedLinkDel, OneDotOneTopics.LATTICE_LINK_DEL)
66+
// Test LatticeLinkDel
67+
if OneDotOneTopics.LatticeLinkDel != expectedLinkDel {
68+
t.Errorf("Expected LatticeLinkDel to be %q, got %q", expectedLinkDel, OneDotOneTopics.LatticeLinkDel)
6969
}
7070

71-
// Test LATTICE_LINK_PUT
71+
// Test LatticeLinkPut
7272
if err != nil {
7373
t.Errorf("Expected err to be nil, got: %v", err)
7474
}
7575
expectedLinkPut = fmt.Sprintf("wasmbus.rpc.lattice123.%s.linkdefs.put", xkeyPublicKey)
76-
if OneDotOneTopics.LATTICE_LINK_PUT != expectedLinkPut {
77-
t.Errorf("Expected LATTICE_LINK_PUT to be %q, got %q", expectedLinkPut, OneDotOneTopics.LATTICE_LINK_PUT)
76+
if OneDotOneTopics.LatticeLinkPut != expectedLinkPut {
77+
t.Errorf("Expected LatticeLinkPut to be %q, got %q", expectedLinkPut, OneDotOneTopics.LatticeLinkPut)
7878
}
7979

80-
// Test LATTICE_SHUTDOWN
81-
if OneDotOneTopics.LATTICE_SHUTDOWN != expectedShutdown {
82-
t.Errorf("Expected LATTICE_SHUTDOWN to be %q, got %q", expectedShutdown, OneDotOneTopics.LATTICE_SHUTDOWN)
80+
// Test LatticeShutdown
81+
if OneDotOneTopics.LatticeShutdown != expectedShutdown {
82+
t.Errorf("Expected LatticeShutdown to be %q, got %q", expectedShutdown, OneDotOneTopics.LatticeShutdown)
8383
}
8484

85-
// Test LATTICE_HEALTH
86-
if OneDotOneTopics.LATTICE_HEALTH != expectedHealth {
87-
t.Errorf("Expected LATTICE_HEALTH to be %q, got %q", expectedHealth, OneDotOneTopics.LATTICE_HEALTH)
85+
// Test LatticeHealth
86+
if OneDotOneTopics.LatticeHealth != expectedHealth {
87+
t.Errorf("Expected LatticeHealth to be %q, got %q", expectedHealth, OneDotOneTopics.LatticeHealth)
8888
}
8989
}

provider/provider.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
)
2828

2929
type WasmcloudProvider struct {
30-
Id string
30+
ID string
3131

3232
context context.Context
3333
cancel context.CancelFunc
@@ -221,7 +221,7 @@ func NewWithHostDataSource(source io.Reader, options ...ProviderHandler) (*Wasmc
221221

222222
ctx, cancel := context.WithCancel(context.Background())
223223
provider := &WasmcloudProvider{
224-
Id: hostData.ProviderKey,
224+
ID: hostData.ProviderKey,
225225
Logger: logger,
226226
RPCClient: wrpc,
227227
Topics: LatticeTopics(hostData, providerXkey),
@@ -290,6 +290,7 @@ func (wp *WasmcloudProvider) NatsConnection() *nats.Conn {
290290
return wp.natsConnection
291291
}
292292

293+
//nolint:revive
293294
func (wp *WasmcloudProvider) OutgoingRpcClient(target string) *wrpcnats.Client {
294295
return wrpcnats.NewClient(wp.natsConnection, wrpcnats.WithPrefix(fmt.Sprintf("%s.%s", wp.hostData.LatticeRPCPrefix, target)))
295296
}
@@ -313,9 +314,9 @@ func (wp *WasmcloudProvider) Start() error {
313314
return err
314315
}
315316

316-
wp.Logger.Info("provider started", "id", wp.Id)
317+
wp.Logger.Info("provider started", "id", wp.ID)
317318
<-wp.context.Done()
318-
wp.Logger.Info("provider exiting", "id", wp.Id)
319+
wp.Logger.Info("provider exiting", "id", wp.ID)
319320
return nil
320321
}
321322

@@ -345,7 +346,7 @@ func (wp *WasmcloudProvider) Shutdown() error {
345346

346347
func (wp *WasmcloudProvider) subToNats() error {
347348
// ------------------ Subscribe to Health topic --------------------
348-
health, err := wp.natsConnection.Subscribe(wp.Topics.LATTICE_HEALTH,
349+
health, err := wp.natsConnection.Subscribe(wp.Topics.LatticeHealth,
349350
func(m *nats.Msg) {
350351
msg := wp.healthMsgFunc()
351352
hc := HealthCheckResponse{
@@ -365,14 +366,14 @@ func (wp *WasmcloudProvider) subToNats() error {
365366
}
366367
})
367368
if err != nil {
368-
wp.Logger.Error("LATTICE_HEALTH", slog.Any("error", err))
369+
wp.Logger.Error("LatticeHealth", slog.Any("error", err))
369370
return err
370371
}
371372

372-
wp.natsSubscriptions[wp.Topics.LATTICE_HEALTH] = health
373+
wp.natsSubscriptions[wp.Topics.LatticeHealth] = health
373374

374375
// ------------------ Subscribe to Delete link topic --------------
375-
linkDel, err := wp.natsConnection.Subscribe(wp.Topics.LATTICE_LINK_DEL,
376+
linkDel, err := wp.natsConnection.Subscribe(wp.Topics.LatticeLinkDel,
376377
func(m *nats.Msg) {
377378
link := InterfaceLinkDefinition{}
378379
err := json.Unmarshal(m.Data, &link)
@@ -393,10 +394,10 @@ func (wp *WasmcloudProvider) subToNats() error {
393394
return err
394395
}
395396

396-
wp.natsSubscriptions[wp.Topics.LATTICE_LINK_DEL] = linkDel
397+
wp.natsSubscriptions[wp.Topics.LatticeLinkDel] = linkDel
397398

398399
// ------------------ Subscribe to New link topic --------------
399-
linkPut, err := wp.natsConnection.Subscribe(wp.Topics.LATTICE_LINK_PUT,
400+
linkPut, err := wp.natsConnection.Subscribe(wp.Topics.LatticeLinkPut,
400401
func(m *nats.Msg) {
401402
link := linkWithEncryptedSecrets{}
402403
err := json.Unmarshal(m.Data, &link)
@@ -422,10 +423,10 @@ func (wp *WasmcloudProvider) subToNats() error {
422423
return err
423424
}
424425

425-
wp.natsSubscriptions[wp.Topics.LATTICE_LINK_PUT] = linkPut
426+
wp.natsSubscriptions[wp.Topics.LatticeLinkPut] = linkPut
426427

427428
// ------------------ Subscribe to Shutdown topic ------------------
428-
shutdown, err := wp.natsConnection.Subscribe(wp.Topics.LATTICE_SHUTDOWN,
429+
shutdown, err := wp.natsConnection.Subscribe(wp.Topics.LatticeShutdown,
429430
func(m *nats.Msg) {
430431
err := wp.shutdownFunc()
431432
if err != nil {
@@ -447,11 +448,11 @@ func (wp *WasmcloudProvider) subToNats() error {
447448
wp.cancel()
448449
})
449450
if err != nil {
450-
wp.Logger.Error("LATTICE_SHUTDOWN", slog.Any("error", err))
451+
wp.Logger.Error("LatticeShutdown", slog.Any("error", err))
451452
return err
452453
}
453454

454-
wp.natsSubscriptions[wp.Topics.LATTICE_SHUTDOWN] = shutdown
455+
wp.natsSubscriptions[wp.Topics.LatticeShutdown] = shutdown
455456
return nil
456457
}
457458

@@ -506,14 +507,14 @@ func (wp *WasmcloudProvider) putLink(l InterfaceLinkDefinition) error {
506507

507508
wp.lock.Lock()
508509
defer wp.lock.Unlock()
509-
if l.SourceID == wp.Id {
510+
if l.SourceID == wp.ID {
510511
err := wp.putSourceLinkFunc(l)
511512
if err != nil {
512513
return err
513514
}
514515

515516
wp.sourceLinks[l.Target] = l
516-
} else if l.Target == wp.Id {
517+
} else if l.Target == wp.ID {
517518
err := wp.putTargetLinkFunc(l)
518519
if err != nil {
519520
return err
@@ -534,9 +535,9 @@ func (wp *WasmcloudProvider) updateProviderLinkMap(l InterfaceLinkDefinition) er
534535
}
535536
wp.lock.Lock()
536537
defer wp.lock.Unlock()
537-
if l.SourceID == wp.Id {
538+
if l.SourceID == wp.ID {
538539
wp.sourceLinks[l.Target] = l
539-
} else if l.Target == wp.Id {
540+
} else if l.Target == wp.ID {
540541
wp.targetLinks[l.SourceID] = l
541542
} else {
542543
wp.Logger.Info("received link that isn't for this provider, ignoring", "link", l)
@@ -547,14 +548,14 @@ func (wp *WasmcloudProvider) updateProviderLinkMap(l InterfaceLinkDefinition) er
547548
func (wp *WasmcloudProvider) deleteLink(l InterfaceLinkDefinition) error {
548549
wp.lock.Lock()
549550
defer wp.lock.Unlock()
550-
if l.SourceID == wp.Id {
551+
if l.SourceID == wp.ID {
551552
err := wp.delSourceLinkFunc(l)
552553
if err != nil {
553554
return err
554555
}
555556

556557
delete(wp.sourceLinks, l.Target)
557-
} else if l.Target == wp.Id {
558+
} else if l.Target == wp.ID {
558559
err := wp.delTargetLinkFunc(l)
559560
if err != nil {
560561
return err
@@ -568,14 +569,14 @@ func (wp *WasmcloudProvider) deleteLink(l InterfaceLinkDefinition) error {
568569
return nil
569570
}
570571

571-
func (wp *WasmcloudProvider) isLinked(sourceId string, target string) bool {
572+
func (wp *WasmcloudProvider) isLinked(sourceID string, target string) bool {
572573
wp.lock.Lock()
573574
defer wp.lock.Unlock()
574-
if sourceId == wp.Id {
575+
if sourceID == wp.ID {
575576
_, exists := wp.sourceLinks[target]
576577
return exists
577-
} else if target == wp.Id {
578-
_, exists := wp.targetLinks[sourceId]
578+
} else if target == wp.ID {
579+
_, exists := wp.targetLinks[sourceID]
579580
return exists
580581
}
581582
return false

0 commit comments

Comments
 (0)