bundleuri

package
v18.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package bundleuri is used to enable the use Bundle-URI when the client clones/fetches from the repository.

Bundle-URI is a concept in Git that allows the server to send one or more URIs where git bundles are available. The client can download such bundles to pre-populate the repository before it starts the object negotiation with the server. This reduces the CPU load on the server, and the amount of traffic that has to travel directly from server to client.

Index

Constants

View Source
const (
	// VirtualStorageKey is used to retrieve the virtual storage
	// from the gRPC metadata of a request. It is a duplicate constant
	// from here: /internal/praefect/coordinator.gp
	// Importing it would produce cyclic dependency issue.
	VirtualStorageKey = "virtual_storage"
)

Variables

This section is empty.

Functions

func CapabilitiesGitConfig

func CapabilitiesGitConfig(ctx context.Context, enable bool) []gitcmd.ConfigPair

CapabilitiesGitConfig returns a slice of gitcmd.ConfigPairs that can be injected into the Git config to enable or disable bundle-uri capability.

If the feature flag is OFF, this config disables bundle-uri regardless of the `enable` parameter.

Explicitly disabling bundle-uri capability is used during calls to git-upload-pack(1) when no bundle exists for the given repository. This prevents the client from requesting a non-existing URI.

This function is also used when spawning git-upload-pack(1) --advertise-refs in response to the GET /info/refs request.

func UploadPackGitConfig

func UploadPackGitConfig(ctx context.Context, signedURL string) []gitcmd.ConfigPair

UploadPackGitConfig return a slice of gitcmd.ConfigPairs you can inject into the call to git-upload-pack(1) to advertise the available bundle to the client who clones/fetches from the repository.

Types

type GenerationManager

type GenerationManager struct {
	// contains filtered or unexported fields
}

GenerationManager manages bundle generation. It handles requests to generate bundles for a repository, and enforces concurrency by limiting one bundle generation per repo at any given time as well as a global limit across all repositories.

func NewGenerationManager

func NewGenerationManager(ctx context.Context, sink *Sink, logger log.Logger, nodeManager storage.Node, strategy GenerationStrategy) (*GenerationManager, error)

NewGenerationManager creates a new GenerationManager ctx must be a cancellable context. It will be passed to the function generating bundles and writing bundles to storage. If ctx gets cancelled, all bundles currently being generated at that moment will also be cancelled.

func (*GenerationManager) Collect

func (g *GenerationManager) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*GenerationManager) Describe

func (g *GenerationManager) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*GenerationManager) Generate

func (g *GenerationManager) Generate(ctx context.Context, repo *localrepo.Repo) (returnErr error)

Generate will generate a bundle for the given `repo`. This method does not attempt to verify any feature flag or conditions. Calling this method WILL generate a bundle.

func (*GenerationManager) GenerateWithStrategy

func (g *GenerationManager) GenerateWithStrategy(ctx context.Context, repo *localrepo.Repo) error

GenerateWithStrategy runs the strategy within the manager to determine if a bundle must be generated.

func (*GenerationManager) SignedURL

func (g *GenerationManager) SignedURL(ctx context.Context, repo storage.Repository) (string, error)

SignedURL returns a public URL to give anyone access to download the bundle from.

func (*GenerationManager) UploadPackGitConfig

func (g *GenerationManager) UploadPackGitConfig(ctx context.Context, repo storage.Repository) []gitcmd.ConfigPair

UploadPackGitConfig is a helper function to provide all required, and computed, configurations to inject into the `git-upload-pack` command in order to advertise `bundle-uri` and provide the URI for the bundle for the given repository.

type GenerationStrategy

type GenerationStrategy interface {
	// Evaluate evaluates if a bundle must be generated for the given repository, and
	// calls the callback function `cb` if it does.
	// - ctx: must be the context of the current RPC
	// - repo: the repository for which the strategy must determine if a bundle needs to be generated
	// - cb: a callback function to be called **only if** the strategy determines that a bundle must be generated
	Evaluate(ctx context.Context, repo *localrepo.Repo, cb StrategyCallbackFn) error
}

GenerationStrategy is the common interface that all bundle generation strategies must implement.

type OccurrenceStrategy

type OccurrenceStrategy struct {
	// contains filtered or unexported fields
}

OccurrenceStrategy is a strategy type that generates a bundle for a given repository only if n occurrences happened during a pre-determined interval. To avoid generating too much of the same bundle, it also keeps track of the last time a bundle was generated, and make sure to never generate a bundle that is newer than `maxBundleAge`.

func NewOccurrenceStrategy

func NewOccurrenceStrategy(logger log.Logger, threshold int, interval time.Duration, maxConcurrent int, maxBundleAge time.Duration) (*OccurrenceStrategy, error)

NewOccurrenceStrategy creates a new OccurrenceStrategy. It initializes the internal state of the strategy.

  • threshold: The amount of occurrences within an interval that should trigger a bundle generation. A value of 1 or below indicate that a bundle should be generated everytime.
  • interval: the interval in which `n` occurrences must happen to trigger a bundle generation
  • maxBundleAge: the duration within which an already existing bundle should not be overwritten by a new one

func (*OccurrenceStrategy) Collect

func (s *OccurrenceStrategy) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*OccurrenceStrategy) Describe

func (s *OccurrenceStrategy) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*OccurrenceStrategy) Evaluate

Evaluate prepares an evaluateRequest and sends it to the evaluateQueue for further processing.

func (*OccurrenceStrategy) Start

func (s *OccurrenceStrategy) Start(ctx context.Context) (stop func())

Start must be called before calling `Evaluate`. It starts the listener on the evaluateQueue in order to process the evaluateRequests.

type SimpleStrategy

type SimpleStrategy struct {
	// contains filtered or unexported fields
}

SimpleStrategy is a very simple strategy used for testing. Either it always generate a bundle or it doesn't.

func NewSimpleStrategy

func NewSimpleStrategy(always bool) *SimpleStrategy

NewSimpleStrategy creates a new simpleStrategy

func (SimpleStrategy) Evaluate

Evaluate calls the cb if always is true.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink is a wrapper around the storage bucket used for accessing/writing bundleuri bundles.

func NewSink

func NewSink(ctx context.Context, uri string) (*Sink, error)

NewSink creates a Sink from the given parameters.

type StrategyCallbackFn

type StrategyCallbackFn func(ctx context.Context, repo *localrepo.Repo) error

StrategyCallbackFn defines a function type that the `Evaluate` method of the `GenerationStrategy` expects as a callback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL