zipkin

package
v0.0.0-...-74c4be5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 33

Documentation

Overview

Package zipkin adds Zipkin tracing support that can be used in conjunction with SpoofingClient to log zipkin traces for requests that have encountered server errors i.e HTTP request that have HTTP status between 500 to 600.

This package exposes following methods:

SetupZipkinTracing(kubernetes.Interface) error
	SetupZipkinTracing sets up zipkin tracing by setting up port-forwarding from
	localhost to zipkin pod on the cluster. On successful setup this method sets
	an internal flag zipkinTracingEnabled to true.

CleanupZipkinTracingSetup() error
	CleanupZipkinTracingSetup cleans up zipkin tracing setup by cleaning up the
	port-forwarding setup by call to SetupZipkinTracing. This method also sets
	zipkinTracingEnabled flag to false.

A general flow for a Test Suite to use Zipkin Tracing support is as follows:

  1. Call SetupZipkinTracing(kubernetes.Interface) in TestMain.
  2. Use SpoofingClient to make HTTP requests.
  3. Call CleanupZipkinTracingSetup on cleanup after tests are executed.

Index

Constants

View Source
const (
	// ZipkinTraceIDHeader HTTP response header key to be used to store Zipkin Trace ID.
	ZipkinTraceIDHeader = "ZIPKIN_TRACE_ID"

	// ZipkinPort is port exposed by the Zipkin Pod
	// https://github.com/knative/serving/blob/main/config/monitoring/200-common/100-zipkin.yaml#L25 configures the Zipkin Port on the cluster.
	ZipkinPort = 9411

	// ZipkinTraceEndpoint port-forwarded zipkin endpoint
	ZipkinTraceEndpoint = "http://localhost:9411/api/v2/trace/"
)

Variables

View Source
var (

	// Deprecated: Use IsTracingEnabled for checking the current state.
	ZipkinTracingEnabled = false
)

Functions

func CleanupZipkinTracingSetup

func CleanupZipkinTracingSetup(logf logging.FormatLogger)

CleanupZipkinTracingSetup cleans up the Zipkin tracing setup on the machine. This involves killing the process performing port-forward. This should be called exactly once in TestMain. Likely in the form:

func TestMain(m *testing.M) {
    os.Exit(func() int {
      // Any setup required for the tests.
      defer zipkin.CleanupZipkinTracingSetup(logger)
      return m.Run()
    }())
}

func IsTracingEnabled

func IsTracingEnabled() bool

IsTracingEnabled indicates if zipkin tracing is enabled.

func JSONTrace

func JSONTrace(traceID string, expected int, timeout time.Duration) ([]model.SpanModel, error)

JSONTrace returns a trace for the given traceID. It will continually try to get the trace. If the trace it gets has the expected number of spans, then it will be returned. If not, it will try again. If it reaches timeout, then it returns everything it has so far with an error.

func JSONTracePred

func JSONTracePred(traceID string, timeout time.Duration, pred func([]model.SpanModel) bool) (trace []model.SpanModel, err error)

JSONTracePred returns a trace for the given traceID. It will continually try to get the trace until the trace spans satisfy the predicate. If the timeout is reached then the last fetched trace tree if available is returned along with an error.

func SetupZipkinTracing

func SetupZipkinTracing(ctx context.Context, kubeClientset kubernetes.Interface, logf logging.FormatLogger, zipkinRemotePort int, zipkinNamespace string) (err error)

SetupZipkinTracing sets up zipkin tracing which involves:

  1. Setting up port-forwarding from localhost to zipkin pod on the cluster (pid of the process doing Port-Forward is stored in a global variable).
  2. Enable AlwaysSample config for tracing for the SpoofingClient.

The zipkin deployment must have the label app=zipkin

func SetupZipkinTracingFromConfigTracing

func SetupZipkinTracingFromConfigTracing(ctx context.Context, kubeClientset kubernetes.Interface, logf logging.FormatLogger, configMapNamespace string) error

SetupZipkinTracingFromConfigTracing setups zipkin tracing like SetupZipkinTracing but retrieving the zipkin configuration from config-tracing config map

func SetupZipkinTracingFromConfigTracingOrFail

func SetupZipkinTracingFromConfigTracingOrFail(ctx context.Context, t testing.TB, kubeClientset kubernetes.Interface, configMapNamespace string)

SetupZipkinTracingFromConfigTracingOrFail is same as SetupZipkinTracingFromConfigTracing, but fails the test if an error happens

func SetupZipkinTracingOrFail

func SetupZipkinTracingOrFail(ctx context.Context, t testing.TB, kubeClientset kubernetes.Interface, zipkinRemotePort int, zipkinNamespace string)

SetupZipkinTracingOrFail is same as SetupZipkinTracing, but fails the test if an error happens

Types

type TimeoutError

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

TimeoutError is an error returned by JSONTrace if it times out before getting the expected number of traces.

func (*TimeoutError) Error

func (t *TimeoutError) Error() string

Jump to

Keyboard shortcuts

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