monitor

package
v0.0.0-...-c0ae054 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Reports global metrics about all PodProtector objects.

Index

Constants

View Source
const ProportionPpmUnits = 1000000

Variables

View Source
var New = component.Declare[Args, Options, Deps, State, util.Empty](
	func(Args) string { return "generator-monitor" },
	func(_ Args, fs *flag.FlagSet) Options {
		return Options{
			Enable: fs.Bool("enable", true, "Enable global PodProtector monitor"),
		}
	},
	func(_ Args, requests *component.DepRequests) Deps {
		return Deps{
			observer: o11y.Request[observer.Observer](requests),
			podseidonInformers: component.DepPtr(requests, kube.NewInformers(kube.PodseidonInformers(
				constants.CoreClusterName,
				constants.LeaderPhase,
				optional.Some(constants.GeneratorElectorArgs),
			))),
		}
	},
	func(_ context.Context, _ Args, options Options, deps Deps) (*State, error) {
		state := &State{
			statusMu:        sync.Mutex{},
			status:          util.Zero[observer.MonitorWorkloads](),
			addedDeltaCache: map[types.NamespacedName]observer.MonitorWorkloads{},
		}

		if *options.Enable {
			pprInformer := deps.podseidonInformers.Get().Podseidon().V1alpha1().PodProtectors()
			_, err := pprInformer.Informer().AddEventHandler(kube.GenericEventHandlerWithStaleState(
				func(ppr *podseidonv1a1.PodProtector, stillPresent bool) {
					nsName := types.NamespacedName{Namespace: ppr.Namespace, Name: ppr.Name}

					if stillPresent {
						status := pprToStatus(ppr)
						state.add(nsName, status)
					} else {
						state.remove(nsName)
					}
				},
			))
			if err != nil {
				return nil, errors.TagWrapf("AddEventHandler", err, "add event handler to ppr informer")
			}
		}

		return state, nil
	},
	component.Lifecycle[Args, Options, Deps, State]{
		Start: func(ctx context.Context, _ *Args, options *Options, deps *Deps, state *State) error {
			if *options.Enable {
				deps.observer.Get().MonitorWorkloads(ctx, util.Empty{}, func() observer.MonitorWorkloads {
					state.statusMu.Lock()
					defer state.statusMu.Unlock()

					return state.status
				})
			}

			return nil
		},
		Join:         nil,
		HealthChecks: nil,
	},
	func(_ *component.Data[Args, Options, Deps, State]) util.Empty { return util.Empty{} },
)

Functions

This section is empty.

Types

type Args

type Args struct{}

type Deps

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

type Options

type Options struct {
	Enable *bool
}

type State

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

Jump to

Keyboard shortcuts

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