report

package
v0.0.0-...-07a72d5 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithStateConfigMapName

func WithStateConfigMapName(value string) rightSizerReportBuilderOption

WithStateConfigMapName sets the corresponding field in a RightSizerReportBuilder type.

func WithStateConfigMapNamespace

func WithStateConfigMapNamespace(value string) rightSizerReportBuilderOption

WithStateConfigMapNamespace sets the corresponding field in a RightSizerReportBuilder type.

func WithTooOldAge

func WithTooOldAge(value time.Duration) rightSizerReportBuilderOption

WithTooOldAge sets the corresponding field in a RightSizerReportBuilder type.

Types

type RightSizerReportBuilder

type RightSizerReportBuilder struct {
	Report *RightSizerReportProperties

	HTTPServer *http.Server // Allows retrieving the current report
	// contains filtered or unexported fields
}

RightSizerReportBuilder holds internal resources required to create and manipulate a RightSizerReport

func NewRightSizerReportBuilder

func NewRightSizerReportBuilder(kubeClientResources util.KubeClientResources, options ...rightSizerReportBuilderOption) *RightSizerReportBuilder

NewRightSizerReportBuilder returns a pointer to a new initialized RightSizerReportBuilder type.

func (*RightSizerReportBuilder) CreateRightSizerReportItem

func (b *RightSizerReportBuilder) CreateRightSizerReportItem(podController *unstructured.Unstructured, container *core.Container) *RightSizerReportItem

CreateRightSizerReportItem constructs a new report item using fields from the specified resources, and any existing report item of the same Kubernetes kind, namespace, and name. Although the unstructured.Unstructured pod-controller contains a `Containers` block, A separate core.Container is required for situations where the container is not defined in the pod-controller, such asinjection by Kubernetes admission webhooks.

func (*RightSizerReportBuilder) GetConfigAsString

func (b *RightSizerReportBuilder) GetConfigAsString() string

GetConfigAsString returns RightSizerReportBuilder configuration struct members formatted as a string for pretty-printing, such as logs. This does not return all struct fields.

func (*RightSizerReportBuilder) GetNumItems

func (b *RightSizerReportBuilder) GetNumItems() int

GetNumItems returns the number of items currently in the report.

func (*RightSizerReportBuilder) GetReportJSON

func (b *RightSizerReportBuilder) GetReportJSON() ([]byte, error)

