-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add get/list probe command #204
Merged
+577
−261
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
efa5627
fix
shivam-Purohit 966e489
add get/list probe command
shivam-Purohit 7039f61
fix:fmt
shivam-Purohit 1b74e59
get-probes:add non-interactivte flag support
shivam-Purohit 534bf7c
fix:non-iteractive mode
shivam-Purohit 8f589e6
add probe-id flag for probe details
shivam-Purohit 6988455
improve logic for probe-id flag
shivam-Purohit 958a385
fix:filter query on listprobe command
shivam-Purohit a340bf3
fix:fmt
shivam-Purohit c970333
get probe:add more details
shivam-Purohit 4c5789f
refactor get probe command into smaller funcs
shivam-Purohit 9ad0d28
fix:double printing of break statement get probe
shivam-Purohit e2e6e5b
fix:fmt
shivam-Purohit 63818c8
remove toolchain
shivam-Purohit 263a556
fix swap created by/at
shivam-Purohit c3c3cbf
refactor the get probe cmd
shivam-Purohit b20fd7a
remove unnecessary fields from get probe query
shivam-Purohit 8546861
add referencedBy in output get probe
shivam-Purohit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,107 @@ | ||
package probe | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
"net/http" | ||
|
||
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
"github.com/litmuschaos/litmusctl/pkg/apis" | ||
"github.com/litmuschaos/litmusctl/pkg/types" | ||
"github.com/litmuschaos/litmusctl/pkg/utils" | ||
) | ||
|
||
func GetProbeRequest(pid string, probeID string, cred types.Credentials) (GetProbeResponse, error) { | ||
var gqlReq GetProbeGQLRequest | ||
gqlReq.Query = GetProbeQuery | ||
gqlReq.Variables.ProjectID = pid | ||
gqlReq.Variables.ProbeName = probeID | ||
|
||
query, err := json.Marshal(gqlReq) | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
resp, err := apis.SendRequest( | ||
apis.SendRequestParams{ | ||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, | ||
Token: cred.Token, | ||
}, | ||
query, | ||
string(types.Post), | ||
) | ||
|
||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
var getProbeResponse GetProbeResponse | ||
err = json.Unmarshal(bodyBytes, &getProbeResponse) | ||
if err != nil { | ||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error()) | ||
} | ||
if len(getProbeResponse.Errors) > 0 { | ||
return GetProbeResponse{}, errors.New(getProbeResponse.Errors[0].Message) | ||
} | ||
return getProbeResponse, nil | ||
|
||
} else { | ||
return GetProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes)) | ||
} | ||
|
||
} | ||
|
||
func ListProbeRequest(pid string, probetypes []*models.ProbeType, cred types.Credentials) (ListProbeResponse, error) { | ||
var gqlReq ListProbeGQLRequest | ||
gqlReq.Query = ListProbeQuery | ||
gqlReq.Variables.ProjectID = pid | ||
gqlReq.Variables.Filter = models.ProbeFilterInput{ | ||
Type: probetypes, | ||
} | ||
|
||
query, err := json.Marshal(gqlReq) | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
resp, err := apis.SendRequest( | ||
apis.SendRequestParams{ | ||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, | ||
Token: cred.Token, | ||
}, | ||
query, | ||
string(types.Post), | ||
) | ||
|
||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
var listProbeResponse ListProbeResponse | ||
err = json.Unmarshal(bodyBytes, &listProbeResponse) | ||
if err != nil { | ||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error()) | ||
} | ||
if len(listProbeResponse.Errors) > 0 { | ||
return ListProbeResponse{}, errors.New(listProbeResponse.Errors[0].Message) | ||
} | ||
return listProbeResponse, nil | ||
|
||
} else { | ||
return ListProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes)) | ||
} | ||
} |
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,77 @@ | ||
package probe | ||
|
||
const ( | ||
ListProbeQuery = `query ListProbes($projectID: ID!, $probeNames: [ID!], $filter: ProbeFilterInput) { | ||
listProbes(projectID: $projectID, probeNames: $probeNames, filter: $filter) { | ||
name | ||
type | ||
createdAt | ||
createdBy{ | ||
username | ||
} | ||
} | ||
} | ||
` | ||
GetProbeQuery = `query getProbe($projectID: ID!, $probeName: ID!) { | ||
getProbe(projectID: $projectID, probeName: $probeName) { | ||
name | ||
description | ||
type | ||
infrastructureType | ||
kubernetesHTTPProperties{ | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
kubernetesCMDProperties{ | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
k8sProperties { | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
promProperties { | ||
probeTimeout | ||
interval | ||
retry | ||
attempt | ||
probePollingInterval | ||
initialDelay | ||
evaluationTimeout | ||
stopOnFailure | ||
} | ||
createdAt | ||
createdBy{ | ||
username | ||
} | ||
updatedAt | ||
updatedBy{ | ||
username | ||
} | ||
tags | ||
} | ||
} | ||
` | ||
DeleteProbeQuery = `mutation deleteProbe($probeName: ID!, $projectID: ID!) { | ||
deleteProbe(probeName: $probeName, projectID: $projectID) | ||
} | ||
` | ||
) |
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,43 @@ | ||
package probe | ||
|
||
import model "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
|
||
type GetProbeGQLRequest struct { | ||
Query string `json:"query"` | ||
Variables struct { | ||
ProjectID string `json:"projectID"` | ||
ProbeName string `json:"probeName"` | ||
} `json:"variables"` | ||
} | ||
|
||
type GetProbeResponse struct { | ||
Errors []struct { | ||
Message string `json:"message"` | ||
Path []string `json:"path"` | ||
} `json:"errors"` | ||
Data GetProbeResponseData `json:"data"` | ||
} | ||
|
||
type GetProbeResponseData struct { | ||
GetProbe model.Probe `json:"getProbe"` | ||
} | ||
|
||
type ListProbeGQLRequest struct { | ||
Query string `json:"query"` | ||
Variables struct { | ||
ProjectID string `json:"projectID"` | ||
Filter model.ProbeFilterInput `json:"filter"` | ||
} `json:"variables"` | ||
} | ||
|
||
type ListProbeResponse struct { | ||
Errors []struct { | ||
Message string `json:"message"` | ||
Path []string `json:"path"` | ||
} `json:"errors"` | ||
Data ListProbeResponseData `json:"data"` | ||
} | ||
|
||
type ListProbeResponseData struct { | ||
Probes []model.Probe `json:"listProbes"` | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using all the properties? If not, then we can consider removing them from query