utils

package
v0.0.0-...-7d5d04f Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const TracerName = "github.com/Azure/ARO-HCP/frontend"

Variables

View Source
var (
	// PanicTotal counts the total number of panics caught byt this handler.
	// If available, it labels by controller.  If not available, they go into "" bucket.
	// This could be expanded later for a resource type for the frontend if necessay, but something
	// counting crashes is better than nothing.
	PanicTotal = promauto.With(legacyregistry.Registerer()).NewCounterVec(
		prometheus.CounterOpts{
			Name: "panic_total",
			Help: "Total number of panics per controller.",
		},
		[]string{"controller"},
	)
)

Functions

func ContextWithControllerName

func ContextWithControllerName(ctx context.Context, controllerName string) context.Context

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger logr.Logger) context.Context

func ContextWithResourceID

func ContextWithResourceID(ctx context.Context, resourceID *azcorearm.ResourceID) context.Context

func ControllerNameFromContext

func ControllerNameFromContext(ctx context.Context) (string, bool)

func DefaultLogger

func DefaultLogger() logr.Logger

func ErrorMessageWithoutLineTracking

func ErrorMessageWithoutLineTracking(err error) string

ErrorMessageWithoutLineTracking returns err.Error() after peeling zero or more *LineTrackingError wrappers (from TrackError). Use this when persisting or surfacing errors to users so internal file/line prefixes are not included.

func IncrementPanicMetrics

func IncrementPanicMetrics(ctx context.Context, r interface{})

func LoggerFromContext

func LoggerFromContext(ctx context.Context) logr.Logger

func ResourceIDFromContext

func ResourceIDFromContext(ctx context.Context) (*azcorearm.ResourceID, error)

func TrackError

func TrackError(err error) error

TrackError creates a new LineTrackingError that wraps the provided error and captures the caller's file and line number information.

func VerifyErrorsMatch

func VerifyErrorsMatch(t *testing.T, expectedErrors []ExpectedError, errs field.ErrorList)

Types

type ContextError

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

func (*ContextError) Error

func (c *ContextError) Error() string

type ExpectedError

type ExpectedError struct {
	Message   string // Expected error message (partial match)
	FieldPath string // Expected field path for the error
}

type FSWatcher

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

FSWatcher watches a file for content changes using hash-based change detection. Changes are detected through periodic checks at the configured interval.

func NewFSWatcher

func NewFSWatcher(filePath string, checkInterval time.Duration, onChange func(ctx context.Context) error) (*FSWatcher, error)

NewFSWatcher creates a new file system watcher that monitors a file for content changes.

Parameters:

  • filePath: the file to watch (e.g., /mnt/secrets/cert.pem)
  • checkInterval: how often to check for changes (must be > 0)
  • onChange: callback invoked when file content changes (required), receives context for logging

func (*FSWatcher) Start

func (w *FSWatcher) Start(ctx context.Context) error

Start begins watching the file for content changes.

The initial file hash is computed before starting the background watcher to ensure the file exists and is readable. The watcher then runs in a background goroutine until ctx is canceled.

Changes are detected through periodic hash checks at the configured checkInterval. When a change is detected, the onChange callback is invoked.

type LineTrackingError

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

LineTrackingError wraps an existing error and tracks the file and line number where the error was created, providing detailed origin information when printed.

func (*LineTrackingError) Error

func (e *LineTrackingError) Error() string

Error implements the error interface and returns a formatted string showing both the original error and the location where it was wrapped.

func (*LineTrackingError) Unwrap

func (e *LineTrackingError) Unwrap() error

Unwrap returns the original wrapped error, enabling errors.As and errors.Is to work correctly with the underlying error type.

type LogValues

type LogValues []any

LogValues is a slice of key/value pairs for use with logger.WithValues. It supports method chaining for a fluent API:

logger.WithValues(
    utils.LogValues{}.
        AddOperation(val).
        AddResourceGroup(val).
        AddResourceName(val)...)

