Skip to content

Commit 80580c8

Browse files
committed
add docs for some clients, logging and concurrency packages
1 parent fc2d7e3 commit 80580c8

File tree

12 files changed

+240
-1
lines changed

12 files changed

+240
-1
lines changed

book/src/SUMMARY.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
- [Define NFRs and check alerts](./libs/wasp/how-to/define_nfr_check_alerts.md)
7777
- [Use labels](./libs/wasp/how-to/use_labels.md)
7878
- [Incorporate load tests in your workflow](./libs/wasp/how-to/incorporate_load_tests.md)
79-
- [Reuse dashboard components](./libs/wasp/how-to/reuse_dashboard_components.md)
79+
- [Reuse dashboard components](./libs/wasp/how-to/reuse_dashboard_components.md)
8080
- [Parallelize load](./libs/wasp/how-to/parallelise_load.md)
8181
- [Debug Loki errors](./libs/wasp/how-to/debug_loki_errors.md)
8282
- [Havoc](./libs/havoc.md)
@@ -85,6 +85,20 @@
8585
---
8686

8787
- [Releasing modules](releasing_modules.md)
88+
---
89+
90+
- [Lib](libv2/overview.md)
91+
- [Concurrency](libv2/concurrency.md)
92+
- [Client](libv2/client.md)
93+
- [Anvil]()
94+
- [AWS Secrets Manager](libv2/client/aws_secrets_manager.md)
95+
- [Github](libv2/client/github.md)
96+
- [Kafka](libv2/client/kafka.md)
97+
- [Loki](libv2/client/loki.md)
98+
- [MockServer](libv2/client/mockserver.md)
99+
- [Postgres](libv2/client/postgres.md)
100+
- [Prometheus](libv2/client/prometheus.md)
101+
- [Logging](libv2/logging.md)
88102

89103
---
90104
- [Lib (*Deprecated*)](lib.md)

