Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NH-79350] Refactors to remove most global state #87

Merged
merged 41 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b983a3f
checkpoint
swi-jared May 2, 2024
f56b125
measurements scope
swi-jared May 2, 2024
e7332ff
fix reporter test
swi-jared May 2, 2024
725972e
Fix processor_test.go
swi-jared May 2, 2024
b26a839
Cleanups
swi-jared May 2, 2024
7325c9c
fix metrics_test.go
swi-jared May 2, 2024
9870904
misc cleanups
swi-jared May 2, 2024
7549910
lint fixes
swi-jared May 2, 2024
792a117
remove global reporter
swi-jared May 2, 2024
73c5dd3
misc cleanups
swi-jared May 2, 2024
80f3eab
checkpoint
swi-jared May 3, 2024
fd335e0
checkpoint
swi-jared May 3, 2024
c78ebee
fix test
swi-jared May 3, 2024
383c0ac
misc cleanups
swi-jared May 3, 2024
d289721
build
swi-jared May 3, 2024
ba0dd38
checkpoint
swi-jared May 3, 2024
c2f525e
fix reporter test
swi-jared May 3, 2024
8d1fa0f
tests pass
swi-jared May 3, 2024
87b793c
lint fix
swi-jared May 3, 2024
f1f819e
license header
swi-jared May 3, 2024
dab43a3
various cleanups
swi-jared May 3, 2024
a3db5ba
license header
swi-jared May 3, 2024
c394147
refactor/cleanup
swi-jared May 3, 2024
9b49a2a
misc cleanups
swi-jared May 3, 2024
8b9955b
replace test
swi-jared May 3, 2024
b0e3cef
more refactors
swi-jared May 3, 2024
cd31590
re-enable test
swi-jared May 3, 2024
85cba6e
use internal state to handle service name
swi-jared May 3, 2024
fce8a22
more cleanups
swi-jared May 3, 2024
31ff717
more cleanups
swi-jared May 3, 2024
77e8520
license header
swi-jared May 3, 2024
21077e7
use config.precision
swi-jared May 10, 2024
e006ed4
Misc metrics cleanups
swi-jared May 10, 2024
1a16031
more misc cleanups
swi-jared May 10, 2024
08e97ab
misc cleanups
swi-jared May 10, 2024
f1ba5bd
Some Makefile changes
swi-jared May 10, 2024
e100ad3
more cleanups
swi-jared May 10, 2024
c75cf31
more cleanups
swi-jared May 10, 2024
40c0215
remove unused commented out method
swi-jared May 10, 2024
f8c3000
errors.Is fixes
swi-jared May 10, 2024
8f3d38f
linter fix
swi-jared May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ removecert:
test: certgen runtest removecert
testfast: certgen runtestfast removecert

examples:
@cd examples && go test -race -timeout 1m -short ./... && echo "All examples passed."

vet:
@go vet -composites=false ./... && echo "Go vet analysis passed."

clean:
@go clean -testcache

sure: clean test examples vet
lint:
golangci-lint run ./...

license-check:
./license_check.sh

sure: clean test vet lint license-check

.PHONY: certgen test removecert examples vet clean
.PHONY: certgen test removecert vet clean lint license-check
13 changes: 4 additions & 9 deletions instrumentation/net/http/swohttp/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package swohttp

