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

Moving location of statuszTmpl #206

Merged
merged 9 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM gcr.io/distroless/static:latest
LABEL maintainer "Stackdriver Engineering <engineering@stackdriver.com>"

COPY stackdriver-prometheus-sidecar /bin/stackdriver-prometheus-sidecar
COPY cmd/stackdriver-prometheus-sidecar/statusz-tmpl.html /statusz-tmpl.html

EXPOSE 9091
ENTRYPOINT [ "/bin/stackdriver-prometheus-sidecar" ]
12 changes: 12 additions & 0 deletions cmd/stackdriver-prometheus-sidecar/statik/statik.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion cmd/stackdriver-prometheus-sidecar/statusz.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate statik -src=./ -include=*.html
package main

import (
"html/template"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"time"

_ "github.com/Stackdriver/stackdriver-prometheus-sidecar/cmd/stackdriver-prometheus-sidecar/statik"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/common/version"
"github.com/rakyll/statik/fs"
)

var (
serverStart = time.Now()
statuszTmpl = template.Must(template.ParseFiles("statusz-tmpl.html"))
statuszTmpl *template.Template
)

type statuszHandler struct {
Expand All @@ -36,6 +41,25 @@ type statuszHandler struct {
cfg *mainConfig
}

func init() {
statikFS, err := fs.New()
if err != nil {
panic(err)
}
statuszFile, err := statikFS.Open("/statusz-tmpl.html")
if err != nil {
panic(err)
}
contents, err := ioutil.ReadAll(statuszFile)
if err != nil {
panic(err)
}
statuszTmpl, err = template.New("statusz-tmpl.html").Parse(string(contents))
if err != nil {
panic(err)
}
}

func (h *statuszHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var data struct {
ServerName string
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
github.com/prometheus/procfs v0.0.3 // indirect
github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d
github.com/prometheus/tsdb v0.10.0
github.com/rakyll/statik v0.1.6
github.com/rogpeppe/go-internal v1.5.0 // indirect
github.com/samuel/go-zookeeper v0.0.0-20190801204459-3c104360edc8 // indirect
github.com/shopspring/decimal v0.0.0-20191125035519-b054a8dfd10d // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d/go.mod h1:11
github.com/prometheus/tsdb v0.9.1/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4=
github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic=
github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4=
github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs=
github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rlmcpherson/s3gof3r v0.5.0/go.mod h1:s7vv7SMDPInkitQMuZzH615G7yWHdrU2r/Go7Bo71Rs=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
202 changes: 202 additions & 0 deletions vendor/github.com/rakyll/statik/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading