diff --git a/cmd/serve.go b/cmd/serve.go index fe1c83ce8..7bfb42ef6 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,9 +1,11 @@ package main import ( + "net/http" "os" "os/signal" "path" + "strconv" "github.com/crazy-max/diun/v4/internal/app" "github.com/crazy-max/diun/v4/internal/config" @@ -11,6 +13,10 @@ import ( "github.com/crazy-max/diun/v4/pkg/utl" "github.com/pkg/profile" "github.com/rs/zerolog/log" + + diunApi "github.com/crazy-max/diun/v4/pkg/api" + apiMetrics "github.com/crazy-max/diun/v4/pkg/api/metrics" + apiScan "github.com/crazy-max/diun/v4/pkg/api/scan" ) // ServeCmd holds serve command args and flags @@ -89,6 +95,28 @@ func (s *ServeCmd) Run(ctx *Context) error { log.Fatal().Err(err).Msgf("Cannot initialize %s", ctx.Meta.Name) } + if *cfg.APIMetrics.EnableAPI || *cfg.APIMetrics.EnableScan { + httpAPI := diunApi.New(cfg.APIMetrics.Token, cfg.APIMetrics.Port) + + if *cfg.APIMetrics.EnableAPI { + metricsHandler := apiMetrics.New() + httpAPI.RegisterFunc(cfg.APIMetrics.APIPath, metricsHandler.Handle) + log.Info().Msgf("API Server Registered: %s", cfg.APIMetrics.APIPath) + } + + if *cfg.APIMetrics.EnableScan { + scanHandler := apiScan.New(func() { diun.Run() }) + httpAPI.RegisterFunc(cfg.APIMetrics.ScanPath, scanHandler.Handle) + log.Info().Msgf("API Server Registered: %s", cfg.APIMetrics.ScanPath) + } + + if err := httpAPI.Start(false); err != nil && err != http.ErrServerClosed { + log.Fatal().Err(err).Msgf("failed to start API %s", err) + } + + log.Info().Msgf("API Server Started Port: %s EnableAPI: %s EnableScan: %s", cfg.APIMetrics.Port, strconv.FormatBool(*cfg.APIMetrics.EnableAPI), strconv.FormatBool(*cfg.APIMetrics.EnableScan)) + } + // Start err = diun.Start() if err != nil { diff --git a/docs/config/apimetrics.md b/docs/config/apimetrics.md new file mode 100644 index 000000000..e23b14d31 --- /dev/null +++ b/docs/config/apimetrics.md @@ -0,0 +1,93 @@ +# API Metrics configuration + +## Overview + +```yaml +apimetrics: + enableApi: true + enableScan: true + token: ApiToken + port: 6080 + apiPath: /v1/metrics + scanPath: /v1/scan +``` + +## Configuration + +### `token` + +Authentication Bearer Token used for accessing the Metrics API endpoint and the Scan API endpoint. (default: ApiToken) + +!!! example "Config file" + ```yaml + apimetrics: + token: ApiToken + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_TOKEN` + +### `port` + +TCP port used for the http api. (default: 6080) + +!!! example "Config file" + ```yaml + apimetrics: + port: 6080 + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_PORT` + +### `enableApi` + +Enable or disable the Metrics endpoint. (default: false) + +!!! example "Config file" + ```yaml + apimetrics: + enableApi: true + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_ENABLEAPI` + +### `apiPath` + +Path to expose the API Metrics on. (default: /v1/metrics) + +!!! example "Config file" + ```yaml + apimetrics: + apiPath: /v1/metrics + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_APIPATH` + +### `enableScan` + +Enable or disable the Scan endpoint. The Scan endpoint allows for the triggering of a re-scan of the images. (default: false) + +!!! example "Config file" + ```yaml + apimetrics: + enableScan: true + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_ENABLESCAN` + +### `scanPath` + +Path to expose the API Metrics on. (default: /v1/scann) + +!!! example "Config file" + ```yaml + apimetrics: + apiScan: true + ``` + +!!! abstract "Environment variables" + * `DIUN_APIMETRICS_APISCAN` diff --git a/docs/config/index.md b/docs/config/index.md index 26342998c..e411a4432 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -229,3 +229,4 @@ Can be transposed to: * [nomad](../providers/nomad.md) * [dockerfile](../providers/dockerfile.md) * [file](../providers/file.md) +* [apimetrics](apimetrics.md) diff --git a/docs/providers/docker.md b/docs/providers/docker.md index 46e09082b..b5f259197 100644 --- a/docs/providers/docker.md +++ b/docs/providers/docker.md @@ -169,12 +169,28 @@ Include created and exited containers too (default `false`). !!! abstract "Environment variables" * `DIUN_PROVIDERS_DOCKER_WATCHSTOPPED` +### `pullImages` + +Pull new image if found in the remote repository. (default `false`). +This feature is used in conjunction with the apimetrics. + +!!! example "File" + ```yaml + providers: + docker: + pullImages: true + ``` + +!!! abstract "Environment variables" + * `DIUN_PROVIDERS_DOCKER_PULLIMAGES` + + ## Docker labels You can configure more finely the way to analyze the image of your container through Docker labels: | Name | Default | Description | -|---------------------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| +| ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | `diun.enable` | | Set to true to enable image analysis of this container | | `diun.regopt` | | [Registry options](../config/regopts.md) name to use | | `diun.watch_repo` | `false` | Watch all tags of this container image ([be careful](../faq.md#docker-hub-rate-limits) with this setting) | @@ -190,7 +206,7 @@ You can configure more finely the way to analyze the image of your container thr ## Default metadata | Key | Description | -|-------------------------------|-------------------------| +| ----------------------------- | ----------------------- | | `diun.metadata.ctn_id` | Container ID | | `diun.metadata.ctn_names` | Container names | | `diun.metadata.ctn_command` | Container command | diff --git a/go.mod b/go.mod index 7efd6e460..ae73e93c4 100644 --- a/go.mod +++ b/go.mod @@ -51,6 +51,8 @@ require ( k8s.io/client-go v0.25.4 ) +require github.com/prometheus/client_golang v1.12.1 + require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/Masterminds/semver v1.5.0 // indirect @@ -63,6 +65,8 @@ require ( github.com/andybalholm/cascadia v1.0.0 // indirect github.com/aokoli/goutils v1.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/containerd/typeurl v1.0.2 // indirect github.com/containers/libtrust v0.0.0-20200511145503-9c3a6c22cd9a // indirect github.com/containers/ocicrypt v1.1.5 // indirect @@ -105,6 +109,7 @@ require ( github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -116,6 +121,9 @@ require ( github.com/opencontainers/runc v1.1.4 // indirect github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.37.0 // indirect + github.com/prometheus/procfs v0.7.3 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect diff --git a/go.sum b/go.sum index aac5ba523..60a81c42e 100644 --- a/go.sum +++ b/go.sum @@ -10,18 +10,27 @@ cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6T cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw= github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI= @@ -92,6 +101,7 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0= github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o= github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= @@ -106,6 +116,7 @@ github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd3 github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= @@ -124,6 +135,8 @@ github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInq github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw= github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M= github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= @@ -340,8 +353,12 @@ github.com/go-gomail/gomail v0.0.0-20160411212932-81ebce5c23df/go.mod h1:GJr+FCS github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -402,6 +419,7 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -428,6 +446,7 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -442,12 +461,14 @@ github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= @@ -532,15 +553,18 @@ github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52Cu github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -601,6 +625,8 @@ github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vq github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -642,6 +668,7 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -726,10 +753,14 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20180110214958-89604d197083/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= @@ -737,6 +768,10 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= +github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -748,6 +783,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -861,7 +898,9 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1: github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= @@ -878,6 +917,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -965,6 +1005,10 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -973,8 +1017,11 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -982,6 +1029,8 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 h1:nt+Q6cXKz4MosCSpnbMtqiQ8Oz0pxTef2B4Vca2lvfk= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1044,10 +1093,16 @@ golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200817155316-9781c653f443/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1065,6 +1120,7 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1074,6 +1130,7 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1081,6 +1138,7 @@ golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1137,11 +1195,20 @@ golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200916195026-c9a70fc28ce3/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= @@ -1159,8 +1226,13 @@ google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsb google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -1189,11 +1261,20 @@ google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvx google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c= @@ -1210,8 +1291,10 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= @@ -1287,6 +1370,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/api v0.20.1/go.mod h1:KqwcCVogGxQY3nBlRpwt+wpAMF/KjaCc7RpywacvqUo= k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ= k8s.io/api v0.20.6/go.mod h1:X9e8Qag6JV/bL5G6bU8sdVRltWKmdHsFUGS3eVndqE8= diff --git a/internal/app/diun.go b/internal/app/diun.go index 850787d1a..02c4a7a65 100644 --- a/internal/app/diun.go +++ b/internal/app/diun.go @@ -19,6 +19,7 @@ import ( kubernetesPrd "github.com/crazy-max/diun/v4/internal/provider/kubernetes" nomadPrd "github.com/crazy-max/diun/v4/internal/provider/nomad" swarmPrd "github.com/crazy-max/diun/v4/internal/provider/swarm" + containerMetrics "github.com/crazy-max/diun/v4/pkg/metrics" "github.com/crazy-max/gohealthchecks" "github.com/hako/durafmt" "github.com/panjf2000/ants/v2" @@ -138,7 +139,7 @@ func (di *Diun) Run() { di.cron.Entry(di.jobID).Next) } - log.Info().Msg("Cron triggered") + log.Info().Msg("Diun Run triggered") entries := new(model.NotifEntries) di.HealthchecksStart() defer di.HealthchecksSuccess(entries) @@ -188,7 +189,11 @@ func (di *Diun) Run() { Int("unchanged", entries.CountUnchange). Int("skipped", entries.CountSkip). Int("failed", entries.CountError). + Int("stale", entries.CountStale). + Int("total", entries.CountTotal). Msg("Jobs completed") + + containerMetrics.RegisterNotification(*entries) } // Close closes diun diff --git a/internal/app/job.go b/internal/app/job.go index 0f1f7c119..55682f9a2 100644 --- a/internal/app/job.go +++ b/internal/app/job.go @@ -6,6 +6,8 @@ import ( "github.com/containers/image/v5/pkg/docker/config" "github.com/containers/image/v5/types" + "github.com/opencontainers/go-digest" + "github.com/crazy-max/diun/v4/internal/model" "github.com/crazy-max/diun/v4/pkg/registry" "github.com/crazy-max/diun/v4/pkg/utl" @@ -166,10 +168,12 @@ func (di *Diun) createJob(job model.Job) { func (di *Diun) runJob(job model.Job) (entry model.NotifEntry) { var err error entry = model.NotifEntry{ - Status: model.ImageStatusError, - Provider: job.Provider, - Image: job.RegImage, - Metadata: job.Image.Metadata, + Status: model.ImageStatusError, + Provider: job.Provider, + Image: job.RegImage, + Metadata: job.Image.Metadata, + ContainerName: job.Image.ContainerName, + ContainerLabels: job.Image.ContainerLabels, } sublog := log.With(). @@ -207,9 +211,15 @@ func (di *Diun) runJob(job model.Job) (entry model.NotifEntry) { entry.Image.HubLink = job.HubLinkOverride } + stale := !digestInList(entry.Manifest.Digest.String(), job.Image.Digests) + sublog.Debug().Msgf("Image: %s Running Image Digests: %s Registry Image Digest: %s", job.Image.Name, job.Image.Digests, entry.Manifest.Digest.String()) + if len(dbManifest.Name) == 0 { entry.Status = model.ImageStatusNew sublog.Info().Msg("New image found") + } else if stale { + entry.Status = model.ImageStatusStale + sublog.Info().Msgf("New Image found for %s - %s", job.Image.Name, entry.Manifest.Digest.String()) } else if updated { entry.Status = model.ImageStatusUpdate sublog.Info().Msg("Image update found") @@ -232,6 +242,15 @@ func (di *Diun) runJob(job model.Job) (entry model.NotifEntry) { return } + // Pull Image if configured. + if job.PullImage && entry.Status == model.ImageStatusStale { + sublog.Debug().Msgf("Pulling image: %s", entry.Image.String()) + err := job.Registry.PullImage(entry.Image.String()) + if err != nil { + sublog.Error().Msgf("Unable to pull the image: %s", entry.Image.String()) + } + } + notifyOn := model.NotifyOn(entry.Status) if !notifyOn.OneOf(job.Image.NotifyOn) { sublog.Debug().Msgf("Skipping notification (%s not part of specified notify status)", entry.Status) @@ -241,3 +260,12 @@ func (di *Diun) runJob(job model.Job) (entry model.NotifEntry) { di.notif.Send(entry) return } + +func digestInList(a string, list []digest.Digest) bool { + for _, b := range list { + if b.String() == a { + return true + } + } + return false +} diff --git a/internal/config/config.go b/internal/config/config.go index d7f61258f..5fcb2385c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,18 +14,20 @@ import ( // Config holds configuration details type Config struct { - Db *model.Db `yaml:"db,omitempty" json:"db,omitempty"` - Watch *model.Watch `yaml:"watch,omitempty" json:"watch,omitempty"` - Notif *model.Notif `yaml:"notif,omitempty" json:"notif,omitempty"` - RegOpts model.RegOpts `yaml:"regopts,omitempty" json:"regopts,omitempty" validate:"unique=Name,dive"` - Providers *model.Providers `yaml:"providers,omitempty" json:"providers,omitempty"` + Db *model.Db `yaml:"db,omitempty" json:"db,omitempty"` + Watch *model.Watch `yaml:"watch,omitempty" json:"watch,omitempty"` + Notif *model.Notif `yaml:"notif,omitempty" json:"notif,omitempty"` + RegOpts model.RegOpts `yaml:"regopts,omitempty" json:"regopts,omitempty" validate:"unique=Name,dive"` + Providers *model.Providers `yaml:"providers,omitempty" json:"providers,omitempty"` + APIMetrics *model.APIMetrics `yaml:"apimetrics,omitempty" json:"metricsapi,omitempty"` } // Load returns Config struct func Load(config string) (*Config, error) { cfg := Config{ - Db: (&model.Db{}).GetDefaults(), - Watch: (&model.Watch{}).GetDefaults(), + Db: (&model.Db{}).GetDefaults(), + Watch: (&model.Watch{}).GetDefaults(), + APIMetrics: (&model.APIMetrics{}).GetDefaults(), } fileLoader := gonfig.NewFileLoader(gonfig.FileLoaderConfig{ diff --git a/internal/model/apimetrics.go b/internal/model/apimetrics.go new file mode 100644 index 000000000..5c5827343 --- /dev/null +++ b/internal/model/apimetrics.go @@ -0,0 +1,29 @@ +package model + +import "github.com/crazy-max/diun/v4/pkg/utl" + +type APIMetrics struct { + EnableAPI *bool `yaml:"enableApi,omitempty" json:"enableApi,omitempty"` + EnableScan *bool `yaml:"enableScan,omitempty" json:"enableScan,omitempty"` + Port string `yaml:"port,omitempty" json:"port,omitempty"` + Token string `yaml:"token,omitempty" json:"token,omitempty"` + APIPath string `yaml:"apiPath,omitempty" json:"apiPath,omitempty"` + ScanPath string `yaml:"scanPath,omitempty" json:"scanPath,omitempty"` +} + +// GetDefaults gets the default values +func (s *APIMetrics) GetDefaults() *APIMetrics { + n := &APIMetrics{} + n.SetDefaults() + return n +} + +// SetDefaults sets the default values +func (s *APIMetrics) SetDefaults() { + s.EnableAPI = utl.NewFalse() + s.EnableScan = utl.NewFalse() + s.APIPath = "/v1/metrics" + s.ScanPath = "/v1/scan" + s.Port = "6080" + s.Token = "ApiToken" +} diff --git a/internal/model/image.go b/internal/model/image.go index 59d44aac4..20bc28de8 100644 --- a/internal/model/image.go +++ b/internal/model/image.go @@ -1,21 +1,27 @@ package model -import "github.com/crazy-max/diun/v4/pkg/registry" +import ( + "github.com/crazy-max/diun/v4/pkg/registry" + digest "github.com/opencontainers/go-digest" +) // Image holds image configuration type Image struct { - Name string `yaml:"name,omitempty" json:",omitempty"` - Platform ImagePlatform `yaml:"platform,omitempty" json:",omitempty"` - RegOpt string `yaml:"regopt,omitempty" json:",omitempty"` - WatchRepo bool `yaml:"watch_repo,omitempty" json:",omitempty"` - NotifyOn []NotifyOn `yaml:"notify_on,omitempty" json:",omitempty"` - MaxTags int `yaml:"max_tags,omitempty" json:",omitempty"` - SortTags registry.SortTag `yaml:"sort_tags,omitempty" json:",omitempty"` - IncludeTags []string `yaml:"include_tags,omitempty" json:",omitempty"` - ExcludeTags []string `yaml:"exclude_tags,omitempty" json:",omitempty"` - HubTpl string `yaml:"hub_tpl,omitempty" json:",omitempty"` - HubLink string `yaml:"hub_link,omitempty" json:",omitempty"` - Metadata map[string]string `yaml:"metadata,omitempty" json:",omitempty"` + Name string `yaml:"name,omitempty" json:",omitempty"` + Platform ImagePlatform `yaml:"platform,omitempty" json:",omitempty"` + RegOpt string `yaml:"regopt,omitempty" json:",omitempty"` + WatchRepo bool `yaml:"watch_repo,omitempty" json:",omitempty"` + NotifyOn []NotifyOn `yaml:"notify_on,omitempty" json:",omitempty"` + MaxTags int `yaml:"max_tags,omitempty" json:",omitempty"` + SortTags registry.SortTag `yaml:"sort_tags,omitempty" json:",omitempty"` + IncludeTags []string `yaml:"include_tags,omitempty" json:",omitempty"` + ExcludeTags []string `yaml:"exclude_tags,omitempty" json:",omitempty"` + HubTpl string `yaml:"hub_tpl,omitempty" json:",omitempty"` + HubLink string `yaml:"hub_link,omitempty" json:",omitempty"` + Metadata map[string]string `yaml:"metadata,omitempty" json:",omitempty"` + Digests []digest.Digest + ContainerName string + ContainerLabels map[string]string } // ImagePlatform holds image platform configuration @@ -32,6 +38,7 @@ const ( ImageStatusUnchange = ImageStatus("unchange") ImageStatusSkip = ImageStatus("skip") ImageStatusError = ImageStatus("error") + ImageStatusStale = ImageStatus("stale") ) // ImageStatus holds Docker image status analysis diff --git a/internal/model/job.go b/internal/model/job.go index dfdfbdb3c..b7e49ce7e 100644 --- a/internal/model/job.go +++ b/internal/model/job.go @@ -12,4 +12,5 @@ type Job struct { Registry *registry.Client FirstCheck bool HubLinkOverride string + PullImage bool } diff --git a/internal/model/notif.go b/internal/model/notif.go index cca3d68e9..226bf4f6b 100644 --- a/internal/model/notif.go +++ b/internal/model/notif.go @@ -19,15 +19,18 @@ type NotifEntries struct { CountSkip int CountError int CountTotal int + CountStale int } // NotifEntry represents a notification entry type NotifEntry struct { - Status ImageStatus `json:"status,omitempty"` - Provider string `json:"provider,omitempty"` - Image registry.Image `json:"image,omitempty"` - Manifest registry.Manifest `json:"manifest,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` + Status ImageStatus `json:"status,omitempty"` + Provider string `json:"provider,omitempty"` + Image registry.Image `json:"image,omitempty"` + Manifest registry.Manifest `json:"manifest,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` + ContainerName string `json:"container,omitempty"` + ContainerLabels map[string]string } // Notif holds data necessary for notification configuration @@ -77,5 +80,8 @@ func (s *NotifEntries) Add(entry NotifEntry) { case ImageStatusError: s.CountError++ s.CountTotal++ + case ImageStatusStale: + s.CountStale++ + s.CountTotal++ } } diff --git a/internal/model/provider_docker.go b/internal/model/provider_docker.go index 00f7d8ca1..de288c6c3 100644 --- a/internal/model/provider_docker.go +++ b/internal/model/provider_docker.go @@ -12,6 +12,7 @@ type PrdDocker struct { TLSVerify *bool `yaml:"tlsVerify" json:"tlsVerify,omitempty" validate:"required"` WatchByDefault *bool `yaml:"watchByDefault" json:"watchByDefault,omitempty" validate:"required"` WatchStopped *bool `yaml:"watchStopped" json:"watchStopped,omitempty" validate:"required"` + PullImages *bool `yaml:"pullImages" json:"pullImages,omitempty" validate:"omitempty"` } // GetDefaults gets the default values @@ -26,4 +27,5 @@ func (s *PrdDocker) SetDefaults() { s.TLSVerify = utl.NewTrue() s.WatchByDefault = utl.NewFalse() s.WatchStopped = utl.NewFalse() + s.PullImages = utl.NewFalse() } diff --git a/internal/provider/common.go b/internal/provider/common.go index cdcc51314..bb7b4dfd4 100644 --- a/internal/provider/common.go +++ b/internal/provider/common.go @@ -9,6 +9,7 @@ import ( "github.com/containerd/containerd/platforms" "github.com/crazy-max/diun/v4/internal/model" "github.com/crazy-max/diun/v4/pkg/registry" + digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" ) @@ -17,16 +18,37 @@ var ( metadataKeyRegexp = regexp.MustCompile(`^[` + metadataKeyChars + `]+$`) ) -// ValidateImage returns a standard image through Docker labels -func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool) (img model.Image, err error) { - if i := strings.Index(image, "@sha256:"); i > 0 { +func ValidateImageWithDigest(image string, metadata, labels map[string]string, watchByDef bool, digests []string) (img model.Image, err error) { + if i := strings.Index(image, "@sha256"); i > 0 { image = image[:i] } + + l := make([]digest.Digest, len(digests)+1) + j := 0 + for d := range digests { + digestString := digests[d] + + if i := strings.Index(digestString, "@sha256"); i > 0 { + digestString = digestString[i+1:] + + if len(digestString) > 0 { + dgst, err := digest.Parse(digestString) + if err != nil { + return img, fmt.Errorf("cannot parse %s value of image digest", digestString) + } + + l[j] = dgst + j++ + } + } + } + img = model.Image{ - Name: image, - Metadata: metadata, - NotifyOn: model.NotifyOnDefaults, - SortTags: registry.SortTagReverse, + Name: image, + NotifyOn: model.NotifyOnDefaults, + SortTags: registry.SortTagReverse, + Digests: l, + ContainerName: metadata["ctn_name"], } if enableStr, ok := labels["diun.enable"]; ok { @@ -104,12 +126,23 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef img.Metadata = map[string]string{} } img.Metadata[mkey] = value + case key == "diun.label-schema.group": + if img.ContainerLabels == nil { + img.ContainerLabels = map[string]string{} + } + img.ContainerLabels[key] = value } } return img, nil } +// ValidateImage returns a standard image through Docker labels +func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool) (img model.Image, err error) { + d := make([]string, 1, 2) + return ValidateImageWithDigest(image, metadata, labels, watchByDef, d) +} + func validateMetadataKey(key string) error { if !metadataKeyRegexp.MatchString(key) { return errors.Errorf("only %q are allowed", metadataKeyChars) diff --git a/internal/provider/docker/container.go b/internal/provider/docker/container.go index 54e75b691..31b07ffd1 100644 --- a/internal/provider/docker/container.go +++ b/internal/provider/docker/container.go @@ -91,7 +91,7 @@ func (c *Client) listContainerImage() []model.Image { Str("ctn_image", imageName). Interface("ctn_labels", ctn.Labels). Msg("Validate image") - image, err := provider.ValidateImage(imageName, metadata(ctn), ctn.Labels, *c.config.WatchByDefault) + image, err := provider.ValidateImageWithDigest(imageName, metadata(ctn), ctn.Labels, *c.config.WatchByDefault, imageRaw.RepoDigests) if err != nil { c.logger.Error().Err(err). @@ -119,6 +119,7 @@ func metadata(ctn types.Container) map[string]string { return map[string]string{ "ctn_id": ctn.ID, "ctn_names": formatNames(ctn.Names), + "ctn_name": formatNames(ctn.Names), "ctn_command": ctn.Command, "ctn_createdat": time.Unix(ctn.Created, 0).String(), "ctn_state": ctn.State, diff --git a/internal/provider/docker/docker.go b/internal/provider/docker/docker.go index 90df4c23a..01bb0ac9b 100644 --- a/internal/provider/docker/docker.go +++ b/internal/provider/docker/docker.go @@ -40,8 +40,9 @@ func (c *Client) ListJob() []model.Job { var list []model.Job for _, image := range images { list = append(list, model.Job{ - Provider: "docker", - Image: image, + Provider: "docker", + Image: image, + PullImage: *c.config.PullImages, }) } diff --git a/internal/provider/kubernetes/pod.go b/internal/provider/kubernetes/pod.go index 7b12ce9c2..7879eec47 100644 --- a/internal/provider/kubernetes/pod.go +++ b/internal/provider/kubernetes/pod.go @@ -2,7 +2,6 @@ package kubernetes import ( "reflect" - "strings" "github.com/crazy-max/diun/v4/internal/model" "github.com/crazy-max/diun/v4/internal/provider" @@ -33,7 +32,7 @@ func (c *Client) listPodImage() []model.Image { var list []model.Image for _, pod := range pods { - for _, ctn := range pod.Spec.Containers { + for _, ctn := range pod.Status.ContainerStatuses { c.logger.Debug(). Str("pod_name", pod.Name). Interface("pod_annot", pod.Annotations). @@ -41,7 +40,9 @@ func (c *Client) listPodImage() []model.Image { Str("ctn_image", ctn.Image). Msg("Validate image") - image, err := provider.ValidateImage(ctn.Image, metadata(pod, ctn), pod.Annotations, *c.config.WatchByDefault) + digests := make([]string, 1, 4) + digests[0] = ctn.ImageID + image, err := provider.ValidateImageWithDigest(ctn.Image, metadata(pod, ctn), pod.Annotations, *c.config.WatchByDefault, digests) if err != nil { c.logger.Error().Err(err). Str("pod_name", pod.Name). @@ -67,13 +68,14 @@ func (c *Client) listPodImage() []model.Image { return list } -func metadata(pod v1.Pod, ctn v1.Container) map[string]string { +func metadata(pod v1.Pod, ctn v1.ContainerStatus) map[string]string { return map[string]string{ "pod_name": pod.Name, "pod_status": pod.Status.String(), "pod_namespace": pod.Namespace, "pod_createdat": pod.CreationTimestamp.String(), "ctn_name": ctn.Name, - "ctn_command": strings.Join(ctn.Command, " "), + "ctn_command": "", + "ctn_names": pod.Name, } } diff --git a/pkg/api/api.go b/pkg/api/api.go new file mode 100644 index 000000000..db74ed0d9 --- /dev/null +++ b/pkg/api/api.go @@ -0,0 +1,84 @@ +package api + +import ( + "fmt" + "net/http" + + log "github.com/sirupsen/logrus" +) + +const tokenMissingMsg = "api token is empty or has not been set. exiting" + +// API is the http server responsible for serving the HTTP API endpoints +type API struct { + Token string + hasHandlers bool + Port string +} + +// New is a factory function creating a new API instance +func New(token string, port ...string) *API { + listenPort := ":8080" + if len(port) > 0 && port[0] != "" { + listenPort = port[0] + } + if listenPort[0:1] != ":" { + listenPort = ":" + listenPort + } + return &API{ + Token: token, + hasHandlers: false, + Port: listenPort, + } +} + +// RequireToken is wrapper around http.HandleFunc that checks token validity +func (api *API) RequireToken(fn http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + auth := r.Header.Get("Authorization") + want := fmt.Sprintf("Bearer %s", api.Token) + if auth != want { + w.WriteHeader(http.StatusUnauthorized) + return + } + log.Debug("Valid token found.") + fn(w, r) + } +} + +// RegisterFunc is a wrapper around http.HandleFunc that also sets the flag used to determine whether to launch the API +func (api *API) RegisterFunc(path string, fn http.HandlerFunc) { + api.hasHandlers = true + http.HandleFunc(path, api.RequireToken(fn)) +} + +// RegisterHandler is a wrapper around http.Handler that also sets the flag used to determine whether to launch the API +func (api *API) RegisterHandler(path string, handler http.Handler) { + api.hasHandlers = true + http.Handle(path, api.RequireToken(handler.ServeHTTP)) +} + +// Start the API and serve over HTTP. Requires an API Token to be set. +func (api *API) Start(block bool) error { + if !api.hasHandlers { + log.Debug("Diun HTTP API skipped. No handlers are defined.") + return nil + } + + if api.Token == "" { + log.Fatal(tokenMissingMsg) + } + + if block { + runHTTPServer(api) + } else { + go func() { + runHTTPServer(api) + }() + } + return nil +} + +func runHTTPServer(api *API) { + log.Fatal(http.ListenAndServe(api.Port, nil)) +} diff --git a/pkg/api/metrics/metrics.go b/pkg/api/metrics/metrics.go new file mode 100644 index 000000000..c8634b047 --- /dev/null +++ b/pkg/api/metrics/metrics.go @@ -0,0 +1,28 @@ +package metrics + +import ( + "net/http" + + "github.com/crazy-max/diun/v4/pkg/metrics" + + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +// Handler is an HTTP handle for serving metric data +type Handler struct { + Path string + Handle http.HandlerFunc + Metrics *metrics.Metrics +} + +// New is a factory function creating a new Metrics instance +func New() *Handler { + m := metrics.Default() + handler := promhttp.Handler() + + return &Handler{ + Path: "/v1/metrics", + Handle: handler.ServeHTTP, + Metrics: m, + } +} diff --git a/pkg/api/scan/scan.go b/pkg/api/scan/scan.go new file mode 100644 index 000000000..c5d87a10a --- /dev/null +++ b/pkg/api/scan/scan.go @@ -0,0 +1,36 @@ +package metrics + +import ( + "io" + "net/http" + "os" + + "github.com/rs/zerolog/log" +) + +// New is a factory function creating a new Handler instance +func New(scanFn func()) *Handler { + return &Handler{ + fn: scanFn, + Path: "/v1/scan", + } +} + +// Handler is an API handler used for triggering container update scans +type Handler struct { + fn func() + Path string +} + +// Handle is the actual http.Handle function doing all the heavy lifting +func (handle *Handler) Handle(w http.ResponseWriter, r *http.Request) { + log.Info().Msg("Updates triggered by HTTP API request.") + + _, err := io.Copy(os.Stdout, r.Body) + if err != nil { + log.Error().Err(err).Msg("Error") + return + } + + handle.fn() +} diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go new file mode 100644 index 000000000..2b35094eb --- /dev/null +++ b/pkg/metrics/metrics.go @@ -0,0 +1,138 @@ +package metrics + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" + + "github.com/crazy-max/diun/v4/internal/model" +) + +var metrics *Metrics + +var staleImages = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "diun_stale_image", + Help: "todo", + }, + []string{"image", "container", "label_schema_group"}, +) + +// Metric is the data points of a single scan +type Metric struct { + Scanned int + Updated int + Failed int + Stale int +} + +// Metrics is the handler processing all individual scan metrics +type Metrics struct { + channel chan *Metric + scanned prometheus.Gauge + updated prometheus.Gauge + failed prometheus.Gauge + stale prometheus.Gauge + total prometheus.Counter + skipped prometheus.Counter + staleImages []prometheus.GaugeVec +} + +// Register registers metrics for an executed scan +func (metrics *Metrics) Register(metric *Metric) { + metrics.channel <- metric +} + +// Default creates a new metrics handler if none exists, otherwise returns the existing one +func Default() *Metrics { + if metrics != nil { + return metrics + } + + prometheus.Register(staleImages) + + metrics = &Metrics{ + scanned: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "diun_containers_scanned", + Help: "Number of containers scanned for changes during the last scan", + }), + updated: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "diun_containers_updated", + Help: "Number of containers updated during the last scan", + }), + failed: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "diun_containers_failed", + Help: "Number of containers where update failed during the last scan", + }), + stale: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "diun_containers_stale", + Help: "Number of containers identified that could be updated during the last scan", + }), + total: promauto.NewCounter(prometheus.CounterOpts{ + Name: "diun_scans_total", + Help: "Number of scans since diun started", + }), + skipped: promauto.NewCounter(prometheus.CounterOpts{ + Name: "diun_scans_skipped", + Help: "Number of skipped scans since diun started", + }), + channel: make(chan *Metric, 10), + } + + go metrics.HandleUpdate(metrics.channel) + + return metrics +} + +// Register a Notifications Metrics. +func RegisterNotification(s model.NotifEntries) { + RegisterScan(NewMetric(s)) + + for _, item := range s.Entries { + labels := prometheus.Labels{"image": item.Image.String(), "container": item.ContainerName, "label_schema_group": ""} + + if v, ok := item.ContainerLabels["diun.label-schema.group"]; ok { + labels = prometheus.Labels{"image": item.Image.String(), "container": item.ContainerName, "label_schema_group": v} + } + + if item.Status == model.ImageStatusStale { + staleImages.With(labels).Set(1) + } else { + staleImages.With(labels).Set(0) + } + } +} + +// RegisterScan fetches a metric handler and enqueues a metric +func RegisterScan(metric *Metric) { + metrics := Default() + metrics.Register(metric) +} + +func NewMetric(s model.NotifEntries) *Metric { + return &Metric{ + Scanned: s.CountTotal, + Stale: s.CountStale, + } +} + +// HandleUpdate dequeue the metric channel and processes it +func (metrics *Metrics) HandleUpdate(channel <-chan *Metric) { + for change := range channel { + if change == nil { + // Update was skipped and rescheduled + metrics.total.Inc() + metrics.skipped.Inc() + metrics.scanned.Set(0) + metrics.updated.Set(0) + metrics.failed.Set(0) + metrics.stale.Set(0) + continue + } + // Update metrics with the new values + metrics.total.Inc() + metrics.scanned.Set(float64(change.Scanned)) + metrics.updated.Set(float64(change.Updated)) + metrics.failed.Set(float64(change.Failed)) + metrics.stale.Set(float64(change.Stale)) + } +} diff --git a/pkg/registry/pullimage.go b/pkg/registry/pullimage.go new file mode 100644 index 000000000..9e1c4fe02 --- /dev/null +++ b/pkg/registry/pullimage.go @@ -0,0 +1,35 @@ +package registry + +import ( + "context" + "io/ioutil" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/client" + "github.com/rs/zerolog/log" +) + +func (c *Client) PullImage(imageName string) error { + ctx := context.Background() + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + log.Err(err) + return err + } + defer cli.Close() + + response, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{}) + if err != nil { + log.Err(err) + return err + } + + defer response.Close() + + // the pull request will be aborted prematurely unless the response is read + if _, err = ioutil.ReadAll(response); err != nil { + log.Err(err) + return err + } + return nil +}