Skip to content

Commit

Permalink
Remove throttling from blobs
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Laine <[email protected]>
  • Loading branch information
phillebaba committed Oct 7, 2024
1 parent 6bb8a9e commit 819c049
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 235 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- [#596](https://github.com/spegel-org/spegel/pull/596) Remove throttling from blobs.

### Fixed

### Security
Expand Down
1 change: 0 additions & 1 deletion charts/spegel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ spec:
| serviceMonitor.scrapeTimeout | string | `"30s"` | Prometheus scrape interval timeout. |
| spegel.additionalMirrorRegistries | list | `[]` | Additional target mirror registries other than Spegel. |
| spegel.appendMirrors | bool | `false` | When true existing mirror configuration will be appended to instead of replaced. |
| spegel.blobSpeed | string | `""` | Maximum write speed per request when serving blob layers. Should be an integer followed by unit Bps, KBps, MBps, GBps, or TBps. |
| spegel.containerdContentPath | string | `"/var/lib/containerd/io.containerd.content.v1.content"` | Path to Containerd content store.. |
| spegel.containerdMirrorAdd | bool | `true` | If true Spegel will add mirror configuration to the node. |
| spegel.containerdNamespace | string | `"k8s.io"` | Containerd namespace where images are stored. |
Expand Down
3 changes: 0 additions & 3 deletions charts/spegel/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ spec:
- --leader-election-name={{ .Release.Name }}-leader-election
- --resolve-latest-tag={{ .Values.spegel.resolveLatestTag }}
- --local-addr=$(NODE_IP):{{ .Values.service.registry.hostPort }}
{{- with .Values.spegel.blobSpeed }}
- --blob-speed={{ . }}
{{- end }}
{{- with .Values.spegel.containerdContentPath }}
- --containerd-content-path={{ . }}
{{- end }}
Expand Down
2 changes: 0 additions & 2 deletions charts/spegel/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ spegel:
resolveTags: true
# -- When true latest tags will be resolved to digests.
resolveLatestTag: true
# -- Maximum write speed per request when serving blob layers. Should be an integer followed by unit Bps, KBps, MBps, GBps, or TBps.
blobSpeed: ""
# -- When true existing mirror configuration will be appended to instead of replaced.
appendMirrors: false

Expand Down
32 changes: 13 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"net"
"net/http"
"net/http/pprof"
Expand All @@ -13,8 +14,6 @@ import (
"syscall"
"time"

"log/slog"

"github.com/alexflint/go-arg"
"github.com/go-logr/logr"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -28,7 +27,6 @@ import (
"github.com/spegel-org/spegel/pkg/registry"
"github.com/spegel-org/spegel/pkg/routing"
"github.com/spegel-org/spegel/pkg/state"
"github.com/spegel-org/spegel/pkg/throttle"
)

type ConfigurationCmd struct {
Expand All @@ -50,19 +48,18 @@ type BootstrapConfig struct {

type RegistryCmd struct {
BootstrapConfig
BlobSpeed *throttle.Byterate `arg:"--blob-speed,env:BLOB_SPEED" help:"Maximum write speed per request when serving blob layers. Should be an integer followed by unit Bps, KBps, MBps, GBps, or TBps."`
ContainerdRegistryConfigPath string `arg:"--containerd-registry-config-path,env:CONTAINERD_REGISTRY_CONFIG_PATH" default:"/etc/containerd/certs.d" help:"Directory where mirror configuration is written."`
MetricsAddr string `arg:"--metrics-addr,required,env:METRICS_ADDR" help:"address to serve metrics."`
LocalAddr string `arg:"--local-addr,required,env:LOCAL_ADDR" help:"Address that the local Spegel instance will be reached at."`
ContainerdSock string `arg:"--containerd-sock,env:CONTAINERD_SOCK" default:"/run/containerd/containerd.sock" help:"Endpoint of containerd service."`
ContainerdNamespace string `arg:"--containerd-namespace,env:CONTAINERD_NAMESPACE" default:"k8s.io" help:"Containerd namespace to fetch images from."`
ContainerdContentPath string `arg:"--containerd-content-path,env:CONTAINERD_CONTENT_PATH" default:"/var/lib/containerd/io.containerd.content.v1.content" help:"Path to Containerd content store"`
RouterAddr string `arg:"--router-addr,env:ROUTER_ADDR,required" help:"address to serve router."`
RegistryAddr string `arg:"--registry-addr,env:REGISTRY_ADDR,required" help:"address to server image registry."`
Registries []url.URL `arg:"--registries,env:REGISTRIES,required" help:"registries that are configured to be mirrored."`
MirrorResolveTimeout time.Duration `arg:"--mirror-resolve-timeout,env:MIRROR_RESOLVE_TIMEOUT" default:"20ms" help:"Max duration spent finding a mirror."`
MirrorResolveRetries int `arg:"--mirror-resolve-retries,env:MIRROR_RESOLVE_RETRIES" default:"3" help:"Max amount of mirrors to attempt."`
ResolveLatestTag bool `arg:"--resolve-latest-tag,env:RESOLVE_LATEST_TAG" default:"true" help:"When true latest tags will be resolved to digests."`
ContainerdRegistryConfigPath string `arg:"--containerd-registry-config-path,env:CONTAINERD_REGISTRY_CONFIG_PATH" default:"/etc/containerd/certs.d" help:"Directory where mirror configuration is written."`
MetricsAddr string `arg:"--metrics-addr,required,env:METRICS_ADDR" help:"address to serve metrics."`
LocalAddr string `arg:"--local-addr,required,env:LOCAL_ADDR" help:"Address that the local Spegel instance will be reached at."`
ContainerdSock string `arg:"--containerd-sock,env:CONTAINERD_SOCK" default:"/run/containerd/containerd.sock" help:"Endpoint of containerd service."`
ContainerdNamespace string `arg:"--containerd-namespace,env:CONTAINERD_NAMESPACE" default:"k8s.io" help:"Containerd namespace to fetch images from."`
ContainerdContentPath string `arg:"--containerd-content-path,env:CONTAINERD_CONTENT_PATH" default:"/var/lib/containerd/io.containerd.content.v1.content" help:"Path to Containerd content store"`
RouterAddr string `arg:"--router-addr,env:ROUTER_ADDR,required" help:"address to serve router."`
RegistryAddr string `arg:"--registry-addr,env:REGISTRY_ADDR,required" help:"address to server image registry."`
Registries []url.URL `arg:"--registries,env:REGISTRIES,required" help:"registries that are configured to be mirrored."`
MirrorResolveTimeout time.Duration `arg:"--mirror-resolve-timeout,env:MIRROR_RESOLVE_TIMEOUT" default:"20ms" help:"Max duration spent finding a mirror."`
MirrorResolveRetries int `arg:"--mirror-resolve-retries,env:MIRROR_RESOLVE_RETRIES" default:"3" help:"Max amount of mirrors to attempt."`
ResolveLatestTag bool `arg:"--resolve-latest-tag,env:RESOLVE_LATEST_TAG" default:"true" help:"When true latest tags will be resolved to digests."`
}

type Arguments struct {
Expand Down Expand Up @@ -196,9 +193,6 @@ func registryCommand(ctx context.Context, args *RegistryCmd) (err error) {
registry.WithLocalAddress(args.LocalAddr),
registry.WithLogger(log),
}
if args.BlobSpeed != nil {
registryOpts = append(registryOpts, registry.WithBlobSpeed(*args.BlobSpeed))
}
reg := registry.NewRegistry(ociClient, router, registryOpts...)
regSrv, err := reg.Server(args.RegistryAddr)
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/spegel-org/spegel/pkg/metrics"
"github.com/spegel-org/spegel/pkg/oci"
"github.com/spegel-org/spegel/pkg/routing"
"github.com/spegel-org/spegel/pkg/throttle"
)

const (
Expand All @@ -31,7 +30,6 @@ const (
type Registry struct {
bufferPool *buffer.BufferPool
log logr.Logger
throttler *throttle.Throttler
ociClient oci.Client
router routing.Router
transport http.RoundTripper
Expand Down Expand Up @@ -73,12 +71,6 @@ func WithLocalAddress(localAddr string) Option {
}
}

func WithBlobSpeed(blobSpeed throttle.Byterate) Option {
return func(r *Registry) {
r.throttler = throttle.NewThrottler(blobSpeed)
}
}

func WithLogger(log logr.Logger) Option {
return func(r *Registry) {
r.log = log
Expand Down Expand Up @@ -345,9 +337,6 @@ func (r *Registry) handleBlob(rw mux.ResponseWriter, req *http.Request, ref refe
return
}
var w io.Writer = rw
if r.throttler != nil {
w = r.throttler.Writer(rw)
}
rc, err := r.ociClient.GetBlob(req.Context(), ref.dgst)
if err != nil {
rw.WriteError(http.StatusInternalServerError, fmt.Errorf("could not get reader for blob with digest %s: %w", ref.dgst.String(), err))
Expand Down
48 changes: 0 additions & 48 deletions pkg/throttle/byterate.go

This file was deleted.

75 changes: 0 additions & 75 deletions pkg/throttle/byterate_test.go

This file was deleted.

48 changes: 0 additions & 48 deletions pkg/throttle/throttle.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/throttle/throttle_test.go

This file was deleted.

0 comments on commit 819c049

Please sign in to comment.