mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to 862b22d7
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
85
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/exporter.go
generated
vendored
Normal file
85
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/exporter.go
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// Copyright The OpenTelemetry 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 tracetest is a testing helper package for the SDK. User can
|
||||
// configure no-op or in-memory exporters to verify different SDK behaviors or
|
||||
// custom instrumentation.
|
||||
package tracetest // import "go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
var _ trace.SpanExporter = (*NoopExporter)(nil)
|
||||
|
||||
// NewNoopExporter returns a new no-op exporter.
|
||||
func NewNoopExporter() *NoopExporter {
|
||||
return new(NoopExporter)
|
||||
}
|
||||
|
||||
// NoopExporter is an exporter that drops all received spans and performs no
|
||||
// action.
|
||||
type NoopExporter struct{}
|
||||
|
||||
// ExportSpans handles export of spans by dropping them.
|
||||
func (nsb *NoopExporter) ExportSpans(context.Context, []trace.ReadOnlySpan) error { return nil }
|
||||
|
||||
// Shutdown stops the exporter by doing nothing.
|
||||
func (nsb *NoopExporter) Shutdown(context.Context) error { return nil }
|
||||
|
||||
var _ trace.SpanExporter = (*InMemoryExporter)(nil)
|
||||
|
||||
// NewInMemoryExporter returns a new InMemoryExporter.
|
||||
func NewInMemoryExporter() *InMemoryExporter {
|
||||
return new(InMemoryExporter)
|
||||
}
|
||||
|
||||
// InMemoryExporter is an exporter that stores all received spans in-memory.
|
||||
type InMemoryExporter struct {
|
||||
mu sync.Mutex
|
||||
ss SpanStubs
|
||||
}
|
||||
|
||||
// ExportSpans handles export of spans by storing them in memory.
|
||||
func (imsb *InMemoryExporter) ExportSpans(_ context.Context, spans []trace.ReadOnlySpan) error {
|
||||
imsb.mu.Lock()
|
||||
defer imsb.mu.Unlock()
|
||||
imsb.ss = append(imsb.ss, SpanStubsFromReadOnlySpans(spans)...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Shutdown stops the exporter by clearing spans held in memory.
|
||||
func (imsb *InMemoryExporter) Shutdown(context.Context) error {
|
||||
imsb.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the current in-memory storage.
|
||||
func (imsb *InMemoryExporter) Reset() {
|
||||
imsb.mu.Lock()
|
||||
defer imsb.mu.Unlock()
|
||||
imsb.ss = nil
|
||||
}
|
||||
|
||||
// GetSpans returns the current in-memory stored spans.
|
||||
func (imsb *InMemoryExporter) GetSpans() SpanStubs {
|
||||
imsb.mu.Lock()
|
||||
defer imsb.mu.Unlock()
|
||||
ret := make(SpanStubs, len(imsb.ss))
|
||||
copy(ret, imsb.ss)
|
||||
return ret
|
||||
}
|
91
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/recorder.go
generated
vendored
Normal file
91
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/recorder.go
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright The OpenTelemetry 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 tracetest // import "go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
// SpanRecorder records started and ended spans.
|
||||
type SpanRecorder struct {
|
||||
startedMu sync.RWMutex
|
||||
started []sdktrace.ReadWriteSpan
|
||||
|
||||
endedMu sync.RWMutex
|
||||
ended []sdktrace.ReadOnlySpan
|
||||
}
|
||||
|
||||
var _ sdktrace.SpanProcessor = (*SpanRecorder)(nil)
|
||||
|
||||
func NewSpanRecorder() *SpanRecorder {
|
||||
return new(SpanRecorder)
|
||||
}
|
||||
|
||||
// OnStart records started spans.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) OnStart(_ context.Context, s sdktrace.ReadWriteSpan) {
|
||||
sr.startedMu.Lock()
|
||||
defer sr.startedMu.Unlock()
|
||||
sr.started = append(sr.started, s)
|
||||
}
|
||||
|
||||
// OnEnd records completed spans.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) OnEnd(s sdktrace.ReadOnlySpan) {
|
||||
sr.endedMu.Lock()
|
||||
defer sr.endedMu.Unlock()
|
||||
sr.ended = append(sr.ended, s)
|
||||
}
|
||||
|
||||
// Shutdown does nothing.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) Shutdown(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForceFlush does nothing.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) ForceFlush(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Started returns a copy of all started spans that have been recorded.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) Started() []sdktrace.ReadWriteSpan {
|
||||
sr.startedMu.RLock()
|
||||
defer sr.startedMu.RUnlock()
|
||||
dst := make([]sdktrace.ReadWriteSpan, len(sr.started))
|
||||
copy(dst, sr.started)
|
||||
return dst
|
||||
}
|
||||
|
||||
// Ended returns a copy of all ended spans that have been recorded.
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (sr *SpanRecorder) Ended() []sdktrace.ReadOnlySpan {
|
||||
sr.endedMu.RLock()
|
||||
defer sr.endedMu.RUnlock()
|
||||
dst := make([]sdktrace.ReadOnlySpan, len(sr.ended))
|
||||
copy(dst, sr.ended)
|
||||
return dst
|
||||
}
|
163
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/span.go
generated
vendored
Normal file
163
vendor/go.opentelemetry.io/otel/sdk/trace/tracetest/span.go
generated
vendored
Normal file
@ -0,0 +1,163 @@
|
||||
// Copyright The OpenTelemetry 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 tracetest // import "go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type SpanStubs []SpanStub
|
||||
|
||||
// SpanStubsFromReadOnlySpans returns SpanStubs populated from ro.
|
||||
func SpanStubsFromReadOnlySpans(ro []tracesdk.ReadOnlySpan) SpanStubs {
|
||||
if len(ro) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
s := make(SpanStubs, 0, len(ro))
|
||||
for _, r := range ro {
|
||||
s = append(s, SpanStubFromReadOnlySpan(r))
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Snapshots returns s as a slice of ReadOnlySpans.
|
||||
func (s SpanStubs) Snapshots() []tracesdk.ReadOnlySpan {
|
||||
if len(s) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
ro := make([]tracesdk.ReadOnlySpan, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
ro[i] = s[i].Snapshot()
|
||||
}
|
||||
return ro
|
||||
}
|
||||
|
||||
// SpanStub is a stand-in for a Span.
|
||||
type SpanStub struct {
|
||||
Name string
|
||||
SpanContext trace.SpanContext
|
||||
Parent trace.SpanContext
|
||||
SpanKind trace.SpanKind
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
Attributes []attribute.KeyValue
|
||||
Events []tracesdk.Event
|
||||
Links []tracesdk.Link
|
||||
Status tracesdk.Status
|
||||
DroppedAttributes int
|
||||
DroppedEvents int
|
||||
DroppedLinks int
|
||||
ChildSpanCount int
|
||||
Resource *resource.Resource
|
||||
InstrumentationLibrary instrumentation.Library
|
||||
}
|
||||
|
||||
// SpanStubFromReadOnlySpan returns a SpanStub populated from ro.
|
||||
func SpanStubFromReadOnlySpan(ro tracesdk.ReadOnlySpan) SpanStub {
|
||||
if ro == nil {
|
||||
return SpanStub{}
|
||||
}
|
||||
|
||||
return SpanStub{
|
||||
Name: ro.Name(),
|
||||
SpanContext: ro.SpanContext(),
|
||||
Parent: ro.Parent(),
|
||||
SpanKind: ro.SpanKind(),
|
||||
StartTime: ro.StartTime(),
|
||||
EndTime: ro.EndTime(),
|
||||
Attributes: ro.Attributes(),
|
||||
Events: ro.Events(),
|
||||
Links: ro.Links(),
|
||||
Status: ro.Status(),
|
||||
DroppedAttributes: ro.DroppedAttributes(),
|
||||
DroppedEvents: ro.DroppedEvents(),
|
||||
DroppedLinks: ro.DroppedLinks(),
|
||||
ChildSpanCount: ro.ChildSpanCount(),
|
||||
Resource: ro.Resource(),
|
||||
InstrumentationLibrary: ro.InstrumentationLibrary(),
|
||||
}
|
||||
}
|
||||
|
||||
// Snapshot returns a read-only copy of the SpanStub.
|
||||
func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan {
|
||||
return spanSnapshot{
|
||||
name: s.Name,
|
||||
spanContext: s.SpanContext,
|
||||
parent: s.Parent,
|
||||
spanKind: s.SpanKind,
|
||||
startTime: s.StartTime,
|
||||
endTime: s.EndTime,
|
||||
attributes: s.Attributes,
|
||||
events: s.Events,
|
||||
links: s.Links,
|
||||
status: s.Status,
|
||||
droppedAttributes: s.DroppedAttributes,
|
||||
droppedEvents: s.DroppedEvents,
|
||||
droppedLinks: s.DroppedLinks,
|
||||
childSpanCount: s.ChildSpanCount,
|
||||
resource: s.Resource,
|
||||
instrumentationLibrary: s.InstrumentationLibrary,
|
||||
}
|
||||
}
|
||||
|
||||
type spanSnapshot struct {
|
||||
// Embed the interface to implement the private method.
|
||||
tracesdk.ReadOnlySpan
|
||||
|
||||
name string
|
||||
spanContext trace.SpanContext
|
||||
parent trace.SpanContext
|
||||
spanKind trace.SpanKind
|
||||
startTime time.Time
|
||||
endTime time.Time
|
||||
attributes []attribute.KeyValue
|
||||
events []tracesdk.Event
|
||||
links []tracesdk.Link
|
||||
status tracesdk.Status
|
||||
droppedAttributes int
|
||||
droppedEvents int
|
||||
droppedLinks int
|
||||
childSpanCount int
|
||||
resource *resource.Resource
|
||||
instrumentationLibrary instrumentation.Library
|
||||
}
|
||||
|
||||
func (s spanSnapshot) Name() string { return s.name }
|
||||
func (s spanSnapshot) SpanContext() trace.SpanContext { return s.spanContext }
|
||||
func (s spanSnapshot) Parent() trace.SpanContext { return s.parent }
|
||||
func (s spanSnapshot) SpanKind() trace.SpanKind { return s.spanKind }
|
||||
func (s spanSnapshot) StartTime() time.Time { return s.startTime }
|
||||
func (s spanSnapshot) EndTime() time.Time { return s.endTime }
|
||||
func (s spanSnapshot) Attributes() []attribute.KeyValue { return s.attributes }
|
||||
func (s spanSnapshot) Links() []tracesdk.Link { return s.links }
|
||||
func (s spanSnapshot) Events() []tracesdk.Event { return s.events }
|
||||
func (s spanSnapshot) Status() tracesdk.Status { return s.status }
|
||||
func (s spanSnapshot) DroppedAttributes() int { return s.droppedAttributes }
|
||||
func (s spanSnapshot) DroppedLinks() int { return s.droppedLinks }
|
||||
func (s spanSnapshot) DroppedEvents() int { return s.droppedEvents }
|
||||
func (s spanSnapshot) ChildSpanCount() int { return s.childSpanCount }
|
||||
func (s spanSnapshot) Resource() *resource.Resource { return s.resource }
|
||||
func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library {
|
||||
return s.instrumentationLibrary
|
||||
}
|
Reference in New Issue
Block a user