import (
"github.com/solarwinds/apm-go/internal/reporter"
"github.com/solarwinds/apm-go/swo"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
Expand All @@ -32,12 +31,10 @@ const (
XTraceOptionsResponse = "X-Trace-Options-Response"
)

var xtraceRegexp = regexp.MustCompile(`\A00-[[:xdigit:]]{32}-[[:xdigit:]]{16}-01\z`)
// TODO future: we should figure out a way to mock oboe so we can test for sampled == 01
var xtraceRegexp = regexp.MustCompile(`\A00-[[:xdigit:]]{32}-[[:xdigit:]]{16}-00\z`)

func TestHandlerNoXOptsResponse(t *testing.T) {
r := reporter.SetTestReporter(reporter.TestReporterSettingType(reporter.DefaultST))
defer r.Close(0)

cb, err := swo.Start()
require.NoError(t, err)
defer cb()
Expand All @@ -49,9 +46,6 @@ func TestHandlerNoXOptsResponse(t *testing.T) {
}

func TestHandlerWithXOptsResponse(t *testing.T) {
r := reporter.SetTestReporter(reporter.TestReporterSettingType(reporter.DefaultST))
defer r.Close(0)

cb, err := swo.Start()
require.NoError(t, err)
defer cb()
Expand All @@ -61,7 +55,8 @@ func TestHandlerWithXOptsResponse(t *testing.T) {
require.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, XTrace+","+XTraceOptionsResponse, resp.Header.Get(ACEHdr))
require.Regexp(t, xtraceRegexp, resp.Header.Get(XTrace))
require.Regexp(t, "trigger-trace=ok", resp.Header.Get(XTraceOptionsResponse))
// TODO: it'd be nice to have this actually receive settings from oboe and test for `trigger-trace=ok`
require.Regexp(t, "trigger-trace=settings-not-available", resp.Header.Get(XTraceOptionsResponse))
}

func doRequest(t *testing.T, xtOpts string) *http.Response {
Expand Down
14 changes: 14 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ const (
InfoLabel = "info"
UnknownLabel = "UNKNOWN"
)

const (
KvSignatureKey = "SignatureKey"
KvBucketCapacity = "BucketCapacity"
KvBucketRate = "BucketRate"
KvTriggerTraceRelaxedBucketCapacity = "TriggerRelaxedBucketCapacity"
KvTriggerTraceRelaxedBucketRate = "TriggerRelaxedBucketRate"
KvTriggerTraceStrictBucketCapacity = "TriggerStrictBucketCapacity"
KvTriggerTraceStrictBucketRate = "TriggerStrictBucketRate"
KvMetricsFlushInterval = "MetricsFlushInterval"
KvEventsFlushInterval = "EventsFlushInterval"
KvMaxTransactions = "MaxTransactions"
KvMaxCustomMetrics = "MaxCustomMetrics"
)
21 changes: 12 additions & 9 deletions internal/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
)

type exporter struct {
r reporter.Reporter
}

func exportSpan(_ context.Context, s sdktrace.ReadOnlySpan) {
func (e *exporter) exportSpan(_ context.Context, s sdktrace.ReadOnlySpan) {
evt := reporter.CreateEntryEvent(s.SpanContext(), s.StartTime(), s.Parent())
layer := fmt.Sprintf("%s:%s", strings.ToUpper(s.SpanKind().String()), s.Name())
evt.SetLayer(layer)
Expand Down Expand Up @@ -68,7 +69,7 @@ func exportSpan(_ context.Context, s sdktrace.ReadOnlySpan) {

evt.AddKVs(s.Attributes())

if err := reporter.ReportEvent(evt); err != nil {
if err := e.r.ReportEvent(evt); err != nil {
log.Warning("cannot send entry event", err)
return
}
Expand All @@ -88,33 +89,35 @@ func exportSpan(_ context.Context, s sdktrace.ReadOnlySpan) {
}
}
evt.AddKVs(otEvt.Attributes)
if err := reporter.ReportEvent(evt); err != nil {
if err := e.r.ReportEvent(evt); err != nil {
log.Warningf("could not send %s event: %s", s.Name(), err)
continue
}
}

evt = reporter.CreateExitEvent(s.SpanContext(), s.EndTime())
evt.AddKV(attribute.String(constants.Layer, layer))
if err := reporter.ReportEvent(evt); err != nil {
if err := e.r.ReportEvent(evt); err != nil {
log.Warning("cannot send exit event", err)
return
}

}

func (e *exporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
reporter.WaitForReady(ctx)
e.r.WaitForReady(ctx)
for _, s := range spans {
exportSpan(ctx, s)
e.exportSpan(ctx, s)
}
return nil
}

func (e *exporter) Shutdown(ctx context.Context) error {
return reporter.Shutdown(ctx)
return e.r.Shutdown(ctx)
}

func NewExporter() sdktrace.SpanExporter {
return &exporter{}
func NewExporter(r reporter.Reporter) sdktrace.SpanExporter {
return &exporter{
r: r,
}
}
9 changes: 3 additions & 6 deletions internal/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (

func TestExportSpan(t *testing.T) {
r := &capturingReporter{}
defer reporter.SetGlobalReporter(r)()
tr, cb := testutils.TracerWithExporter(NewExporter())
tr, cb := testutils.TracerWithExporter(NewExporter(r))
defer cb()

ctx := context.Background()
Expand Down Expand Up @@ -156,8 +155,7 @@ func TestExportSpan(t *testing.T) {

func TestExportSpanBacktrace(t *testing.T) {
r := &capturingReporter{}
defer reporter.SetGlobalReporter(r)()
tr, cb := testutils.TracerWithExporter(NewExporter())
tr, cb := testutils.TracerWithExporter(NewExporter(r))
defer cb()

ctx := context.Background()
Expand Down Expand Up @@ -199,8 +197,7 @@ func getBsonFromEvent(t *testing.T, event reporter.Event) map[string]interface{}

func TestExportSpanStatusCodes(t *testing.T) {
r := &capturingReporter{}
defer reporter.SetGlobalReporter(r)()
tr, cb := testutils.TracerWithExporter(NewExporter())
tr, cb := testutils.TracerWithExporter(NewExporter(r))
defer cb()

permutations := []struct {
Expand Down
Loading
Loading