api

package
v0.0.0-...-b7b0d94 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func KObj

func KObj(obj proto.Metadata) fmt.Stringer

KObj wraps a proto.Metadata to normalize log values.

Note: This is similar klog.KObj, except references proto.Metadata and avoids reflection calls that don't compile in TinyGo 0.28

func KObjSlice

func KObjSlice[M proto.Metadata](objs []M) fmt.Stringer

KObjSlice wraps a slice of proto.Metadata to normalize log values.

Note: This is similar klog.KObjSlice, except references proto.Metadata and avoids reflection calls that don't compile in TinyGo 0.28

func KObjSliceFn

func KObjSliceFn[M proto.Metadata](lazy func() []M) fmt.Stringer

KObjSliceFn wraps function that produces a slice of proto.Metadata to normalize log values.

Note: This is the same as KObjSlice, except avoids calling a function when logging is disabled.

Types

type Klog

type Klog interface {
	// Info records an event at INFO level.
	//
	// The event is a concatenation of the arguments. A newline is appended when
	// the last arg doesn't already end with one.
	//
	// # Notes
	//
	//   - See Klog godoc for an example.
	//   - Wrap args in objectRef where possible, to normalize the output of types
	//     such as proto.Pod.
	Info(args ...any)

	// InfoS is like klog.InfoS. This records the description of an event,
	// `msg` followed by key/value pairs to describe it.
	//
	// # Notes
	//
	//   - See Klog godoc for an example.
	//   - Wrap values in objectRef where possible, to normalize the output of types
	//     such as proto.Pod.
	InfoS(msg string, keysAndValues ...any)

	// Error is like Info, except ERROR level.
	Error(args ...any)

	// ErrorS is like InfoS, except ERROR level. Also, the `err` parameter
	// becomes the value of the "err" key in `keysAndValues`.
	ErrorS(err error, msg string, keysAndValues ...any)
}

Klog is a logger that exposes functions typically in the klog package.

This contains functions like klog.Info, but allows flexibility to disable logging in WebAssembly, where it is more expensive due to inlined garbage collection.

Note: Embed UnimplementedKlog when implementing for real or test usage.

Example
/*
   Copyright 2023 The Kubernetes Authors.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package main

import (
	"fmt"

	"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto"
	"sigs.k8s.io/kube-scheduler-wasm-extension/guest/klog/api"
)

var (
	klog api.Klog = api.UnimplementedKlog{}
	pod  proto.Pod
)

func main() {
	klog.Info("NodeNumberArgs is successfully applied")

	// For structured logging, use pairs, wrapping values in api.KObj where possible.
	klog.InfoS("execute Score on NodeNumber plugin", "pod", api.KObj(pod))

	metricName := "scheduler_framework_extension_point_duration_milliseconds"
	err := fmt.Errorf("metric %q not found", metricName)
	klog.Error(err)

	bucketSize := 32
	histBucketSize := 16
	index := 2
	err = fmt.Errorf("found different bucket size: expect %v, but got %v at index %v", bucketSize, histBucketSize, index)
	labels := map[string]string{"Name": "some-name"}
	klog.ErrorS(err, "the validation for HistogramVec is failed. The data for this metric won't be stored in a benchmark result file", "metric", metricName, "labels", labels)

}
Output:

type UnimplementedKlog

type UnimplementedKlog struct{}

func (UnimplementedKlog) Error

func (UnimplementedKlog) Error(args ...any)

Error implements Klog.Error

func (UnimplementedKlog) ErrorS

func (UnimplementedKlog) ErrorS(err error, msg string, keysAndValues ...any)

ErrorS implements Klog.ErrorS

func (UnimplementedKlog) Info

func (UnimplementedKlog) Info(args ...any)

Info implements Klog.Info

func (UnimplementedKlog) InfoS

func (UnimplementedKlog) InfoS(msg string, keysAndValues ...any)

InfoS implements Klog.InfoS

Jump to

Keyboard shortcuts

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