Skip to content

Commit

Permalink
Merge branch 'develop' into aptos-init__csa-key-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Nov 8, 2024
2 parents 831a2b8 + 1757514 commit a37d5f1
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 56 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
uses: ./.github/actions/setup-go
with:
# race/fuzz tests don't benefit repeated caching, so restore from develop's build cache
restore-build-cache-only: ${{ matrix.type.cmd == 'go_core_race_tests' || matrix.type.cmd == 'go_core_fuzz' }}
restore-build-cache-only: ${{ matrix.type.cmd == 'go_core_fuzz' }}
build-cache-version: ${{ matrix.type.cmd }}

- name: Replace chainlink-evm deps
Expand Down Expand Up @@ -220,12 +220,13 @@ jobs:
go install ./pkg/chainlink/cmd/chainlink-starknet
popd
- name: Increase Race Timeout
# Increase race timeout for scheduled runs only
- name: Increase Timeouts for Fuzz/Race
# Increase timeouts for scheduled runs only
if: ${{ github.event.schedule != '' && needs.filter.outputs.should-run-ci-core == 'true' }}
run: |
echo "TIMEOUT=10m" >> $GITHUB_ENV
echo "COUNT=50" >> $GITHUB_ENV
echo "FUZZ_TIMEOUT_MINUTES=10">> $GITHUB_ENV
- name: Install gotestloghelper
if: ${{ needs.filter.outputs.should-run-ci-core == 'true' }}
Expand Down
19 changes: 18 additions & 1 deletion core/services/chainlink/config_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chainlink

import (
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/static"
)

type telemetryConfig struct {
Expand Down Expand Up @@ -31,8 +32,24 @@ func (b *telemetryConfig) OtelExporterGRPCEndpoint() string {
return *b.s.Endpoint
}

// ResourceAttributes returns the resource attributes set in the TOML config
// by the user, but first sets OTEL required attributes:
//
// service.name
// service.version
//
// These can be overridden by the TOML if the user so chooses
func (b *telemetryConfig) ResourceAttributes() map[string]string {
return b.s.ResourceAttributes
defaults := map[string]string{
"service.name": "chainlink",
"service.version": static.Version,
}

for k, v := range b.s.ResourceAttributes {
defaults[k] = v
}

return defaults
}

func (b *telemetryConfig) TraceSampleRatio() float64 {
Expand Down
142 changes: 142 additions & 0 deletions core/services/chainlink/config_telemetry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package chainlink

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/static"
)

func TestTelemetryConfig_Enabled(t *testing.T) {
trueVal := true
falseVal := false

tests := []struct {
name string
telemetry toml.Telemetry
expected bool
}{
{"EnabledTrue", toml.Telemetry{Enabled: &trueVal}, true},
{"EnabledFalse", toml.Telemetry{Enabled: &falseVal}, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.Enabled())
})
}
}

func TestTelemetryConfig_InsecureConnection(t *testing.T) {
trueVal := true
falseVal := false

tests := []struct {
name string
telemetry toml.Telemetry
expected bool
}{
{"InsecureConnectionTrue", toml.Telemetry{InsecureConnection: &trueVal}, true},
{"InsecureConnectionFalse", toml.Telemetry{InsecureConnection: &falseVal}, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.InsecureConnection())
})
}
}

func TestTelemetryConfig_CACertFile(t *testing.T) {
tests := []struct {
name string
telemetry toml.Telemetry
expected string
}{
{"CACertFileSet", toml.Telemetry{CACertFile: ptr("test.pem")}, "test.pem"},
{"CACertFileNil", toml.Telemetry{CACertFile: nil}, ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.CACertFile())
})
}
}

func TestTelemetryConfig_OtelExporterGRPCEndpoint(t *testing.T) {
tests := []struct {
name string
telemetry toml.Telemetry
expected string
}{
{"EndpointSet", toml.Telemetry{Endpoint: ptr("localhost:4317")}, "localhost:4317"},
{"EndpointNil", toml.Telemetry{Endpoint: nil}, ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.OtelExporterGRPCEndpoint())
})
}
}

func TestTelemetryConfig_ResourceAttributes(t *testing.T) {
tests := []struct {
name string
telemetry toml.Telemetry
expected map[string]string
}{
{
"DefaultAttributes",
toml.Telemetry{ResourceAttributes: nil},
map[string]string{
"service.name": "chainlink",
"service.version": static.Version,
},
},
{
"CustomAttributes",
toml.Telemetry{ResourceAttributes: map[string]string{"custom.key": "custom.value"}},
map[string]string{
"service.name": "chainlink",
"service.version": static.Version,
"custom.key": "custom.value",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.Equal(t, tt.expected, tc.ResourceAttributes())
})
}
}

func TestTelemetryConfig_TraceSampleRatio(t *testing.T) {
tests := []struct {
name string
telemetry toml.Telemetry
expected float64
}{
{"TraceSampleRatioSet", toml.Telemetry{TraceSampleRatio: ptrFloat(0.5)}, 0.5},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := telemetryConfig{s: tt.telemetry}
assert.InEpsilon(t, tt.expected, tc.TraceSampleRatio(), 0.0001)
})
}
}

func ptrFloat(f float64) *float64 {
return &f
}
2 changes: 1 addition & 1 deletion deployment/keystone/changeset/internal/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func deployCapReg(t *testing.T, lggr logger.Logger, chain deployment.Chain) *kcr
}

func addNops(t *testing.T, lggr logger.Logger, chain deployment.Chain, registry *kcr.CapabilitiesRegistry, nops []kcr.CapabilitiesRegistryNodeOperator) *kslib.RegisterNOPSResponse {
resp, err := kslib.RegisterNOPS(context.TODO(), kslib.RegisterNOPSRequest{
resp, err := kslib.RegisterNOPS(context.TODO(), lggr, kslib.RegisterNOPSRequest{
Chain: chain,
Registry: registry,
Nops: nops,
Expand Down
Loading

0 comments on commit a37d5f1

Please sign in to comment.