book/src/libv2/client.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Client
2+
3+
We support a variety of clients that ease communication with following applications:
4+
* [Anvil](./client/anvil.md)
5+
* [AWS Secrets Manager](./client/aws_secrets_manager.md)
6+
* [Github](./client/github.md)
7+
* [Kafka](./client/kafka.md)
8+
* [Loki](./client/loki.md)
9+
* [MockServer](./client/mockserver.md)
10+
* [Postgres](./client/postgres.md)
11+
* [Prometheus](./client/prometheus.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# AWS Secrets Manager
2+
3+
This simple client makes it even easier to:
4+
* read
5+
* create
6+
* remove secrets from AWS Secrets Manager.
7+
8+
Creating a new instance is straight-forward. You should either use environment variables or shared configuration and credentials.
9+
10+
> [!NOTE]
11+
> Environment variables take precedence over shared credentials.
12+
13+
## Using environment variables
14+
You can pass required configuration as following environment variables:
15+
* `AWS_ACCESS_KEY_ID`
16+
* `AWS_SECRET_ACCESS_KEY`
17+
* `AWS_REGION`
18+
19+
## Using shared credentials
20+
If you have shared credentials stored in `.aws/credentials` file, then the easiest way to configure the client is by setting
21+
`AWS_PROFILE` environment variable with the profile name. If that environment variable is not set, the SDK will try to use default profile.
22+
23+
> [!WARNING]
24+
> Remember, that most probably you will need to manually create a new session for that profile before running your application.
25+
26+
27+
> [!NOTE]
28+
> You can read more about configuring the AWS SDK [here](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html).
29+
30+
Once you have an instance of AWS Secrets Manager you gain access to following functions:
31+
* `CreateSecret(key string, val string, override bool) error`
32+
* `GetSecret(key string) (AWSSecret, error)`
33+
* `RemoveSecret(key string, noRecovery bool) error`

book/src/libv2/client/github.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Github
2+
3+
This small client makes it easy to get `N` latest releases or tags from any Github.com repository. To use it, all you need to have
4+
is a properly scoped access token.
5+
6+
```go
7+
publicRepoClient := NewGithubClient(WITHOUT_TOKEN)
8+
9+
// "smartcontractkit", "chainlink"
10+
latestCLReleases, err := publicRepoClient.ListLatestCLCoreReleases(10)
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
// "smartcontractkit", "chainlink"
16+
latestCLTags, err := publicRepoClient.ListLatestCLCoreTags(10)
17+
if err != nil {
18+
panic(err)
19+
}
20+
21+
privateRepoClient := NewGithubClient("my-secret-PAT")
22+
myLatestReleases, err := privateRepoClient.ListLatestReleases("my-org", "my-private-repo", 5)
23+
if err != nil {
24+
panic(err)
25+
}
26+
```
27+
28+
There's really not much more to it...

book/src/libv2/client/kafka.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Kafka
2+
3+
This is a wrapper over HTTP client that can only return a list of topics from Kafka instance.
4+
5+
```go
6+
client, err := NewKafkaRestClient(&NewKafkaRestClient{URL: "my-kafka-url"})
7+
if err != nil {
8+
panic(err)
9+
}
10+
11+
topis, err := client.GetTopics()
12+
if err != nil {
13+
panic(err)
14+
}
15+
16+
for _, topic := range topics {
17+
fmt.Println("topic: " + topic)
18+
}
19+
```

book/src/libv2/client/loki.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Loki
2+
3+
Loki client simplifies querying of Loki logs with `LogQL`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# MockServer

book/src/libv2/client/postgres.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Postgres
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Prometheus

book/src/libv2/concurrency.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Concurrency
2+
3+
It's a small library that simplifies dividing N tasks between X workers with but two options:
4+
* payload
5+
* early exit on first error
6+
7+
It was created for parallelising chain interaction with [Seth](../libs/seth.md), where strict ordering
8+
and association of a given private key with a specific contract is required.
9+
10+
> [!NOTE]
11+
> This library is an overkill if all you need to do is to deploy 10 contract, where each deployment
12+
> consists of a single transaction.
13+
> But... if your deployment flow is a multi-stepped one and it's crucial that all operations are executed
14+
> using the same private key (e.g. due to privilleged access) it might be a good pick. Especially, if
15+
> you don't want to extensively test a native `WaitGroup`/`ErrGroup`-based solution.
16+
17+
## No payload
18+
If the task to be executed requires no payload (or it's the same for each task) using the tool is much simpler.
19+
20+
First you need to create an instance of the executor:
21+
```go
22+
l := logging.GetTestLogger(nil)
23+
24+
executor := concurrency.NewConcurrentExecutor[ContractIntstance, contractResult, concurrency.NoTaskType](l)
25+
```
26+
27+
Where generic parameters represent (from left to right):
28+
* type of execution result
29+
* type of channel that holds the results
30+
* type of task payload
31+
32+
In our case, we want the execution to return `ContractInstance`s, that will be stored by this type:
33+
```go
34+
type contractResult struct {
35+
instance ContractIntstance
36+
}
37+
```
38+
39+
And which won't use any payload, as indicated by a no-op `concurrency.NoTaskType`.
40+
41+
Then, we need to define a function that will be executed for each task. For example:
42+
```go
43+
var deployContractFn = func(channel chan contractResult, errorCh chan error, executorNum int) {
44+
keyNum := executorNum + 1 // key 0 is the root key
45+
46+
instance, err := client.deployContractFromKey(keyNum)
47+
if err != nil {
48+
errorCh <- err
49+
return
50+
}
51+
52+
channel <- contractResult{instance: instance}
53+
}
54+
```
55+
56+
It needs to have the following signature:
57+
```go
58+
type SimpleTaskProcessorFn[ResultChannelType any] func(resultCh chan ResultChannelType, errorCh chan error, executorNum int)
59+
```
60+
and send results of successful execution to `resultCh` and errors to `errorCh`.
61+
62+
Once the processing function is defined all that's left is the execution:
63+
```go
64+
results, err := executor.ExecuteSimple(client.getConcurrency(), numberOfContracts, deployContractFn)
65+
```
66+
67+
Parameters for `ExecuteSimple` (without payload) are as follows(from left to right):
68+
* concurrency count (number of parallel executors)
69+
* total number of executions
70+
* function to execute
71+
72+
`results` contain a slice with results of each execution with `ContractInstance` type.
73+
`err` will be non-nil if any of the executions failed. To get all errors you should call `executor.GetErrors()`.
74+
75+
## With payload
76+
If your tasks need payload, then two things change.
77+
78+
First, you need to pass task type, when creating the executor instance:
79+
```go
80+
executor := concurrency.NewConcurrentExecutor[ContractIntstance, contractResult, contractConfiguration](l)
81+
```
82+
83+
Here, it's set to dummy:
84+
```go
85+
type contractConfiguration struct{}
86+
```
87+
88+
Second, the signature of processing function:
89+
```go
90+
type TaskProcessorFn[ResultChannelType, TaskType any] func(resultCh chan ResultChannelType, errorCh chan error, executorNum int, payload TaskType)
91+
```
92+
Which now includes a forth parameter representing the payload. And that function's implementation (making use of the payload).
93+
94+
> [!NOTE]
95+
> You can find the full example [here](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/concurrency/example_test.go).

0 commit comments

Comments
 (0)