Skip to content

Commit

Permalink
add all available endpoints to zos environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Sep 5, 2024
1 parent 172a0a2 commit ba93865
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 35 deletions.
66 changes: 47 additions & 19 deletions pkg/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type Environment struct {
// SINCE RELAYS FOR A NODE IS STORED ON THE CHAIN IN A LIMITED SPACE
// PLEASE MAKE SURE THAT ANY ENV HAS NO MORE THAN FOUR RELAYS CONFIGURED
RelayURL []string
ActivationURL string
GraphQL string
ActivationURL []string
GraphQL []string

// private vlan to join
// if set, zos will use this as its priv vlan
Expand Down Expand Up @@ -108,30 +108,44 @@ var (
RunningMode: RunningDev,
SubstrateURL: []string{
"wss://tfchain.dev.grid.tf/",
"wss://tfchain.02.dev.grid.tf",
},
RelayURL: []string{
"wss://relay.dev.grid.tf",
"wss://relay.02.dev.grid.tf",
},
ActivationURL: "https://activation.dev.grid.tf/activation/activate",
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.dev",
GraphQL: "https://graphql.dev.grid.tf/graphql",
ActivationURL: []string{
"https://activation.dev.grid.tf/activation/activate",
"https://activation.02.dev.grid.tf/activation/activate",
},
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.dev",
GraphQL: []string{
"https://graphql.dev.grid.tf/graphql",
"https://graphql.02.dev.grid.tf/graphql",
},
}

envTest = Environment{
RunningMode: RunningTest,
SubstrateURL: []string{
"wss://tfchain.test.grid.tf/",
"wss://tfchain.02.test.grid.tf",
},
RelayURL: []string{
"wss://relay.test.grid.tf",
"wss://relay.02.test.grid.tf",
},
ActivationURL: "https://activation.test.grid.tf/activation/activate",
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.test",
GraphQL: "https://graphql.test.grid.tf/graphql",
ActivationURL: []string{
"https://activation.test.grid.tf/activation/activate",
"https://activation.02.test.grid.tf/activation/activate",
},
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.test",
GraphQL: []string{
"https://graphql.test.grid.tf/graphql",
"https://graphql.02.test.grid.tf/graphql",
},
}

envQA = Environment{
Expand All @@ -142,17 +156,25 @@ var (
},
RelayURL: []string{
"wss://relay.qa.grid.tf",
"wss://relay.02.qa.grid.tf",
},
ActivationURL: []string{
"https://activation.qa.grid.tf/activation/activate",
"https://activation.02.qa.grid.tf/activation/activate",
},
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.qanet",
GraphQL: []string{
"https://graphql.qa.grid.tf/graphql",
"https://graphql.02.qa.grid.tf/graphql",
},
ActivationURL: "https://activation.qa.grid.tf/activation/activate",
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins.qanet",
GraphQL: "https://graphql.qa.grid.tf/graphql",
}

envProd = Environment{
RunningMode: RunningMain,
SubstrateURL: []string{
"wss://tfchain.grid.tf/",
"wss://tfchain.02.grid.tf",
"wss://02.tfchain.grid.tf/",
"wss://03.tfchain.grid.tf/",
"wss://04.tfchain.grid.tf/",
Expand All @@ -161,10 +183,16 @@ var (
"wss://relay.grid.tf",
"wss://relay.02.grid.tf",
},
ActivationURL: "https://activation.grid.tf/activation/activate",
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins",
GraphQL: "https://graphql.grid.tf/graphql",
ActivationURL: []string{
"https://activation.grid.tf/activation/activate",
"https://activation.02.grid.tf/activation/activate",
},
FlistURL: "redis://hub.grid.tf:9900",
BinRepo: "tf-zos-v3-bins",
GraphQL: []string{
"https://graphql.grid.tf/graphql",
"https://graphql.02.grid.tf/graphql",
},
}
)

Expand Down Expand Up @@ -241,7 +269,7 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) {

if activation, ok := params.Get("activation"); ok {
if len(activation) > 0 {
env.ActivationURL = activation[len(activation)-1]
env.ActivationURL = activation
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/perf/healthcheck/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const defaultRequestTimeout = 5 * time.Second

func networkCheck(ctx context.Context) []error {
env := environment.MustGet()
servicesUrl := []string{
env.ActivationURL, env.GraphQL, env.FlistURL,
}
servicesUrl := []string{env.FlistURL}

servicesUrl = append(append(servicesUrl, env.SubstrateURL...), env.RelayURL...)
servicesUrl = append(append(servicesUrl, env.ActivationURL...), env.GraphQL...)

var errors []error

Expand Down
14 changes: 12 additions & 2 deletions pkg/perf/iperf/iperf_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,20 @@ func (t *IperfTest) Jitter() uint32 {
// Run runs the tcp test and returns the result
func (t *IperfTest) Run(ctx context.Context) (interface{}, error) {
env := environment.MustGet()
g := graphql.NewGraphQl(env.GraphQL)
var (
g graphql.GraphQl
err error
freeFarmNodes []graphql.Node
)

// get public up nodes
freeFarmNodes, err := g.GetUpNodes(ctx, 0, 1, 0, true, true)
for _, url := range env.GraphQL {
g = graphql.NewGraphQl(url)
freeFarmNodes, err = g.GetUpNodes(ctx, 0, 1, 0, true, true)
if err == nil {
break
}
}
if err != nil {
return nil, errors.Wrap(err, "failed to list freefarm nodes from graphql")
}
Expand Down
29 changes: 21 additions & 8 deletions pkg/perf/publicip/publicip_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ const (
FetchRealIPFailed = "failed to get real public IP to the node"
)

var errPublicIPLookup = errors.New("failed to reach public ip service")
var errSkippedValidating = errors.New("skipped, there is a node with less ID available")
var (
errPublicIPLookup = errors.New("failed to reach public ip service")
errSkippedValidating = errors.New("skipped, there is a node with less ID available")
)

const testMacvlan = "pub"
const testNamespace = "pubtestns"
const (
testMacvlan = "pub"
testNamespace = "pubtestns"
)

type publicIPValidationTask struct{}

Expand Down Expand Up @@ -96,7 +100,6 @@ func (p *publicIPValidationTask) Run(ctx context.Context) (interface{}, error) {
report, err = p.validateIPs(farm.PublicIPs)
return err
})

if err != nil {
return nil, fmt.Errorf("failed to run public IP validation: %w", err)
}
Expand Down Expand Up @@ -179,12 +182,23 @@ func (p *publicIPValidationTask) validateIPs(publicIPs []substrate.PublicIP) (ma

func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stubs.SubstrateGatewayStub) (bool, error) {
env := environment.MustGet()
gql := graphql.NewGraphQl(env.GraphQL)
var (
nodes []graphql.Node
err error
)

for _, url := range env.GraphQL {
gql := graphql.NewGraphQl(url)

nodes, err := gql.GetUpNodes(ctx, 0, farmID, 0, false, false)
nodes, err = gql.GetUpNodes(ctx, 0, farmID, 0, false, false)
if err == nil {
break
}
}
if err != nil {
return false, fmt.Errorf("failed to get farm %d nodes: %w", farmID, err)
}

cl := perf.GetZbusClient(ctx)
registrar := stubs.NewRegistrarStub(cl)
var nodeID uint32
Expand All @@ -196,7 +210,6 @@ func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stub
}
return nil
}, backoff.NewConstantBackOff(10*time.Second))

if err != nil {
return false, fmt.Errorf("failed to get node id: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/registrar/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ func registerNode(

sk := ed25519.PrivateKey(mgr.PrivateKey(ctx))

if _, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash); err != nil {
for _, url := range env.ActivationURL {
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
break
}
}
if err != nil {
return 0, 0, errors.Wrap(err, "failed to ensure account")
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/registrar/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen

func (r *Registrar) reActivate(ctx context.Context, cl zbus.Client, env environment.Environment) error {
substrateGateway := stubs.NewSubstrateGatewayStub(cl)
var err error

_, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash)
for _, url := range env.ActivationURL {
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
break
}
}

return err
}
Expand Down
2 changes: 1 addition & 1 deletion qemu/vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kernelargs=""
bridge=zos0
graphics="-nographic -nodefaults"
smp=1
mem=3
mem=2
tpm=0

usage() {
Expand Down

0 comments on commit ba93865

Please sign in to comment.