Skip to content

Commit 8e4d828

Browse files
adodon2gorchincha
authored andcommitted
Implement an API for performance monitoring
Signed-off-by: Alexei Dodon <adodon@cisco.com>
1 parent 061dfb3 commit 8e4d828

54 files changed

Lines changed: 27267 additions & 196 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/oci-conformance-action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ jobs:
3333
run: |
3434
cd ./zot
3535
IP=`hostname -I | awk '{print $1}'`
36-
echo "ZOT_URL=http://${IP}:5000" >> $GITHUB_ENV
37-
ZOT_REF="local-zot:v$(date +%Y%m%d%H%M%S)"
38-
docker build -f ./Dockerfile-conformance -t "${ZOT_REF}" .
39-
docker run --rm -p 5000:5000 -v "$(pwd)":/go/src/github.com/anuvu/zot -idt "${ZOT_REF}"
36+
echo "SERVER_URL=http://${IP}:5000" >> $GITHUB_ENV
37+
IMAGE_REF="local-zot:v$(date +%Y%m%d%H%M%S)"
38+
docker build -f ./Dockerfile-conformance -t "${IMAGE_REF}" .
39+
docker run --rm -p 5000:5000 -v "$(pwd)":/go/src/github.com/anuvu/zot -idt "${IMAGE_REF}"
4040
- name: Run OCI Distribution Spec conformance tests
4141
uses: opencontainers/distribution-spec@main
4242
env:
43-
OCI_ROOT_URL: ${{ env.ZOT_URL }}
43+
OCI_ROOT_URL: ${{ env.SERVER_URL }}
4444
OCI_NAMESPACE: oci-conformance/distribution-test
4545
OCI_TEST_PULL: 1
4646
OCI_TEST_PUSH: 1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
bin/
1515
bazel-*
1616
coverage.txt
17+
coverage-extended.txt
18+
coverage-minimal.txt
1719
test/data/
1820
*.orig
1921
.idea/

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ For a minimal dist-spec only zot,
4444
make binary-minimal
4545
```
4646

47+
For a node exporter used by minimal dist-spec only zot,
48+
49+
```
50+
make exporter-minimal
51+
```
52+
4753
## Using container builds (stacker)
4854

4955
```
@@ -62,12 +68,14 @@ make binary-container
6268
.
6369
...
6470
├── cmd/zot # Source code contains the main logic
71+
├── cmd/exporter # Source code contains the main logic for node exporter
6572
├── docs # Source code for Swagger docs
6673
├── errors # Source code for errors
6774
├── examples # Configuration examples to enable various features
6875
├── pkg/api # Source code contains the HTTP handlers
6976
├── pkg/cli # Source code that handles the commandline logic
7077
├── pkg/compliance # Source code that handles the dist-spec compliance logic
78+
├── pkg/exporter # Source code used by the node exporter
7179
├── pkg/extensions # Source code that handles the feature extensions
7280
├── pkg/log # Source code that handles logging
7381
├── pkg/storage # Source code that handles image storage

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
11
export GO111MODULE=on
22
TOP_LEVEL=$(shell git rev-parse --show-toplevel)
33
COMMIT_HASH=$(shell git describe --always --tags --long)
4+
GO_VERSION=$(shell go version | awk '{print $$3}')
45
COMMIT=$(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH))
56
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
67
PATH := bin:$(PATH)
78
TMPDIR := $(shell mktemp -d)
89
STACKER := $(shell which stacker)
910

1011
.PHONY: all
11-
all: swagger binary binary-minimal debug test test-clean check
12+
all: swagger binary binary-minimal exporter-minimal debug test test-clean check
1213

1314
.PHONY: binary-minimal
1415
binary-minimal: swagger
15-
go build -tags minimal,containers_image_openpgp -v -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=minimal" -o bin/zot-minimal ./cmd/zot
16+
go build -o bin/zot-minimal -tags minimal,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=minimal -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot
1617

1718
.PHONY: binary
18-
binary: swagger
19-
go build -tags extended,containers_image_openpgp -v -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=extended" -o bin/zot ./cmd/zot
19+
binary: swagger
20+
go build -o bin/zot -tags extended,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot
2021

2122
.PHONY: debug
2223
debug: swagger
23-
go build -tags extended,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=extended" -o bin/zot-debug ./cmd/zot
24+
go build -o bin/zot-debug -tags extended,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot
25+
26+
.PHONY: exporter-minimal
27+
exporter-minimal: swagger
28+
go build -o bin/zot-exporter -tags minimal,containers_image_openpgp -v -trimpath ./cmd/exporter
2429