This allows us keep our kusto indexing in sync, allow the evolution of keys, and allows for consistent redaction of values.

func (LogValues) AddAPIVersion

func (lv LogValues) AddAPIVersion(value string) LogValues

func (LogValues) AddClientRequestID

func (lv LogValues) AddClientRequestID(value string) LogValues

AddClientRequestID adds the "client_request_id" key with the lowercased value.

func (LogValues) AddCloudErrorCode

func (lv LogValues) AddCloudErrorCode(value string) LogValues

AddCloudErrorCode adds the "cloud_error_code" key with the lowercased value.

func (LogValues) AddCloudErrorMessage

func (lv LogValues) AddCloudErrorMessage(value string) LogValues

AddCloudErrorMessage adds the "cloud_error_message" key with the lowercased value.

func (LogValues) AddControllerName

func (lv LogValues) AddControllerName(value string) LogValues

AddControllerName adds the "controller_name" key with the lowercased value.

func (LogValues) AddCorrelationRequestID

func (lv LogValues) AddCorrelationRequestID(value string) LogValues

AddCorrelationRequestID adds the "correlation_request_id" key with the lowercased value.

func (LogValues) AddCosmosResourceID

func (lv LogValues) AddCosmosResourceID(value string) LogValues

AddCosmosResourceID adds the "cosmos_resource_id" key with the lowercased value.

func (LogValues) AddHCPClusterName

func (lv LogValues) AddHCPClusterName(value string) LogValues

AddHCPClusterName adds the "hcp_cluster_name" key with the lowercased value.

func (LogValues) AddInternalID

func (lv LogValues) AddInternalID(value string) LogValues

AddInternalID adds the "internal_id" key with the lowercased value.

func (LogValues) AddLogValuesForResourceID

func (lv LogValues) AddLogValuesForResourceID(resourceID *azcorearm.ResourceID) LogValues

AddLogValuesForResourceID adds common logging key/value pairs from a resource ID. It adds: subscription_id, resource_group, resource_name, resource_id, and hcp_cluster_name (if applicable).

func (LogValues) AddLogValuesForResourceIDString

func (lv LogValues) AddLogValuesForResourceIDString(resourceIDString string) LogValues

AddLogValuesForResourceIDString parses a resource ID string and adds common logging key/value pairs. It adds: subscription_id, resource_group, resource_name, and resource_id. If parsing fails, only the resource_id is added.

func (LogValues) AddMethod

func (lv LogValues) AddMethod(value string) LogValues

AddMethod adds the "method" key with the lowercased value.

func (LogValues) AddOperation

func (lv LogValues) AddOperation(value string) LogValues

AddOperation adds the "operation" key with the lowercased value.

func (LogValues) AddOperationID

func (lv LogValues) AddOperationID(value string) LogValues

AddOperationID adds the "operation_id" key with the lowercased value.

func (LogValues) AddPath

func (lv LogValues) AddPath(value string) LogValues

AddPath adds the "path" key with the lowercased value.

func (LogValues) AddRequestID

func (lv LogValues) AddRequestID(value string) LogValues

func (LogValues) AddResourceGroup

func (lv LogValues) AddResourceGroup(value string) LogValues

AddResourceGroup adds the "resource_group" key with the lowercased value.

func (LogValues) AddResourceID

func (lv LogValues) AddResourceID(value string) LogValues

AddResourceID adds the "resource_id" key with the lowercased value.

func (LogValues) AddResourceName

func (lv LogValues) AddResourceName(value string) LogValues

AddResourceName adds the "resource_name" key with the lowercased value.

func (LogValues) AddResourceType

func (lv LogValues) AddResourceType(value string) LogValues

func (LogValues) AddSubscriptionID

func (lv LogValues) AddSubscriptionID(value string) LogValues

AddSubscriptionID adds the "subscription_id" key with the lowercased value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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