Skip to content

Commit

Permalink
retry metadata posting on 5xx errors
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Feb 16, 2017
1 parent 40e1882 commit 17a51cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 11 additions & 3 deletions command/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ func runMetadataLoop(c *Context, termMetadataCh <-chan struct{}, quit <-chan str
}

for _, result := range results {
err := c.API.PutMetadata(c.Host.ID, result.namespace, result.metadata)
resp, err := c.API.PutMetadata(c.Host.ID, result.namespace, result.metadata)
// retry on 5XX errors
if resp != nil && resp.StatusCode >= 500 {
logger.Errorf("put metadata %q failed: status %s", result.namespace, resp.Status)
resultCh <- &metadataResult{
namespace: result.namespace,
metadata: result.metadata,
}
continue
}
if err != nil {
logger.Errorf("put metadata %q failed: %s", result.namespace, err.Error())
// do not retry because huge metadata will be always rejected
logger.Errorf("put metadata %q failed: %v", result.namespace, err)
clearMetadataCache(c.Agent.MetadataGenerators, result.namespace)
continue
}
Expand Down
8 changes: 6 additions & 2 deletions mackerel/metadata.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package mackerel

import (
"net/http"
)

// PutMetadata creates or updates metadata of a host.
func (api *API) PutMetadata(hostID string, namespace string, metadata interface{}) error {
func (api *API) PutMetadata(hostID string, namespace string, metadata interface{}) (*http.Response, error) {
resp, err := api.putJSON("/api/v0/hosts/"+hostID+"/metadata/"+namespace, metadata)
defer closeResp(resp)

return err
return resp, err
}

0 comments on commit 17a51cb

Please sign in to comment.