From 30644fcc01df7748d8e2ae15c427f01702dd4e90 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 6 Sep 2018 16:07:13 -0400 Subject: [PATCH] api: remove dependency on graceful This library has no longer been needed since Go 1.8. --- api/api.go | 39 +++---------- bill-of-materials.json | 127 ++++++++++++----------------------------- glide.lock | 18 +++--- glide.yaml | 2 - 4 files changed, 55 insertions(+), 131 deletions(-) diff --git a/api/api.go b/api/api.go index 960235b7..ade080a2 100644 --- a/api/api.go +++ b/api/api.go @@ -15,15 +15,14 @@ package api import ( + "context" "crypto/tls" "crypto/x509" "io/ioutil" - "net" "net/http" "time" log "github.com/sirupsen/logrus" - "github.com/tylerb/graceful" "github.com/coreos/clair/api/v3" "github.com/coreos/clair/database" @@ -61,42 +60,22 @@ func RunHealth(cfg *Config, store database.Datastore, st *stopper.Stopper) { } log.WithField("addr", cfg.HealthAddr).Info("starting health API") - srv := &graceful.Server{ - Timeout: 10 * time.Second, // Interrupt health checks when stopping - NoSignalHandling: true, // We want to use our own Stopper - Server: &http.Server{ - Addr: cfg.HealthAddr, - Handler: http.TimeoutHandler(newHealthHandler(store), cfg.Timeout, timeoutResponse), - }, + srv := http.Server{ + Addr: cfg.HealthAddr, + Handler: http.TimeoutHandler(newHealthHandler(store), cfg.Timeout, timeoutResponse), } - listenAndServeWithStopper(srv, st, "", "") - - log.Info("health API stopped") -} - -// listenAndServeWithStopper wraps graceful.Server's -// ListenAndServe/ListenAndServeTLS and adds the ability to interrupt them with -// the provided stopper.Stopper. -func listenAndServeWithStopper(srv *graceful.Server, st *stopper.Stopper, certFile, keyFile string) { go func() { <-st.Chan() - srv.Stop(0) + srv.Shutdown(context.TODO()) }() - var err error - if certFile != "" && keyFile != "" { - log.Info("API: TLS Enabled") - err = srv.ListenAndServeTLS(certFile, keyFile) - } else { - err = srv.ListenAndServe() + err := srv.ListenAndServe() + if err != nil && err != http.ErrServerClosed { + log.Fatal(err) } - if err != nil { - if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") { - log.Fatal(err) - } - } + log.Info("health API stopped") } // tlsClientConfig initializes a *tls.Config using the given CA. The resulting diff --git a/bill-of-materials.json b/bill-of-materials.json index 374469ed..8242f77f 100644 --- a/bill-of-materials.json +++ b/bill-of-materials.json @@ -1,132 +1,77 @@ [ { - "project": "github.com/beorn7/perks/quantile", - "licenses": [ - { - "type": "MIT License", - "confidence": 0.9891304347826086 - } - ] + "project": "github.com/coreos/clair", + "license": "Apache License 2.0", + "confidence": 1 }, { - "project": "github.com/coreos/clair", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "project": "github.com/beorn7/perks/quantile", + "license": "MIT License", + "confidence": 0.989 }, { "project": "github.com/coreos/pkg/timeutil", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "license": "Apache License 2.0", + "confidence": 1 }, { "project": "github.com/golang/protobuf/proto", - "licenses": [ - { - "type": "BSD 3-clause \"New\" or \"Revised\" License", - "confidence": 0.92 - } - ] + "license": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 0.92 + }, + { + "project": "github.com/google/uuid", + "license": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 0.966 }, { "project": "github.com/matttproud/golang_protobuf_extensions/pbutil", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "license": "Apache License 2.0", + "confidence": 1 }, { "project": "github.com/pborman/uuid", - "licenses": [ - { - "type": "BSD 3-clause \"New\" or \"Revised\" License", - "confidence": 0.9663865546218487 - } - ] + "license": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 0.966 }, { "project": "github.com/prometheus/client_golang/prometheus", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "license": "Apache License 2.0", + "confidence": 1 }, { "project": "github.com/prometheus/client_model/go", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "license": "Apache License 2.0", + "confidence": 1 }, { "project": "github.com/prometheus/common", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "license": "Apache License 2.0", + "confidence": 1 }, { - "project": "github.com/prometheus/procfs", - "licenses": [ - { - "type": "Apache License 2.0", - "confidence": 1 - } - ] + "project": "github.com/prometheus/procfs/xfs", + "license": "Apache License 2.0", + "confidence": 1 }, { "project": "github.com/sirupsen/logrus", - "licenses": [ - { - "type": "MIT License", - "confidence": 1 - } - ] + "license": "MIT License", + "confidence": 1 }, { "project": "github.com/stretchr/testify/assert", - "licenses": [ - { - "type": "MIT License", - "confidence": 0.9430051813471503 - }, - { - "type": "MIT License", - "confidence": 0.9430051813471503 - } - ] + "license": "MIT License", + "confidence": 0.943 }, { "project": "github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew", - "licenses": [ - { - "type": "ISC License", - "confidence": 0.9850746268656716 - } - ] + "license": "ISC License", + "confidence": 0.985 }, { "project": "github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib", - "licenses": [ - { - "type": "BSD 3-clause \"New\" or \"Revised\" License", - "confidence": 0.9830508474576272 - } - ] + "license": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 0.983 } ] diff --git a/glide.lock b/glide.lock index 1c864a32..73e38f49 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: b5b9ebebad30becd361736196a015af23b1d9a616a375c7fc13823121fd17226 -updated: 2017-06-05T16:11:29.019891941-04:00 +hash: 9bf7ad53b92119a17068b8724d9b406a7ca84b5bfcd0baba44b08c696a538b14 +updated: 2018-09-06T15:58:19.234504-04:00 imports: - name: github.com/beorn7/perks version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 @@ -23,9 +23,13 @@ imports: - jsonpb - proto - protoc-gen-go/descriptor + - ptypes - ptypes/any - - ptypes/empty + - ptypes/duration - ptypes/struct + - ptypes/timestamp +- name: github.com/google/uuid + version: e704694aed0ea004bb7eb1fc2e911d048a54606a - name: github.com/grpc-ecosystem/go-grpc-prometheus version: 2500245aa6110c562d17020fb31a2c133d737799 - name: github.com/grpc-ecosystem/grpc-gateway @@ -35,7 +39,7 @@ imports: - runtime/internal - utilities - name: github.com/guregu/null - version: 41961cea0328defc5f95c1c473f89ebf0d1813f6 + version: 80515d440932108546bcade467bb7d6968e812e2 subpackages: - zero - name: github.com/hashicorp/golang-lru @@ -53,7 +57,7 @@ imports: subpackages: - pbutil - name: github.com/pborman/uuid - version: a97ce2ca70fa5a848076093f05e639a89ca34d06 + version: adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1 - name: github.com/pmezard/go-difflib version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: @@ -81,11 +85,9 @@ imports: - name: github.com/sirupsen/logrus version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f - name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 + version: f35b8ab0b5a2cef36673838d662e249dd9c94686 subpackages: - assert -- name: github.com/tylerb/graceful - version: 4654dfbb6ad53cb5e27f37d99b02e16c1872fbbb - name: golang.org/x/net version: 59a0b19b5533c7977ddeb86b017bf507ed407b12 subpackages: diff --git a/glide.yaml b/glide.yaml index d67189b3..e5956e18 100644 --- a/glide.yaml +++ b/glide.yaml @@ -26,7 +26,5 @@ import: version: ^1.1.4 subpackages: - assert -- package: github.com/tylerb/graceful - version: ^1.2.15 - package: gopkg.in/yaml.v2 - package: github.com/cockroachdb/cmux