GetReportJSON( returns the RightSizerReport in JSON form.

func (*RightSizerReportBuilder) HealthHandler

func (b *RightSizerReportBuilder) HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler handles HTTP requests for Kubernetes health checks.

func (*RightSizerReportBuilder) LoopRemoveOldItems

func (b *RightSizerReportBuilder) LoopRemoveOldItems()

LoopRemoveOldItems calls RemoveOldItems() every minute, and calls RightSizerReportBuilder.WriteConfigMap() if any items were removed. This is meant to be run in its own Go ruiteen.

func (*RightSizerReportBuilder) MatchItems

func (b *RightSizerReportBuilder) MatchItems(resourceKind, resourceNamespace, resourceName string) *[]RightSizerReportItem

MatchItems returns a pointer to a slice of RightSizerReportItem matching the supplied kind, namespace, and resource name. IF no items match, nil is returned. There may be multiple matches, differing by other fields such as ResourceContainer.

func (*RightSizerReportBuilder) MatchItemsOlderWithModifiedMemoryLimits

func (b *RightSizerReportBuilder) MatchItemsOlderWithModifiedMemoryLimits(involvedObject core.ObjectReference) (*[]RightSizerReportItem, error)

MatchItemsOlderWithModifiedMemoryLimits wraps a call to MatchItems(), only returning matches where items have an older ResourceGeneration than the `metadata.generation` field of the current in-cluster resource, and whos memory limits are different from those last seen/updated in our report. The current resource is fetched from Kube via core/v1.ObjectReference, typically provided along with a Kube Event.

func (*RightSizerReportBuilder) PopulateExistingItemFields

func (b *RightSizerReportBuilder) PopulateExistingItemFields(yourItem *RightSizerReportItem) (foundItem bool)

PopulateExistingItemFields finds the specified report item via its unique fields, and populates the rest of the fields. The unique fields are kind, namespace, and resource name.

func (*RightSizerReportBuilder) ReadConfigMap

func (b *RightSizerReportBuilder) ReadConfigMap() error

ReadConfigMap reads the report from a Kubernetes ConfigMap resource. IF the ConfigMap does not exist, the report remains unchanged, and a new (empty) ConfigMap is created so the Insights Uploader has something to read. This is useful to populate the report with previous data on Kubernetes controller startup.

func (*RightSizerReportBuilder) RemoveItems

func (b *RightSizerReportBuilder) RemoveItems(removeItems []RightSizerReportItem) (anyItemsRemoved bool)

RemoveItems accepts a slice of RightSizerReportItems, and removes them from the report, returning true if any items were removed. Only the fields included in RightSizerReportItem.String() are compared, when matching an item for removal.

func (*RightSizerReportBuilder) RemoveOldItems

func (b *RightSizerReportBuilder) RemoveOldItems() (anyItemsRemoved bool)

RemoveOldItems removes items from the report that have a last OOMKill older than RightSizerReportBuilder.tooOldAge, and returns true if any items were removed.

func (*RightSizerReportBuilder) RemoveRelatedItemsOlderWithModifiedMemoryLimits

func (b *RightSizerReportBuilder) RemoveRelatedItemsOlderWithModifiedMemoryLimits(objRef core.ObjectReference) error

RemoveRelatedItemsOlderWithModifiedMemoryLimits wraps a call to MatchRelatedItemsOlderWithModifiedMemoryLimits, removing any report items that match.

func (*RightSizerReportBuilder) ReportHandler

func (b *RightSizerReportBuilder) ReportHandler(w http.ResponseWriter, r *http.Request)

ReportHandler handles HTTP requests by serving the report as JSON.

func (RightSizerReportBuilder) RunServer

func (b RightSizerReportBuilder) RunServer()

RunServer starts the report builder HTTP server and registers the report handler. This server can be used to retrieve the current report JSON or issue health checks.

func (*RightSizerReportBuilder) StoreItem

func (b *RightSizerReportBuilder) StoreItem(newItem RightSizerReportItem)

StoreItem accepts a RightSizerReportItem and adds or updates it in the report. If the item already exists, `FirstOOM` and `StartingMemory` fields are retained from the original, and all other fields are updated from the new item.

func (*RightSizerReportBuilder) WriteConfigMap

func (b *RightSizerReportBuilder) WriteConfigMap() error

WriteConfigMap writes the report to a Kubernetes ConfigMap resource. IF the ConfigMap does not exist, it will be created.

type RightSizerReportItem

type RightSizerReportItem struct {
	Kind               string             `json:"kind"`
	ResourceName       string             `json:"resourceName"`
	ResourceNamespace  string             `json:"resourceNamespace"`
	ResourceContainer  string             `json:"resourceContainer"`
	StartingMemory     *resource.Quantity `json:"startingMemory"`
	EndingMemory       *resource.Quantity `json:"endingMemory"`
	NumOOMs            int64              `json:"numOOMs"`
	FirstOOM           time.Time          `json:"firstOOM"`
	LastOOM            time.Time          `json:"lastOOM"`
	ResourceGeneration int64              `json:"resourceGeneration"`
}

RightSizerReportItem contains properties of a right-sizer item.

func (RightSizerReportItem) IncrementMemory

func (i RightSizerReportItem) IncrementMemory(currentMemory *resource.Quantity, incrementMultiplier, maxMultiplier float64) *resource.Quantity

IncrementMemory validates that incrementing a RightSizerReportItem memory limits would not exceed the specified maximum, then returns a resource.Quantity reflecting the incremented value. An empty resource.Quantity is returned if incrementing is not allowed because it would exceed the maximum.

func (RightSizerReportItem) MaxAllowedEndingMemory

func (i RightSizerReportItem) MaxAllowedEndingMemory(maxMultiplier float64) (*resource.Quantity, error)

MaxAllowedEndingMemory returns a resource.Quantity that is the highest a report item memory limits is allowed to be increased. This is determined by multiplying the item starting memory limits by the supplied factor.

func (RightSizerReportItem) String

func (i RightSizerReportItem) String() string

String represents unique fields to differentiate a report item.

func (RightSizerReportItem) StringFull

func (i RightSizerReportItem) StringFull() string

StringFull represents all fields of a report item, for pretty-printing, such as debug logs.

type RightSizerReportProperties

type RightSizerReportProperties struct {
	Items []RightSizerReportItem `json:"items"`
}

RightSizerReportProperties holds multiple right-sizer-items

Jump to

Keyboard shortcuts

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