Skip to content

Commit

Permalink
add grafana metric dashboard example
Browse files Browse the repository at this point in the history
  • Loading branch information
sefacan committed Aug 4, 2024
1 parent 69261bd commit efc0436
Show file tree
Hide file tree
Showing 15 changed files with 2,484 additions and 0 deletions.
22 changes: 22 additions & 0 deletions example/grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.21-alpine AS builder

WORKDIR /project

COPY go.mod go.sum ./
COPY main.go ./
COPY config.yml ./config.yml

RUN go mod download
RUN CGO_ENABLED=0 go build -a -o example main.go

FROM alpine:3.17.1

WORKDIR /app

RUN apk --no-cache add ca-certificates

USER nobody
COPY --from=builder --chown=nobody:nobody /project/example .
COPY --from=builder --chown=nobody:nobody /project/config.yml ./config.yml

ENTRYPOINT ["./example"]
16 changes: 16 additions & 0 deletions example/grafana/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
hosts:
- couchbase:8091
username: user
password: password
bucketName: dcp-test
dcp:
group:
name: groupName
membership:
type: static
metadata:
type: couchbase
config:
bucket: dcp-test
scope: _default
collection: _default
6 changes: 6 additions & 0 deletions example/grafana/couchbase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM couchbase:7.6.2

COPY configure.sh /opt/couchbase
RUN chmod +x /opt/couchbase/configure.sh

CMD ["/opt/couchbase/configure.sh"]
29 changes: 29 additions & 0 deletions example/grafana/couchbase/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Start Couchbase server in background
/entrypoint.sh couchbase-server &

# Wait for Couchbase to start
sleep 10

# Setup cluster
couchbase-cli cluster-init -c 127.0.0.1:8091 \
--cluster-username user \
--cluster-password password \
--services data,index,query,fts,eventing,analytics \
--cluster-ramsize 1024 \
--cluster-index-ramsize 256 \
--cluster-fts-ramsize 256 \
--cluster-eventing-ramsize 256 \
--cluster-analytics-ramsize 1024

# Create a bucket
couchbase-cli bucket-create -c 127.0.0.1:8091 \
--username user \
--password password \
--bucket dcp-test \
--bucket-type couchbase \
--bucket-ramsize 256

# Keep the container running
tail -f /dev/null
54 changes: 54 additions & 0 deletions example/grafana/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3.9'

volumes:
prometheus_data: { }
grafana_data: { }

services:
go-dcp:
build: .
ports:
- "8080:8080"
expose:
- 8080
depends_on:
- couchbase

couchbase:
build: ./couchbase
ports:
- "8091-8094:8091-8094"
- "11210:11210"
expose:
- 8091
environment:
- COUCHBASE_ADMINISTRATOR_USERNAME=user
- COUCHBASE_ADMINISTRATOR_PASSWORD=password

prometheus:

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: yaml.docker-compose.security.no-new-privileges.no-new-privileges Warning

Service 'prometheus' allows for privilege escalation via setuid or setgid binaries. Add 'no-new-privileges:true' in 'security_opt' to prevent this.

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: yaml.docker-compose.security.writable-filesystem-service.writable-filesystem-service Warning

Service 'prometheus' is running with a writable root filesystem. This may allow malicious applications to download and run additional payloads, or modify container files. If an application inside a container has to save something temporarily consider using a tmpfs. Add 'read_only: true' to this service to prevent this.
image: prom/prometheus:v2.53.1
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
ports:
- "9090:9090"
expose:
- 9090

grafana:

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: yaml.docker-compose.security.no-new-privileges.no-new-privileges Warning

Service 'grafana' allows for privilege escalation via setuid or setgid binaries. Add 'no-new-privileges:true' in 'security_opt' to prevent this.

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: yaml.docker-compose.security.writable-filesystem-service.writable-filesystem-service Warning

Service 'grafana' is running with a writable root filesystem. This may allow malicious applications to download and run additional payloads, or modify container files. If an application inside a container has to save something temporarily consider using a tmpfs. Add 'read_only: true' to this service to prevent this.
image: grafana/grafana:10.0.0
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_ANONYMOUS_ENABLED=true
ports:
- "3000:3000"
expose:
- 3000
depends_on:
- prometheus
85 changes: 85 additions & 0 deletions example/grafana/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module grafana

go 1.21

require (
github.com/Trendyol/go-dcp v1.1.50
github.com/couchbase/gocb/v2 v2.9.1
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.6.1 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/couchbase/gocbcore/v10 v10.5.1 // indirect
github.com/couchbase/gocbcoreps v0.1.3 // indirect
github.com/couchbase/goprotostellar v1.0.2 // indirect
github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20240607131231-fb385523de28 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gofiber/adaptor/v2 v2.2.1 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mhmtszr/concurrent-swiss-map v1.0.8 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.4 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/client-go v0.29.4 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit efc0436

Please sign in to comment.