Skip to content

Commit

Permalink
Integrate Google Cloud Monitoring export
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Reinartz authored and fabxc committed Sep 17, 2021
1 parent b094459 commit 655bb33
Show file tree
Hide file tree
Showing 15 changed files with 1,003 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.gitignore
#!include:.gitignore
29 changes: 0 additions & 29 deletions .github/workflows/fuzzing.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ npm_licenses.tar.bz2
/web/ui/static/react
/web/ui/assets_vfsdata.go

/vendor
/.build

!/web/ui/react-app/node_modules/**/#
63 changes: 48 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>"

ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/prometheus /bin/prometheus
COPY .build/${OS}-${ARCH}/promtool /bin/promtool
ARG IMAGE_BUILD_NODEJS=launcher.gcr.io/google/nodejs
ARG IMAGE_BUILD_GO=golang:1.15-buster
ARG IMAGE_BASE_DEBUG=gcr.io/distroless/static-debian10:debug
ARG IMAGE_BASE=gcr.io/distroless/static-debian10

FROM ${IMAGE_BUILD_GO} AS gobase

# Compile the UI assets.
FROM ${IMAGE_BUILD_NODEJS} as assets
# To build the UI we need a recent node version and the go toolchain.
RUN install_node v14.16.1
COPY --from=gobase /usr/local/go /usr/local/
ENV PATH="/usr/local/go/bin:${PATH}"
WORKDIR /app
COPY . ./
RUN make assets
RUN make npm_licenses

# Build the actual Go binary.
FROM gobase as buildbase
WORKDIR /app
COPY --from=assets /app ./
RUN CGO_ENABLED=0 go build \
-tags builtinassets -mod=vendor \
-ldflags="-X main.Version=$(cat VERSION)" \
./cmd/prometheus
RUN CGO_ENABLED=0 go build \
-mod=vendor \
-ldflags="-X main.Version=$(cat VERSION)" \
./cmd/promtool

# Configure distroless base image like the upstream Prometheus image.
# Since the directory and symlink setup needs shell access, we need yet another
# intermediate stage.
FROM ${IMAGE_BASE_DEBUG} as appbase

COPY documentation/examples/prometheus.yml /etc/prometheus/prometheus.yml
COPY console_libraries/ /usr/share/prometheus/console_libraries/
COPY consoles/ /usr/share/prometheus/consoles/
COPY LICENSE /LICENSE
COPY NOTICE /NOTICE
COPY npm_licenses.tar.bz2 /npm_licenses.tar.bz2
RUN ["/busybox/sh", "-c", "ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/"]
RUN ["/busybox/sh", "-c", "mkdir -p /prometheus"]

FROM ${IMAGE_BASE}

RUN ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/
RUN mkdir -p /prometheus && \
chown -R nobody:nobody etc/prometheus /prometheus
COPY --from=buildbase /app/prometheus /bin/prometheus
COPY --from=buildbase /app/promtool /bin/promtool
COPY --from=appbase --chown=nobody:nobody /etc/prometheus /etc/prometheus
COPY --from=appbase --chown=nobody:nobody /prometheus /prometheus
COPY --from=appbase /usr/share/prometheus /usr/share/prometheus
COPY LICENSE /LICENSE
COPY NOTICE /NOTICE
COPY --from=assets /app/npm_licenses.tar.bz2 /npm_licenses.tar.bz2

USER nobody
EXPOSE 9090
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.28.1
2.28.1-gpe.0
25 changes: 25 additions & 0 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"syscall"
"time"

gcm_export "github.com/GoogleCloudPlatform/prometheus-engine/pkg/export"
"github.com/alecthomas/units"
kitloglevel "github.com/go-kit/kit/log/level"
"github.com/go-kit/log"
Expand Down Expand Up @@ -321,6 +322,8 @@ func main() {

promlogflag.AddFlags(a, &cfg.promlogConfig)

gcmExporterOpts := gcm_export.NewFlagOptions(a)

_, err := a.Parse(os.Args[1:])
if err != nil {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments"))
Expand Down Expand Up @@ -615,6 +618,12 @@ func main() {
externalURL,
)
},
}, {
name: "gcm_export",
reloader: func(cfg *config.Config) error {
// Call in closure to not call Global() before it's initialized below.
return gcm_export.Global().ApplyConfig(cfg)
},
},
}

Expand Down Expand Up @@ -685,6 +694,22 @@ func main() {
},
)
}
{
if err := gcm_export.InitGlobal(log.With(logger, "component", "gcm_exporter"), prometheus.DefaultRegisterer, *gcmExporterOpts); err != nil {
level.Error(logger).Log("msg", "Unable to init Google Cloud Monitoring exporter", "err", err)
os.Exit(2)
}
ctx, cancel := context.WithCancel(context.Background())

g.Add(
func() error {
return gcm_export.Global().Run(ctx)
},
func(err error) {
cancel()
},
)
}
{
// Scrape discovery manager.
g.Add(
Expand Down
24 changes: 9 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ require (
github.com/Azure/azure-sdk-for-go v55.2.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.19
github.com/Azure/go-autorest/autorest/adal v0.9.14
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.0.1 // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/GoogleCloudPlatform/prometheus-engine v0.0.8
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15
github.com/aws/aws-sdk-go v1.38.60
github.com/cespare/xxhash/v2 v2.1.1
github.com/containerd/containerd v1.4.3 // indirect
github.com/containerd/containerd v1.5.2 // indirect
github.com/dgryski/go-sip13 v0.0.0-20200911182023-62edffca9245
github.com/digitalocean/godo v1.62.0
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v20.10.7+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/edsrzf/mmap-go v1.0.0
github.com/go-kit/kit v0.10.0
github.com/go-kit/log v0.1.0
Expand All @@ -36,13 +31,9 @@ require (
github.com/json-iterator/go v1.1.11
github.com/linode/linodego v0.28.5
github.com/miekg/dns v1.1.42
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
github.com/oklog/run v1.1.0
github.com/oklog/ulid v1.3.1
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -70,15 +61,18 @@ require (
gopkg.in/fsnotify/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gotest.tools/v3 v3.0.3 // indirect
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/client-go v0.21.1
k8s.io/api v0.21.2
k8s.io/apimachinery v0.21.2
k8s.io/client-go v12.0.0+incompatible
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.9.0
)

replace (
// Dependency resolution fails without adding this override. It's not entirely
// understandable why but this appears to sufficiently fix it.
k8s.io/client-go => k8s.io/client-go v0.21.2

k8s.io/klog => github.com/simonpasquier/klog-gokit v0.3.0
k8s.io/klog/v2 => github.com/simonpasquier/klog-gokit/v2 v2.1.0
)
Expand Down
Loading

0 comments on commit 655bb33

Please sign in to comment.