internal

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UserAgent = fmt.Sprintf("opentelemetry-go/%s", opentelemetry.Version())

UserAgent is the user agent to be added to the outgoing requests from the exporters.

Functions

func MonotonicEndTime

func MonotonicEndTime(start time.Time) time.Time

MonotonicEndTime returns the end time at present but offset from start, monotonically.

The monotonic clock is used in subtractions hence the duration since start added back to start gives end as a monotonic time. See https://golang.org/pkg/time/#hdr-Monotonic_Clocks

func Sanitize

func Sanitize(s string) string

Sanitize returns a string that is trunacated to 100 characters if it's too long, and replaces non-alphanumeric characters to underscores.

Types

type StateLocker

type StateLocker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StateLocker implements a two state lock algorithm that enabled lock free operations inside a state and a global lock for switching between states. At every time, only one state is active and one cold state. States are represented by int numbers 0 and 1.

This was inspired by the algorithm used on the prometheus client library that can be found at: https://github.com/prometheus/client_golang/blob/e7776d2c54305c1b62fdb113b5a7e9b944c5c27e/prometheus/histogram.go#L227

To execute operations within the same state, call `Start()` before the operation and call `End(idx)` to end this operation. The `idx` argument of `End()` is the index of the active state when the operation started and it is returned by the `Start()` method. It is recommended to defer the call to `End(idx)`.

One can change the active state by calling `SwapActiveState(fn)`. `fn` is a function that will be executed *before* switching the active state. Operations such as preparing the new state shall be called by this function. This will wait in-flight operations to end.

Example workflow: 1. State 0 is active. 1.1 Operations to the active state can happen with `Start()` and `End(idx)` methods. 2. Call to `SwitchState(fn)` 2.1 run `fn` function to prepare the new state 2.2 make state 1 active 2.3 wait in-flight operations of the state 0 to end. 3. State 1 is now active and every new operation are executed in it.

`SwitchState(fn)` are synchronized with a mutex that can be access with the `Lock()` and `Unlock()` methods. Access to the cold state must also be synchronized to ensure the cold state is not in the middle of state switch since that could represent an invalid state.

func (*StateLocker) ColdIdx

func (c *StateLocker) ColdIdx() int

ColdIdx returns the index of the cold state.

func (*StateLocker) End

func (c *StateLocker) End(idx int)

End an operation that happened to the idx state.

func (*StateLocker) Start

func (c *StateLocker) Start() int

Start an operation that will happen on a state. The current active state is returned. A call to `End(idx int)` must happens for every `Start()` call.

func (*StateLocker) SwapActiveState

func (c *StateLocker) SwapActiveState(beforeFn func())

SwapActiveState swaps the cold and active states.

This will wait all for in-flight operations that are happening to the current active state to end, this ensure that all access to this state will be consistent.

This is synchronized by a mutex.

Jump to

Keyboard shortcuts

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