github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/test/e2e/pkg/infrastructure.go (about) 1 package e2e 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "net" 7 "os" 8 ) 9 10 const ( 11 dockerIPv4CIDR = "10.186.73.0/24" 12 dockerIPv6CIDR = "fd80:b10c::/48" 13 14 globalIPv4CIDR = "0.0.0.0/0" 15 ) 16 17 // InfrastructureData contains the relevant information for a set of existing 18 // infrastructure that is to be used for running a testnet. 19 type InfrastructureData struct { 20 21 // Provider is the name of infrastructure provider backing the testnet. 22 // For example, 'docker' if it is running locally in a docker network or 23 // 'digital-ocean', 'aws', 'google', etc. if it is from a cloud provider. 24 Provider string `json:"provider"` 25 26 // Instances is a map of all of the machine instances on which to run 27 // processes for a testnet. 28 // The key of the map is the name of the instance, which each must correspond 29 // to the names of one of the testnet nodes defined in the testnet manifest. 30 Instances map[string]InstanceData `json:"instances"` 31 32 // Network is the CIDR notation range of IP addresses that all of the instances' 33 // IP addresses are expected to be within. 34 Network string `json:"network"` 35 36 // InfluxDBURL is the URL of the InfluxDB instance to use for arbitrary data 37 // collection. If not specified, data will not be collected. 38 InfluxDBURL string `json:"influxdb_url,omitempty"` 39 40 // InfluxDBToken is the token to use when writing to the InfluxDB instance. 41 // Must be specified if 'influxdb-url' is specified. 42 InfluxDBToken string `json:"influxdb_token,omitempty"` 43 44 // PyroscopeURL is the URL of the pyroscope instance to use for continuous 45 // profiling. If not specified, data will not be collected. 46 PyroscopeURL string `json:"pyroscope_url,omitempty"` 47 48 // PyroscopeTrace enables adding trace data to pyroscope profiling. 49 PyroscopeTrace bool `json:"pyroscope_trace,omitempty"` 50 51 // PyroscopeProfileTypes is the list of profile types to collect. 52 PyroscopeProfileTypes string `json:"pyroscope_profile_types,omitempty"` 53 } 54 55 // InstanceData contains the relevant information for a machine instance backing 56 // one of the nodes in the testnet. 57 type InstanceData struct { 58 IPAddress net.IP `json:"ip_address"` 59 } 60 61 func NewDockerInfrastructureData(m Manifest) (InfrastructureData, error) { 62 netAddress := dockerIPv4CIDR 63 if m.IPv6 { 64 netAddress = dockerIPv6CIDR 65 } 66 _, ipNet, err := net.ParseCIDR(netAddress) 67 if err != nil { 68 return InfrastructureData{}, fmt.Errorf("invalid IP network address %q: %w", netAddress, err) 69 } 70 ipGen := newIPGenerator(ipNet) 71 ifd := InfrastructureData{ 72 Provider: "docker", 73 Instances: make(map[string]InstanceData), 74 Network: netAddress, 75 } 76 for name := range m.Nodes { 77 ifd.Instances[name] = InstanceData{ 78 IPAddress: ipGen.Next(), 79 } 80 } 81 return ifd, nil 82 } 83 84 func InfrastructureDataFromFile(p string) (InfrastructureData, error) { 85 ifd := InfrastructureData{} 86 b, err := os.ReadFile(p) 87 if err != nil { 88 return InfrastructureData{}, err 89 } 90 err = json.Unmarshal(b, &ifd) 91 if err != nil { 92 return InfrastructureData{}, err 93 } 94 if ifd.Network == "" { 95 ifd.Network = globalIPv4CIDR 96 } 97 return ifd, nil 98 }