Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/javascript/typescrip…
Browse files Browse the repository at this point in the history
…t-eslint/eslint-plugin-5.59.5
  • Loading branch information
wirednkod authored May 12, 2023
2 parents 261f547 + 3d93521 commit 4ff700c
Show file tree
Hide file tree
Showing 15 changed files with 681 additions and 1,203 deletions.
1,395 changes: 201 additions & 1,194 deletions javascript/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
"zombienet": "./packages/cli/dist/cli.js"
},
"dependencies": {
"@polkadot/util": "^12.1.2",
"@types/chai": "^4.3.5",
"chai": "^4.3.7"
},
"devDependencies": {
"@types/node": "^20.1.1",
"@types/node": "^20.1.3",
"@types/tmp": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/parser": "^5.59.5",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
Expand Down
4 changes: 2 additions & 2 deletions javascript/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/cli",
"version": "1.3.51",
"version": "1.3.52",
"description": "ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@zombienet/dsl-parser-wrapper": "^0.1.7",
"@zombienet/orchestrator": "^0.0.40",
"@zombienet/orchestrator": "^0.0.41",
"@zombienet/utils": "^0.0.20",
"cli-progress": "^3.12.0",
"commander": "^10.0.1",
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/cli/src/actions/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from "path";
import { AVAILABLE_PROVIDERS } from "../constants";

/**
* Test - performs test/assertions agins the spawned network, using a set of natural
* Test - performs test/assertions against the spawned network, using a set of natural
* language expressions that allow to make assertions based on metrics, logs and some
* built-in function that query the network using polkadot.js
* Read more here: https://paritytech.github.io/zombienet/cli/testing.html
Expand Down
18 changes: 18 additions & 0 deletions javascript/packages/orchestrator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ npm install
npm run build
```

### Build `parser-wrapper` locally (optional)

Building the `parser-wrapper` can help on running/testing locally changes on the test parser.
In order to build the parser one first needs to run the `wasm-pack` (make sure that [wasm-pack](https://github.com/rustwasm/wasm-pack) is installed):

```bash
cd zombienet/crates/parser-wrapper
wasm-pack build --release --target nodejs --scope zombienet
```

Once it is done, the next step is to create a symlink to the created `pkg` from inside the javascript directory, as can be seen below:

```bash
cd zombienet/javascript
npm link ../crates/parser-wrapper/pkg/
npm run build
```

### Download and install needed artifacts (optional)

For an easier and faster setup of your local environment, run:
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/orchestrator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/orchestrator",
"version": "0.0.40",
"version": "0.0.41",
"description": "ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions javascript/packages/orchestrator/src/chainSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ export async function addStaking(specPath: string, node: Node) {
const runtimeConfig = getRuntimeConfig(chainSpec);
if (!runtimeConfig?.staking) return;

const { sr_stash, sr_account } = node.accounts;
const { sr_stash } = node.accounts;
runtimeConfig.staking.stakers.push([
sr_stash.address,
sr_account.address,
sr_stash.address,
stakingBond || 1000000000000,
"Validator",
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import statemint from "./statemint";
function whichPara(chain: string): PARA {
if (chain.includes("statemint")) return PARA.Statemint;
if (/moonbase|moonriver|moonbeam/.test(chain)) return PARA.Moonbeam;
if (/efinity|rocfinity/.test(chain)) return PARA.Efinity;
if (/efinity|matrix/.test(chain)) return PARA.Efinity;
if (/acala|karura|mandala/.test(chain)) return PARA.Acala;
if (/astar|shiden|shibuya/.test(chain)) return PARA.Astar;
if (/bifrost/.test(chain)) return PARA.Bifrost;
Expand Down
10 changes: 10 additions & 0 deletions monitoring/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:alpine AS build
WORKDIR /app
COPY . .
RUN go build -o main .

# Stage 2: Run
FROM alpine
WORKDIR /app
COPY --from=build /app/main /app/
CMD ["/app/main"]
92 changes: 92 additions & 0 deletions monitoring/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package main

import (
"context"
"fmt"
"net/http"
"strings"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

var (
zombieNamespaceCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "zombie_namespace_count",
Help: "Number of namespaces with names starting with 'zombie-'",
})

zombiePodsCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "zombie_namespace_pods_count",
Help: "Number of pods in namespaces with names starting with 'zombie-'",
}, []string{"namespace"})

zombieNamespaceOld = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "zombie_namespace_old",
Help: "Indicates if a namespace with a name starting with 'zombie-' is older than 2 days",
}, []string{"namespace"})
)

func init() {
prometheus.MustRegister(zombieNamespaceCount)
prometheus.MustRegister(zombiePodsCount)
prometheus.MustRegister(zombieNamespaceOld)
}

func main() {
config, err := rest.InClusterConfig()
if err != nil {
panic(err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err)
}

go func() {
for {
updateMetrics(clientset)
time.Sleep(1 * time.Minute)
}
}()

http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":9090", nil)
}

func updateMetrics(clientset *kubernetes.Clientset) {
namespaces, err := clientset.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
if err != nil {
fmt.Printf("Error listing namespaces: %v\n", err)
return
}

zombieNamespaceCounter := 0
twoDaysAgo := time.Now().Add(-48 * time.Hour)
for _, ns := range namespaces.Items {
if strings.HasPrefix(ns.Name, "zombie-") {
zombieNamespaceCounter++

pods, err := clientset.CoreV1().Pods(ns.Name).List(context.Background(), metav1.ListOptions{})
if err != nil {
fmt.Printf("Error listing pods in namespace %s: %v\n", ns.Name, err)
continue
}

zombiePodsCount.WithLabelValues(ns.Name).Set(float64(len(pods.Items)))

if ns.CreationTimestamp.Time.Before(twoDaysAgo) {
zombieNamespaceOld.WithLabelValues(ns.Name).Set(1)
} else {
zombieNamespaceOld.WithLabelValues(ns.Name).Set(0)
}
}
}

zombieNamespaceCount.Set(float64(zombieNamespaceCounter))
}
56 changes: 56 additions & 0 deletions monitoring/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module zombienet_metrics

go 1.19

require (
github.com/prometheus/client_golang v1.15.1
k8s.io/client-go v0.27.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.1 // indirect
k8s.io/apimachinery v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 4ff700c

Please sign in to comment.