-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refac: Include e2e monitoring stack tests
- Loading branch information
1 parent
07390d3
commit b53a947
Showing
7 changed files
with
205 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2022 Nethermind | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package e2e | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/NethermindEth/sedge/internal/pkg/services" | ||
"github.com/NethermindEth/sedge/internal/utils" | ||
"github.com/docker/docker/client" | ||
) | ||
|
||
func dataDirPath() (string, error) { | ||
userDataHome := os.Getenv("XDG_DATA_HOME") | ||
if userDataHome == "" { | ||
userHome, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
userDataHome = filepath.Join(userHome, ".local", "share") | ||
} | ||
return filepath.Join(userDataHome, ".sedge"), nil | ||
} | ||
|
||
type Target struct { | ||
Labels Labels `json:"labels"` | ||
Health string `json:"health"` | ||
} | ||
|
||
type Labels map[string]string | ||
|
||
type Data struct { | ||
ActiveTargets []Target `json:"activeTargets"` | ||
} | ||
|
||
type PrometheusTargetsResponse struct { | ||
Status string `json:"status"` | ||
Data Data `json:"data"` | ||
} | ||
|
||
func prometheusTargets(t *testing.T) (*PrometheusTargetsResponse, error) { | ||
response, err := utils.GetRequest("http://localhost:9090/api/v1/targets", time.Second) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if response.StatusCode != 200 { | ||
return nil, fmt.Errorf("prometheus targets status code should be 200") | ||
} | ||
var r PrometheusTargetsResponse | ||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(body, &r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &r, nil | ||
} | ||
|
||
func getContainerIDByName(containerName string) (string, error) { | ||
cli, err := client.NewClientWithOpts( | ||
client.FromEnv, | ||
client.WithAPIVersionNegotiation(), | ||
) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer cli.Close() | ||
|
||
dockerServiceManager := services.NewDockerServiceManager(cli) | ||
|
||
containerID, err := dockerServiceManager.ContainerID(containerName) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return containerID, nil | ||
} |
Oops, something went wrong.