-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
@@ -28,56 +26,6 @@ func HeadCommit(path string) (string, error) { | |||
return strings.Trim(string(output), "\n"), err | |||
} | |||
|
|||
func formatGitURL(endpoint, branch string) string { |
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.
I moved these two functions so that they could be attached to a struct so that I could reuse an http client, as opposed to creating a new client on each request, as it was previously doing.
res, err := m.httpClient.Do(req) | ||
if err != nil { | ||
// Return timeout errors so caller can decide whether or not to proceed with updating the repo | ||
if uErr, ok := err.(*url.Error); ok && uErr.Timeout() { |
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.
I chose to only bubble up the error if it was explicitly a timeout error. The goal is to prevent the next step of doing a git fetch or clone from also timing out (which will take much logner). For non-timeout errors, the thinking is that the clone/fetch will either fail the same way or it wont.
} | ||
|
||
func NewManager(cacheRoot string, configFile string, strict bool, db *gorm.DB, uuid string) *Manager { | ||
client := http.Client{ | ||
Timeout: time.Second * 10, |
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.
This client is used for doing the remote sha checking. Is 10 seconds a safe amount of time to wait for a response?
This pulls in a change to automatically copy most headers on http redirects. We had a custom redirect handler doing this, but can now remove it.
d2d2b1a
to
09396e5
Compare
Swallow fewer errors. Add meaningful context to errors. Properly return 500 response codes on calls to the refresh API if the refresh fails.
09396e5
to
8dbce43
Compare
@@ -173,20 +173,26 @@ func formatDSN(user, password, address, dbname, params string) string { | |||
return mysqlConfig.FormatDSN() | |||
} | |||
|
|||
func refresh(m *manager.Manager, update bool) { |
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.
I moved this function simply because there were a bunch of functions with "refresh" in their name and it was quite confusing. I wanted to make it obvious that this function served no purpose other than wrapping the call to RefreshAll and logging the result in the context of autorefresh
if err = git.Update(repoPath, branch); err != nil { | ||
// Ignore error unless running in strict mode | ||
if m.strict { |
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.
Is strict mode always on now?
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.
No, strict mode is still only turned on for validating catalogs. But as far as I can tell, its primary purpose is to validate the yaml files themselves. That it still controlled by the strict flag.
I removed the strict check here to accomplish the following:
If an error is encountered when updating an existing catalog that prevents us from updating the local git repo do not perform a DB update of the catalogs/templates. Previous behavior was to go ahead an update the db entries again, even though the git fetch failed.
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.
Got it. This makes sense.
@@ -71,11 +86,11 @@ func (m *Manager) refreshConfigCatalogs(update bool) error { | |||
catalog = existingCatalog | |||
} | |||
if err := m.refreshCatalog(catalog, update); err != nil { | |||
refreshErrors = append(refreshErrors, fmt.Sprintf("%s: %v", catalog.Name, err)) | |||
refreshErrors = append(refreshErrors, errors.Wrapf(err, "Catalog refresh failed for %v (%v)", catalog.Name, catalog.URL)) |
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.
First should be %s
, right? Not sure if it really matters.
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.
doesnt matter. %v
on a string gets you the string
LGTM. Error handling is much nicer now. |
Addresses rancher/rancher#9669 (and then some)
I ended up revamping our error handling a bit.
The end result is:
refresh
api will now return 500 if the update failed. Previously, it would always return 200.You used to get:
you now get: