Skip to content

Commit 1994028

Browse files
authored
add docs for local container, add health check API, remove unused params from Workflow dashboard (#1752)
1 parent adcb18b commit 1994028

File tree

10 files changed

+2541
-2457
lines changed

10 files changed

+2541
-2457
lines changed

book/src/framework/nodeset_docker_rebuild.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Create a configuration file `smoke.toml`
2222
# Dockerfile path is relative to "docker_ctx"
2323
docker_file = "core/chainlink.Dockerfile"
2424
docker_ctx = "../.."
25+
# Or pin the image after the first build and work on the test
26+
image = "chainlink-tmp:latest"
2527
```
2628

2729
These paths will work for `e2e/capabilities` in our main [repository](https://github.com/smartcontractkit/chainlink/tree/ctf-v2-tests/e2e/capabilities)

framework/.changeset/v0.6.8.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Remove unused params from Workflow dashboard
2+
- Add WaitHealthy to verify components health with regex
3+
- Fix docs for local docker image build

framework/clclient/client.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"math/big"
99
"net/http"
1010
"os"
11+
"regexp"
1112
"strings"
1213
"sync"
1314
"time"
1415

16+
"github.com/avast/retry-go/v4"
1517
"github.com/ethereum/go-ethereum/accounts/keystore"
1618
"github.com/ethereum/go-ethereum/crypto"
1719
"github.com/pkg/errors"
@@ -127,6 +129,80 @@ func (c *ChainlinkClient) Health() (*HealthResponse, *http.Response, error) {
127129
return respBody, resp.RawResponse, err
128130
}
129131

132+
// WaitHealthy waits until all the components (regex) return specified status
133+
func (c *ChainlinkClient) WaitHealthy(pattern, status string, attempts uint) error {
134+
respBody := &HealthResponse{}
135+
framework.L.Info().Str(NodeURL, c.Config.URL).Msg("Check CL node health")
136+
re, err := regexp.Compile(pattern)
137+
if err != nil {
138+
return fmt.Errorf("invalid regex pattern: %w", err)
139+
}
140+
err = retry.Do(
141+
func() error {
142+
framework.L.Info().Str(NodeURL, c.Config.URL).Uint("Attempts", attempts).Msg("Awaiting Chainlink node health status")
143+
resp, err := c.APIClient.R().
144+
SetResult(&respBody).
145+
Get("/health")
146+
if err != nil {
147+
return fmt.Errorf("error connecting to chainlink node after %d attempts: %w", attempts, err)
148+
}
149+
if resp.StatusCode() >= 400 {
150+
return fmt.Errorf("error connecting to chainlink node after %d attempts: %s", attempts, resp.Status())
151+
}
152+
153+
var foundComponents bool
154+
var notReadyComponents []string
155+
156+
for _, d := range respBody.Data {
157+
framework.L.Debug().Str("Component", d.Attributes.Name).Msg("Checking component")
158+
if re.MatchString(d.Attributes.Name) {
159+
foundComponents = true
160+
if d.Attributes.Status != status {
161+
notReadyComponents = append(notReadyComponents,
162+
fmt.Sprintf("%s Current: %s, Expected: %s",
163+
d.Attributes.Name,
164+
d.Attributes.Status,
165+
status))
166+
}
167+
}
168+
}
169+
170+
if !foundComponents {
171+
return fmt.Errorf("no component found in health response")
172+
}
173+
174+
if len(notReadyComponents) > 0 {
175+
framework.L.Debug().
176+
Strs("Components", notReadyComponents).
177+
Msg("Components not yet ready")
178+
return fmt.Errorf("%d components not ready", len(notReadyComponents))
179+
}
180+
181+
return nil
182+
},
183+
retry.Attempts(attempts),
184+
retry.Delay(1*time.Second),
185+
retry.DelayType(retry.FixedDelay),
186+
retry.OnRetry(func(n uint, err error) {
187+
framework.L.Debug().
188+
Uint("Attempt", n+1).
189+
Uint("MaxAttempts", attempts).
190+
Str("Pattern", pattern).
191+
Msg("Retrying health check")
192+
}),
193+
)
194+
195+
if err != nil {
196+
return fmt.Errorf("health check failed after %d attempts: %w", attempts, err)
197+
}
198+
199+
framework.L.Info().
200+
Str("pattern", pattern).
201+
Str("status", status).
202+
Msg("All matching components ready")
203+
return nil
204+
}
205+
130206
// CreateJobRaw creates a Chainlink job based on the provided spec string
131207
func (c *ChainlinkClient) CreateJobRaw(spec string) (*Job, *http.Response, error) {
132208
job := &Job{}

0 commit comments

Comments
 (0)