diff --git a/.dockerignore b/.dockerignore index df37c15..35058c0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ .dockerignore +.pre-commit-config.yaml .git +.gitattributes .github .gitignore Dockerfile diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..622b3cd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto-detect text files, ensure they use LF. +* text=auto eol=lf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 6f6fca9..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @rebuy-de/prp-exporter-merger diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 54946d4..acd6271 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,9 +14,15 @@ on: jobs: docker: runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Install Cosign + uses: sigstore/cosign-installer@main - name: Docker meta id: meta uses: docker/metadata-action@v3 @@ -25,6 +31,7 @@ jobs: jkreileder/exporter-merger quay.io/jkreileder/exporter-merger ghcr.io/jkreileder/exporter-merger + registry-1.industrial-analytics.cloud/github/exporter-merger tags: | type=raw,value=latest,enable={{is_default_branch}} type=ref,event=branch @@ -54,13 +61,27 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to Harbor + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: registry-1.industrial-analytics.cloud + username: ${{ secrets.HARBOR_USERNAME }} + password: ${{ secrets.HARBOR_TOKEN }} - name: Build and push uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64,linux/arm64 + pull: true push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + - name: Sign the images with GitHub OIDC Token **not production ready** + if: github.event_name != 'pull_request' + run: cosign sign --force --recursive ${TAGS} + env: + TAGS: ${{ steps.meta.outputs.tags }} + COSIGN_EXPERIMENTAL: 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..550eb92 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: check-executables-have-shebangs + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + args: [--fix=lf] diff --git a/Dockerfile b/Dockerfile index 36022e8..ffd2e35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,8 @@ ENV GO111MODULE=off RUN go get -u golang.org/x/lint/golint RUN go get -u github.com/golang/dep/cmd/dep -WORKDIR /go/src/github.com/rebuy-de/exporter-merger -COPY --link . /go/src/github.com/rebuy-de/exporter-merger/ +WORKDIR /go/src/github.com/jkreileder/exporter-merger +COPY --link . /go/src/github.com/jkreileder/exporter-merger/ RUN --mount=type=cache,id=go-build,target=/root/.cache/go-build \ make vendor ARG TARGETOS TARGETARCH @@ -22,8 +22,8 @@ RUN --mount=type=cache,id=go-build,target=/root/.cache/go-build \ CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH make xcbuild # final stage -FROM alpine +FROM scratch WORKDIR /app -COPY --from=build-env --link /go/src/github.com/rebuy-de/exporter-merger/merger.yaml /app/ +COPY --from=build-env --link /go/src/github.com/jkreileder/exporter-merger/merger.yaml /app/ COPY --from=build-env --link /go/bin/exporter-merger /app/ CMD [ "./exporter-merger" ] diff --git a/LICENSE b/LICENSE index 91672c3..df4d7f8 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/Makefile b/Makefile index 855e618..7d8c27d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -PACKAGE=github.com/rebuy-de/exporter-merger +PACKAGE=github.com/jkreileder/exporter-merger include golang.mk diff --git a/README.md b/README.md index a7c807a..9b8f540 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +> [!WARNING] +> This repository has been archived because it has been obsoleted by `ServiceMonitor` and `PodMonitor`. See the [Prometheus Operator Documentation](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md) for details. + + # exporter-merger [![Build Status](https://github.com/jkreileder/exporter-merger/workflows/build/badge.svg)](https://github.com/jkreileder/exporter-merger/actions?query=workflow%3Abuild) @@ -5,12 +9,20 @@ [![License](https://img.shields.io/github/license/jkreileder/exporter-merger.svg)](LICENSE) [![GitHub Release](https://img.shields.io/github/release/jkreileder/exporter-merger.svg)](https://github.com/jkreileder/exporter-merger/releases/latest) +Images are available on: + +* [Docker registry](https://hub.docker.com/r/jkreileder/exporter-merger) +* [Quay container regsitry](https://quay.io/repository/jkreileder/exporter-merger) +* [GitHub container regsitry](https://github.com/jkreileder/exporter-merger/pkgs/container/exporter-merger) + +--- + Merges Prometheus metrics from multiple sources. > **Development Status** *exporter-merger* is in an early development phase. > Expect incompatible changes and abandoment at any time. -## But Why?! +## But Why? > [prometheus/prometheus#3756](https://github.com/prometheus/prometheus/issues/3756) @@ -20,23 +32,23 @@ Merges Prometheus metrics from multiple sources. ```yaml exporters: -- url: http://localhost:9100/metrics -- url: http://localhost:9101/metrics + - url: http://localhost:9100/metrics + - url: http://localhost:9101/metrics ``` To start the exporter: -``` +```shell exporter-merger --config-path merger.yaml --listen-port 8080 ``` ### Environment variables Alternatively configuration can be passed via environment variables, here is relevant part of `exporter-merger -h` output: -``` - --listen-port int Listen port for the HTTP server. (ENV:MERGER_PORT) (default 8080) - --url stringSlice URL to scrape. Can be speficied multiple times. (ENV:MERGER_URLS,space-seperated) +```text +--listen-port int Listen port for the HTTP server. (ENV:MERGER_PORT) (default 8080) +--url stringSlice URL to scrape. Can be speficied multiple times. (ENV:MERGER_URLS,space-seperated) ``` ## Kubernetes @@ -68,37 +80,46 @@ spec: spec: containers: - - name: "nginx" - image: "my-nginx" # nginx image with modified config file - - volumeMounts: - - name: mtail - mountPath: /var/log/nginx/mtail - - - name: nginx-exporter - image: quay.io/rebuy/nginx-exporter:v1.1.0 - ports: - - containerPort: 9397 - env: - - name: NGINX_ACCESS_LOGS - value: /var/log/nginx/mtail/access.log - - name: NGINX_STATUS_URI - value: http://localhost:8888/nginx_status - volumeMounts: - - name: mtail - mountPath: /var/log/nginx/mtail - - - name: exporter-merger - image: quay.io/rebuy/exporter-merger:v0.2.0 - ports: - - containerPort: 8080 - env: - # space-separated list of URLs - - name: MERGER_URLS - value: http://localhost:9000/prometheus/metrics http://localhost:9397/metrics - # default exposed port, change only if need other than default 8080 - # - name: MERGER_PORT - # value: 8080 + - name: "nginx" + image: "my-nginx" # nginx image with modified config file + + volumeMounts: + - name: mtail + mountPath: /var/log/nginx/mtail + + - name: nginx-exporter + image: quay.io/rebuy/nginx-exporter:v1.1.0 + ports: + - containerPort: 9397 + env: + - name: NGINX_ACCESS_LOGS + value: /var/log/nginx/mtail/access.log + - name: NGINX_STATUS_URI + value: http://localhost:8888/nginx_status + volumeMounts: + - name: mtail + mountPath: /var/log/nginx/mtail + + - name: exporter-merger + image: quay.io/jkreileder/exporter-merger:v0.4.4 + ports: + - name: metrics + containerPort: 8080 + env: + # space-separated list of URLs + - name: MERGER_URLS + value: http://localhost:9000/prometheus/metrics http://localhost:9397/metrics + # default exposed port, change only if need other than default 8080 + # - name: MERGER_PORT + # value: 8080 + livenessProbe: + httpGet: + path: /alive + port: metrics + readinessProbe: + httpGet: + path: /alive + port: metrics ``` ## Planned Features diff --git a/cmd/command.go b/cmd/command.go index 404e290..2ca9b1a 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -90,6 +90,10 @@ func (app *App) run(cmd *cobra.Command, args []string) { ExportersHTTPTimeout: app.viper.GetInt("exporterstimeout"), }) + http.HandleFunc("/alive", func(w http.ResponseWriter, r *http.Request) { + _, _ = w.Write([]byte("ok")) + }) + port := app.viper.GetInt("port") log.Infof("starting HTTP server on port %d", port) err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil) diff --git a/cmd/handler_test.go b/cmd/handler_test.go index 7e9ec9e..a7ebfb8 100644 --- a/cmd/handler_test.go +++ b/cmd/handler_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/prometheus/common/expfmt" - "github.com/rebuy-de/exporter-merger/cmd" + "github.com/jkreileder/exporter-merger/cmd" log "github.com/sirupsen/logrus" ) diff --git a/golang.mk b/golang.mk index 65b7343..a854bfb 100644 --- a/golang.mk +++ b/golang.mk @@ -1,10 +1,3 @@ -# Source: https://github.com/rebuy-de/golang-template -# Version: 1.3.1 -# Dependencies: -# * Glide -# * gocov (https://github.com/axw/gocov) -# * gocov-html (https://github.com/matm/gocov-html) - NAME=$(notdir $(PACKAGE)) BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' ) @@ -13,12 +6,7 @@ BUILD_HASH=$(shell git rev-parse HEAD) BUILD_MACHINE=$(shell echo $$HOSTNAME) BUILD_USER=$(shell whoami) -BUILD_FLAGS=-ldflags "\ - -X '$(PACKAGE)/cmd.BuildVersion=$(BUILD_VERSION)' \ - -X '$(PACKAGE)/cmd.BuildDate=$(BUILD_DATE)' \ - -X '$(PACKAGE)/cmd.BuildHash=$(BUILD_HASH)' \ - -X '$(PACKAGE)/cmd.BuildEnvironment=$(BUILD_USER)@$(BUILD_MACHINE)' \ -" +BUILD_FLAGS=-ldflags "-s -w" GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*") GOPKGS=$(shell go list ./...) diff --git a/main.go b/main.go index 3f0d5b3..2212c34 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/rebuy-de/exporter-merger/cmd" + "github.com/jkreileder/exporter-merger/cmd" log "github.com/sirupsen/logrus" )