2530
.PHONY: test
2631
test:
2732
$(shell mkdir -p test/data; cd test/data; ../scripts/gen_certs.sh; cd ${TOP_LEVEL}; sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${TOP_LEVEL}/test/data/zot-test:0.0.1;sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${TOP_LEVEL}/test/data/zot-cve-test:0.0.1)
2833
$(shell sudo mkdir -p /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/client.* /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/ca.* /etc/containers/certs.d/127.0.0.1:8089/;)
2934
$(shell sudo chmod a=rwx /etc/containers/certs.d/127.0.0.1:8089/*.key)
30-
go test -tags extended,containers_image_openpgp -v -race -cover -coverpkg ./... -coverprofile=coverage.txt -covermode=atomic ./...
35+
go test -tags extended,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-extended.txt -covermode=atomic ./...
36+
go test -tags minimal,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-minimal.txt -covermode=atomic ./...
3137

3238
.PHONY: test-clean
3339
test-clean:
3440
$(shell sudo rm -rf /etc/containers/certs.d/127.0.0.1:8089/)
3541

3642
.PHONY: covhtml
3743
covhtml:
44+
tail -n +2 coverage-minimal.txt > tmp.txt && mv tmp.txt coverage-minimal.txt
45+
cat coverage-extended.txt coverage-minimal.txt > coverage.txt
3846
go tool cover -html=coverage.txt -o coverage.html
3947

4048
.PHONY: check
4149
check: ./golangcilint.yaml
4250
golangci-lint --version || curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.26.0
43-
golangci-lint --config ./golangcilint.yaml run --enable-all --build-tags extended,containers_image_openpgp ./cmd/... ./pkg/...
51+
golangci-lint --config ./golangcilint.yaml run --enable-all --build-tags extended,containers_image_openpgp ./...
52+
golangci-lint --config ./golangcilint.yaml run --enable-all --build-tags minimal,containers_image_openpgp ./...
4453

4554
swagger/docs.go:
4655
swag -v || go install github.com/swaggo/swag/cmd/swag

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ https://anuvu.github.io/zot/
4141
* Swagger based documentation
4242
* Single binary for _all_ the above features
4343
* Released under Apache 2.0 License
44+
* [Metrics](#metrics) with Prometheus
45+
* Using a node exporter in case of dist-spec-only zot
4446
* ```go get -u github.com/anuvu/zot/cmd/zot```
4547

4648
# Presentations
@@ -267,9 +269,24 @@ runtime interface.
267269

268270
Works with "docker://" transport which is the default.
269271

272+
# Metrics
273+
274+
Can be used for both dist-spec-only zot & the zot with all extensions enabled
275+
276+
## Node Exporter
277+
The dist-spec-only zot exposes internal metrics into a Prometheus format through a node exporter.
278+
The configuration of node exporter contains connection details for the zot server it is intend to scrape metrics from. See a [configuration example](./examples/metrics/exporter/config-minimal.json). The metrics are automatically enabled in the zot server on first scrape from the Node Exporter (no extra configuration option is needed). Similarly, the metrics are automatically disabled when Node Exporter did not perform any scrapings in a while.
279+
280+
```
281+
bin/zot-exporter config _config-file_
282+
```
283+
284+
## Enable Metrics
285+
In the zot with all extensions case see [configuration example](./examples/config-metrics.json) for enabling metrics
286+
270287
# Caveats
271288

272-
* go 1.12+
289+
* go 1.15+
273290
* The OCI distribution spec is still WIP, and we try to keep up
274291

275292
# Contributing

cmd/exporter/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// +build minimal
2+
3+
package main
4+
5+
import (
6+
"os"
7+
8+
"github.com/anuvu/zot/pkg/exporter/cli"
9+
)
10+
11+
func main() {
12+
if err := cli.NewExporterCmd().Execute(); err != nil {
13+
os.Exit(1)
14+
}
15+
}

examples/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Examples of working configurations for various use cases are available [here](..
2323
* [Authentication](#authentication)
2424
* [Identity-based Authorization](#identity-based-authorization)
2525
* [Logging](#logging)
26+
* [Metrics](#metrics)
2627

2728

2829
## Network
@@ -245,3 +246,24 @@ Enable audit logs and set output file with:
245246
"audit": "/tmp/zot-audit.log"
246247
}
247248
```
249+
250+
## Metrics
251+
252+
Enable and configure metrics with:
253+
254+
```
255+
"metrics":{
256+
"enable":"true",
257+
258+
```
259+
260+
Set server path on which metrics will be exposed:
261+
262+
```
263+
"prometheus": {
264+
"path": "/metrics"
265+
}
266+
}
267+
```
268+
269+
In order to test the Metrics feature locally in a [Kind](https://kind.sigs.k8s.io/) cluster, folow [this guide](metrics/README.md).

examples/config-metrics.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.1.0-dev",
3+
"storage": {
4+
"rootDirectory": "/tmp/zot"
5+
},
6+
"http": {
7+
"address": "127.0.0.1",
8+
"port": "8080"
9+
},
10+
"log": {
11+
"level": "debug"
12+
},
13+
"extensions": {
14+
"metrics": {
15+
"enable": true,
16+
"prometheus": {
17+
"path": "/metrics"
18+
}
19+
}
20+
}
21+
}

examples/config-policy.json

100755100644
File mode changed.

examples/metrics/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ---
2+
# Stage 1: Install certs, build binary, create default config file
3+
# ---
4+
FROM docker.io/golang:1.16 AS builder
5+
RUN mkdir -p /go/src/github.com/anuvu/zot
6+
WORKDIR /go/src/github.com/anuvu/zot
7+
COPY . .
8+
RUN CGO_ENABLED=0 make clean binary
9+
RUN echo '{\n\
10+
"storage": {\n\
11+
"rootDirectory": "/var/lib/registry"\n\
12+
},\n\
13+
"http": {\n\
14+
"address": "0.0.0.0",\n\
15+
"port": "5000"\n\
16+
},\n\
17+
"log": {\n\
18+
"level": "debug"\n\
19+
},\n\
20+
"extensions": {\n\
21+
"metrics": {\n\
22+
"enable": true,\n\
23+
"prometheus": {\n\
24+
"path": "/metrics"\n\
25+
}\n\
26+
}\n\
27+
}\n\
28+
}\n' > config.json && cat config.json
29+
30+
# ---
31+
# Stage 2: Final image with nothing but certs, binary, and default config file
32+
# ---
33+
FROM scratch AS final
34+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
35+
COPY --from=builder /go/src/github.com/anuvu/zot/bin/zot /zot
36+
COPY --from=builder /go/src/github.com/anuvu/zot/config.json /etc/zot/config.json
37+
ENTRYPOINT ["/zot"]
38+
EXPOSE 5000
39+
VOLUME ["/var/lib/registry"]
40+
CMD ["serve", "/etc/zot/config.json"]

0 commit comments

Comments
 (0)