Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithControllerName(ctx context.Context, controllerName string) context.Context
- func ContextWithLogger(ctx context.Context, logger logr.Logger) context.Context
- func ContextWithResourceID(ctx context.Context, resourceID *azcorearm.ResourceID) context.Context
- func ControllerNameFromContext(ctx context.Context) (string, bool)
- func DefaultLogger() logr.Logger
- func ErrorMessageWithoutLineTracking(err error) string
- func IncrementPanicMetrics(ctx context.Context, r interface{})
- func LoggerFromContext(ctx context.Context) logr.Logger
- func ResourceIDFromContext(ctx context.Context) (*azcorearm.ResourceID, error)
- func TrackError(err error) error
- func VerifyErrorsMatch(t *testing.T, expectedErrors []ExpectedError, errs field.ErrorList)
- type ContextError
- type ExpectedError
- type FSWatcher
- type LineTrackingError
- type LogValues
- func (lv LogValues) AddAPIVersion(value string) LogValues
- func (lv LogValues) AddClientRequestID(value string) LogValues
- func (lv LogValues) AddCloudErrorCode(value string) LogValues
- func (lv LogValues) AddCloudErrorMessage(value string) LogValues
- func (lv LogValues) AddControllerName(value string) LogValues
- func (lv LogValues) AddCorrelationRequestID(value string) LogValues
- func (lv LogValues) AddCosmosResourceID(value string) LogValues
- func (lv LogValues) AddHCPClusterName(value string) LogValues
- func (lv LogValues) AddInternalID(value string) LogValues
- func (lv LogValues) AddLogValuesForResourceID(resourceID *azcorearm.ResourceID) LogValues
- func (lv LogValues) AddLogValuesForResourceIDString(resourceIDString string) LogValues
- func (lv LogValues) AddMethod(value string) LogValues
- func (lv LogValues) AddOperation(value string) LogValues
- func (lv LogValues) AddOperationID(value string) LogValues
- func (lv LogValues) AddPath(value string) LogValues
- func (lv LogValues) AddRequestID(value string) LogValues
- func (lv LogValues) AddResourceGroup(value string) LogValues
- func (lv LogValues) AddResourceID(value string) LogValues
- func (lv LogValues) AddResourceName(value string) LogValues
- func (lv LogValues) AddResourceType(value string) LogValues
- func (lv LogValues) AddSubscriptionID(value string) LogValues
Constants ¶
const TracerName = "github.com/Azure/ARO-HCP/frontend"
Variables ¶
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 ContextWithLogger ¶
func ContextWithResourceID ¶
func DefaultLogger ¶
func ErrorMessageWithoutLineTracking ¶
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 ResourceIDFromContext ¶
func ResourceIDFromContext(ctx context.Context) (*azcorearm.ResourceID, error)
func TrackError ¶
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 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 ¶
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 (LogValues) AddClientRequestID ¶
AddClientRequestID adds the "client_request_id" key with the lowercased value.
func (LogValues) AddCloudErrorCode ¶
AddCloudErrorCode adds the "cloud_error_code" key with the lowercased value.
func (LogValues) AddCloudErrorMessage ¶
AddCloudErrorMessage adds the "cloud_error_message" key with the lowercased value.
func (LogValues) AddControllerName ¶
AddControllerName adds the "controller_name" key with the lowercased value.
func (LogValues) AddCorrelationRequestID ¶
AddCorrelationRequestID adds the "correlation_request_id" key with the lowercased value.
func (LogValues) AddCosmosResourceID ¶
AddCosmosResourceID adds the "cosmos_resource_id" key with the lowercased value.
func (LogValues) AddHCPClusterName ¶
AddHCPClusterName adds the "hcp_cluster_name" key with the lowercased value.
func (LogValues) AddInternalID ¶
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 ¶
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) AddOperation ¶
AddOperation adds the "operation" key with the lowercased value.
func (LogValues) AddOperationID ¶
AddOperationID adds the "operation_id" key with the lowercased value.
func (LogValues) AddRequestID ¶
func (LogValues) AddResourceGroup ¶
AddResourceGroup adds the "resource_group" key with the lowercased value.
func (LogValues) AddResourceID ¶
AddResourceID adds the "resource_id" key with the lowercased value.
func (LogValues) AddResourceName ¶
AddResourceName adds the "resource_name" key with the lowercased value.
func (LogValues) AddResourceType ¶
func (LogValues) AddSubscriptionID ¶
AddSubscriptionID adds the "subscription_id" key with the lowercased value.