Skip to content
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

Catch more error types in the insights proxy. #1876

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci_oci-env-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
run: |
echo "OCI_ENV_PATH=${HOME}/work/galaxy_ng/oci_env" >> $GITHUB_ENV
echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV
echo "OCI_VERBOSE=1" >> $GITHUB_ENV
echo "GH_DUMP_LOGS=1" >> $GITHUB_ENV

- name: Update apt
run: sudo apt -y update
Expand Down
12 changes: 7 additions & 5 deletions dev/oci_env_integration/actions/action_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OCIEnvIntegrationTest:
do_teardown = True
flags = ""
envs = {}
failed = None

def __init__(self, envs):
for env in envs:
Expand All @@ -59,18 +60,18 @@ def __init__(self, envs):
self.do_teardown = os.environ.get("GH_TEARDOWN", "1") == "1"
self.flags = os.environ.get("GH_FLAGS", "")

failed = False
self.failed = False
try:
self.set_up_env()
self.run_test()
except Exception as e:
print(e)
failed = True
self.failed = True
finally:
self.dump_logs()
self.teardown()

if failed:
if self.failed:
exit(1)

def set_up_env(self):
Expand Down Expand Up @@ -129,8 +130,9 @@ def run_test(self):
def dump_logs(self):
if not self.do_dump_logs:
return
for env in self.envs:
self.exec_cmd(env, "compose logs")
if self.failed:
for env in self.envs:
self.exec_cmd(env, "compose logs")

def teardown(self):
if not self.do_teardown:
Expand Down
44 changes: 43 additions & 1 deletion profiles/insights/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
Expand Down Expand Up @@ -223,6 +224,25 @@ func isConnectionResetByPeer(err error) bool {
return false
}

func isUseOfClosedNetworkConnection(err error) bool {
return strings.Contains(err.Error(), "use of closed network connection")
}

func isWriteBrokenPipe(err error) bool {
return strings.Contains(err.Error(), "write: broken pipe")
}

func isInvalidReadOnClosedBody(err error) bool {
return strings.Contains(err.Error(), "invalid Read on closed Body")
}

func isEOFerror(err error) bool {
if err == io.EOF {
return true
}
return false
}

func retryHTTPRequest(client *http.Client, req *http.Request, maxRetries int) (*http.Response, error) {
for retry := 0; retry < maxRetries; retry++ {
resp, err := client.Do(req)
Expand All @@ -237,6 +257,26 @@ func retryHTTPRequest(client *http.Client, req *http.Request, maxRetries int) (*
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
if isUseOfClosedNetworkConnection(err) {
fmt.Printf("Retry attempt %d: use of closed network connection\n", retry+1)
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
if isWriteBrokenPipe(err) {
fmt.Printf("Retry attempt %d: write broken pipe\n", retry+1)
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
if isInvalidReadOnClosedBody(err) {
fmt.Printf("Retry attempt %d: invalid read on closed body\n", retry+1)
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
if isEOFerror(err) {
fmt.Printf("Retry attempt %d: EOF error\n", retry+1)
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
return nil, err
}

Expand All @@ -247,7 +287,7 @@ func retryHTTPRequest(client *http.Client, req *http.Request, maxRetries int) (*
}

func main() {
fmt.Println("Staring insights proxy.")
fmt.Println("Starting insights proxy.")

// define origin server URL
urlToProxyTo, err := url.Parse(getEnv("UPSTREAM_URL", "http://localhost:5001"))
Expand Down Expand Up @@ -326,6 +366,8 @@ func main() {
data, _ := ioutil.ReadAll(upstreamServerResponse.Body)
modified := downloadUrlReg.ReplaceAll(data, replacementURL)

fmt.Printf("MODIFIED DATA: %s\n", modified)

// Write the response
rw.WriteHeader(upstreamServerResponse.StatusCode)
rw.Write(modified)
Expand Down
Loading