-
Notifications
You must be signed in to change notification settings - Fork 130
chore: add support for vcr compression and trim k8s cassettes #3136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f406ed3
chore: add support for vcr compression and trim k8s cassettes
remyleone 0f14c82
Fix
remyleone 2033540
Fix linter
remyleone 5a99dd0
Fix i18n for error message
remyleone b279bfa
Apply review suggestions
remyleone 53f055d
Apply review suggestions
remyleone ac76827
Fix lint
remyleone b518d24
add documentation
remyleone c90db79
Fix useless continue
remyleone 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 hidden or 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 hidden or 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,104 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1" | ||
"gopkg.in/dnaeon/go-vcr.v3/cassette" | ||
) | ||
|
||
var transientStates = map[string]bool{ | ||
k8s.ClusterStatusCreating.String(): true, | ||
k8s.ClusterStatusDeleting.String(): true, | ||
k8s.ClusterStatusUpdating.String(): true, | ||
k8s.PoolStatusDeleting.String(): true, | ||
k8s.PoolStatusScaling.String(): true, | ||
k8s.PoolStatusUpgrading.String(): true, | ||
} | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatalf("Usage: %s <cassette_file_name_without_yaml>\n", os.Args[0]) | ||
} | ||
|
||
path := os.Args[1] | ||
|
||
inputCassette, err := cassette.Load(path) | ||
if err != nil { | ||
log.Fatalf("Error while reading file : %v\n", err) | ||
} | ||
|
||
outputCassette := cassette.New(path) | ||
transitioning := false | ||
|
||
for i := range len(inputCassette.Interactions) { | ||
interaction := inputCassette.Interactions[i] | ||
responseBody := interaction.Response.Body | ||
requestMethod := interaction.Request.Method | ||
|
||
if requestMethod != "GET" { | ||
transitioning = false | ||
|
||
log.Printf("Interaction %d is not a GET request. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
if responseBody == "" { | ||
log.Printf("Interaction %d got an empty response body. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
var m map[string]interface{} | ||
|
||
err := json.Unmarshal([]byte(responseBody), &m) | ||
if err != nil { | ||
log.Printf("Interaction %d have an error with unmarshalling response body: %v. Recording it\n", i, err) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
if m["status"] == nil { | ||
log.Printf("Interaction %d does not contain a status field. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
status := m["status"].(string) | ||
Gnoale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We test if the state is transient | ||
if _, ok := transientStates[status]; ok { | ||
if transitioning { | ||
log.Printf("Interaction %d is in a transient state while we are already in transitient state. No need to record it: %s\n", i, status) | ||
} else { | ||
log.Printf("Interaction %d is in a transient state: %s, Recording it\n", i, status) | ||
|
||
transitioning = true | ||
|
||
outputCassette.AddInteraction(interaction) | ||
} | ||
} else { | ||
if transitioning { | ||
log.Printf("Interaction %d is not in a transient state anymore: %s, Recording it\n", i, status) | ||
|
||
outputCassette.AddInteraction(interaction) | ||
|
||
transitioning = false | ||
} else { | ||
log.Printf("Interaction %d is not in a transient state: %s, Recording it\n", i, status) | ||
outputCassette.AddInteraction(interaction) | ||
} | ||
} | ||
} | ||
|
||
err = outputCassette.Save() | ||
if err != nil { | ||
log.Fatalf("error while saving file: %v", err) | ||
} | ||
} |
This file contains hidden or 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,55 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"gopkg.in/dnaeon/go-vcr.v3/cassette" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatalf("Usage: %s <cassette_file_name_without_yaml>\n", os.Args[0]) | ||
} | ||
|
||
path := os.Args[1] | ||
|
||
data, err := cassette.Load(path) | ||
if err != nil { | ||
log.Fatalf("Error while reading file: %v\n", err) | ||
} | ||
|
||
for i := range len(data.Interactions) { | ||
interaction := data.Interactions[i] | ||
|
||
log.Println("--------------") | ||
log.Printf("Interaction %d:\n", i+1) | ||
log.Printf(" Request:\n") | ||
log.Printf(" Method: %s\n", interaction.Request.Method) | ||
log.Printf(" URL: %s\n", interaction.Request.URL) | ||
|
||
if interaction.Request.Body != "" { | ||
log.Printf(" Body: %s\n", interaction.Request.Body) | ||
} | ||
|
||
log.Printf(" Response:\n") | ||
log.Printf(" Status: %s\n", interaction.Response.Status) | ||
log.Printf(" Body: %s\n", interaction.Response.Body) | ||
|
||
var m map[string]interface{} | ||
|
||
err := json.Unmarshal([]byte(interaction.Response.Body), &m) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if m["status"] != nil { | ||
log.Println("++++++++++++++++") | ||
log.Printf("status: %s\n", m["status"]) | ||
log.Println("++++++++++++++++") | ||
} | ||
|
||
log.Println("--------------") | ||
} | ||
} |
6,798 changes: 165 additions & 6,633 deletions
6,798
internal/services/k8s/testdata/cluster-multicloud.cassette.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
5,519 changes: 2,013 additions & 3,506 deletions
5,519
internal/services/k8s/testdata/cluster-pool-private-network.cassette.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.