Skip to content

Commit

Permalink
return json header for build endpoint, some minor cleanups (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
talgendler authored Apr 28, 2021
1 parent c846f19 commit 9300677
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,4 @@ jobs:
run: |
tail -n1 coverage-summary.txt | awk '{print "Coverage summary: " $3}'
- name: Codecov
# You may pin to the exact commit or the version.
# uses: codecov/codecov-action@6004246f47ab62d32be025ce173b241cd84ac58e
uses: codecov/[email protected]

# with:
# # User defined upload name. Visible in Codecov UI
# name: # optional
# # Repository upload token - get it from codecov.io. Required only for private repositories
# token: # optional
# # Path to coverage file to upload
# file: # optional
# # Comma-separated list of files to upload
# files: # optional
# # Directory to search for coverage reports.
# directory: # optional
# # Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)
# flags: # optional
# # Write upload file to path before uploading
# path_to_write_report: # optional
# # Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)
# env_vars: # optional
# # Specify whether or not CI build should fail if Codecov runs into an error during upload
# fail_ci_if_error: # optional
9 changes: 5 additions & 4 deletions handlers/debug.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"context"
"encoding/json"
"expvar"
"io/ioutil"
Expand Down Expand Up @@ -58,19 +59,19 @@ func (d *debugHandlersDeps) DumpFunc() http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
file, err := ioutil.TempFile("", "heapdump")
if err != nil {
d.Logger.WithError(err).Info(nil, "failed to create temp file to dump heap into")
d.Logger.WithError(err).Info(context.TODO(), "failed to create temp file to dump heap into")
http.Error(w, "internal error, failed to serve heap dump", http.StatusInternalServerError)
return
}
defer func(logger log.Logger, tempFile *os.File) {
if err := os.Remove(tempFile.Name()); err != nil {
logger.WithError(err).WithField("tempfile", tempFile.Name()).Warn(nil, "failed to remove temp file")
logger.WithError(err).WithField("tempfile", tempFile.Name()).Warn(context.TODO(), "failed to remove temp file")
}
}(d.Logger, file) // remove garbage
debug.WriteHeapDump(file.Fd())
http.ServeFile(w, req, file.Name())
if err = file.Close(); err != nil {
d.Logger.WithError(err).WithField("tempfile", file.Name()).Warn(nil, "temp file wasn't closed")
d.Logger.WithError(err).WithField("tempfile", file.Name()).Warn(context.TODO(), "temp file wasn't closed")
}
}
}
Expand All @@ -85,7 +86,7 @@ func (d *debugHandlersDeps) Stats() http.HandlerFunc {
}
runtime.ReadMemStats(output.Memory)
if err := json.NewEncoder(w).Encode(output); err != nil {
d.Logger.WithError(err).Debug(nil, "failed to serve stats")
d.Logger.WithError(err).Debug(context.TODO(), "failed to serve stats")
w.WriteHeader(http.StatusInternalServerError)
}
}
Expand Down
6 changes: 4 additions & 2 deletions handlers/self.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -39,9 +40,10 @@ func SelfHandlers(deps selfHandlerDeps) []partial.HTTPHandlerPatternPair {
func (s *selfHandlerDeps) BuildInfo() http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
information := mortar.GetBuildInformation(true)
w.Header().Set("Content-type", "application/json; charset=utf-8")
if err := json.NewEncoder(w).Encode(information); err != nil {
w.WriteHeader(http.StatusInternalServerError)
s.Logger.WithError(err).Warn(nil, "failed to serve build info")
s.Logger.WithError(err).Warn(context.TODO(), "failed to serve build info")
}
}
}
Expand All @@ -54,7 +56,7 @@ func (s *selfHandlerDeps) ConfigMap() http.HandlerFunc {
output["environment"] = s.getEnvVariables()
if err := json.NewEncoder(w).Encode(output); err != nil {
w.WriteHeader(http.StatusInternalServerError)
s.Logger.WithError(err).Warn(nil, "failed to server config map")
s.Logger.WithError(err).Warn(context.TODO(), "failed to server config map")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type ProtobufHTTPClient interface {
// Error returned will be of type `(*status.Status).Err()` meaning it will be a gRPC type error.
//
// Note:
// // you can pass `nil` as the last parameter if you don't want to unmarshal HTTP response body.
// // or you know it's going to be empty == EOF
// you can pass `nil` as the last parameter if you don't want to unmarshal HTTP response body.
// or you know it's going to be empty == EOF
// err := Do(ctx, http.MethodPost, "http://host/path", request, nil)
Do(ctx context.Context, method, url string, in proto.Message, out interface{}) error
}
Expand Down

0 comments on commit 9300677

Please sign in to comment.