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

Lightstep Metrics SDK exemplar support #576

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

Lightstep Metrics SDK exemplar support #576

wants to merge 30 commits into from

Conversation

jmacd
Copy link
Member

@jmacd jmacd commented Nov 22, 2023

Description:
First implementation of the OpenTelemetry metrics SDK exemplar specification in the LS Metrics SDK.
This implements the specified exemplar filter mechanism.
This implements two exemplar reservoirs, one named Last and one named Weighted.
Last picks a single exemplar, the most recent.
Weighted uses the VarOpt algorithm from https://github.com/lightstep/varopt.
Depends on lightstep/varopt#20

Link to tracking Issue:
#575

Testing: New tests.

Documentation: New documentation. The new functionality is labeled as experimental.

jmacd added a commit to lightstep/varopt that referenced this pull request Nov 29, 2023
This code was last updated before Go generics. It's an obvious win here,
and was easy to do.
Also adds CopyFrom() and Init() method in support of
lightstep/otel-launcher-go#576 and new tests.
@codecov-commenter
Copy link

Codecov Report

Attention: 79 lines in your changes are missing coverage. Please review.

Comparison is base (3b55ac7) 89.60% compared to head (53b2edd) 89.09%.

❗ Current head 53b2edd differs from pull request most recent head 5fc09ea. Consider uploading reports for the commit 5fc09ea to get more accurate results

Files Patch % Lines
lightstep/sdk/internal/common.go 29.41% 24 Missing ⚠️
lightstep/sdk/metric/exemplar/last.go 64.91% 19 Missing and 1 partial ⚠️
lightstep/sdk/metric/exemplar/weighted.go 81.15% 12 Missing and 1 partial ⚠️
...ghtstep/sdk/metric/internal/viewstate/viewstate.go 87.75% 6 Missing ⚠️
...ightstep/sdk/metric/exporters/otlp/otelcol/otlp.go 92.45% 3 Missing and 1 partial ⚠️
...step/sdk/metric/internal/viewstate/accumulators.go 78.94% 3 Missing and 1 partial ⚠️
...metric/aggregator/minmaxsumcount/minmaxsumcount.go 57.14% 3 Missing ⚠️
lightstep/sdk/metric/internal/test/test.go 92.50% 2 Missing and 1 partial ⚠️
lightstep/sdk/metric/aggregator/gauge/gauge.go 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #576      +/-   ##
==========================================
- Coverage   89.60%   89.09%   -0.52%     
==========================================
  Files          62       64       +2     
  Lines        3686     4007     +321     
==========================================
+ Hits         3303     3570     +267     
- Misses        285      334      +49     
- Partials       98      103       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmacd
Copy link
Member Author

jmacd commented Apr 19, 2024

Recent benchmarks:
BEFORE

goos: darwin
goarch: arm64
pkg: github.com/lightstep/otel-launcher-go/lightstep/sdk/metric
BenchmarkCounterAddNoAttrs-10                          	26393384	        45.33 ns/op	       0 B/op	       0 allocs/op
BenchmarkCounterAddOneAttrSafe-10                      	 5077576	       234.2 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSafeBypass-10                	13181984	        91.18 ns/op	      64 B/op	       1 allocs/op
BenchmarkCounterAddOneAttrUnsafe-10                    	 5312253	       225.4 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrUnsafeBypass-10              	14418744	        82.53 ns/op	      64 B/op	       1 allocs/op
BenchmarkCounterAddOneAttrSliceReuseSafe-10            	 5325102	       225.0 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSliceReuseSafeBypass-10      	19572476	        61.80 ns/op	       0 B/op	       0 allocs/op
BenchmarkCounterAddOneAttrSliceReuseUnsafe-10          	 5200014	       217.5 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSliceReuseUnsafeBypass-10    	21535816	        55.06 ns/op	       0 B/op	       0 allocs/op
2024/04/19 11:23:59 use of empty attribute key, e.g., metric name "hello" with value "V"
BenchmarkCounterAddOneInvalidAttr-10                   	 3683832	       325.6 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterAddManyAttrs-10                        	 4452103	       267.6 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddManyAttrsUnsafe-10                  	 4711712	       256.2 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddManyInvalidAttrs-10                 	 3120043	       381.0 ns/op	     417 B/op	       5 allocs/op
BenchmarkCounterAddManyInvalidAttrsUnsafe-10           	 3449714	       345.6 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterAddManyFilteredAttrs-10                	 3100906	       388.2 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterCollectOneAttrNoReuse-10               	 1949265	       613.4 ns/op	     560 B/op	      11 allocs/op
BenchmarkCounterCollectOneAttrWithReuse-10             	 2409688	       497.7 ns/op	     296 B/op	       7 allocs/op
BenchmarkCounterCollectTenAttrs-10                     	  375853	      3178 ns/op	    2312 B/op	      52 allocs/op
BenchmarkCounterCollectTenAttrsTenTimes-10             	   37594	     31560 ns/op	   23120 B/op	     520 allocs/op
PASS
ok  	github.com/lightstep/otel-launcher-go/lightstep/sdk/metric	28.872s

AFTER

goos: darwin
goarch: arm64
pkg: github.com/lightstep/otel-launcher-go/lightstep/sdk/metric
BenchmarkCounterAddNoAttrs-10                          	19862740	        60.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkCounterAddOneAttrSafe-10                      	 4759293	       251.7 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSafeBypass-10                	10982313	       109.2 ns/op	      64 B/op	       1 allocs/op
BenchmarkCounterAddOneAttrUnsafe-10                    	 4994317	       241.6 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrUnsafeBypass-10              	11678329	       101.9 ns/op	      64 B/op	       1 allocs/op
BenchmarkCounterAddOneAttrSliceReuseSafe-10            	 4943800	       242.9 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSliceReuseSafeBypass-10      	15254890	        78.66 ns/op	       0 B/op	       0 allocs/op
BenchmarkCounterAddOneAttrSliceReuseUnsafe-10          	 5111533	       233.0 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddOneAttrSliceReuseUnsafeBypass-10    	16809517	        71.27 ns/op	       0 B/op	       0 allocs/op
2024/04/19 11:20:16 use of empty attribute key, e.g., metric name "hello" with value "V"
BenchmarkCounterAddOneInvalidAttr-10                   	 3497859	       342.8 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterAddManyAttrs-10                        	 4224228	       283.1 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddManyAttrsUnsafe-10                  	 4414015	       270.9 ns/op	     224 B/op	       5 allocs/op
BenchmarkCounterAddManyInvalidAttrs-10                 	 2995508	       399.4 ns/op	     417 B/op	       5 allocs/op
BenchmarkCounterAddManyInvalidAttrsUnsafe-10           	 3300962	       359.8 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterAddManyFilteredAttrs-10                	 2981546	       403.4 ns/op	     416 B/op	       5 allocs/op
BenchmarkCounterCollectOneAttrNoReuse-10               	 1858605	       646.5 ns/op	     576 B/op	      11 allocs/op
BenchmarkCounterCollectOneAttrWithReuse-10             	 2277570	       523.1 ns/op	     296 B/op	       7 allocs/op
BenchmarkCounterCollectTenAttrs-10                     	  348994	      3352 ns/op	    2312 B/op	      52 allocs/op
BenchmarkCounterCollectTenAttrsTenTimes-10             	   36268	     33371 ns/op	   23120 B/op	     520 allocs/op
PASS
ok  	github.com/lightstep/otel-launcher-go/lightstep/sdk/metric	29.034s

If we take the best-case performance and study the before/after with trace enabled, it appears similar.

For example, BenchmarkCounterAddNoAttrs-10 rises from 45ns to 60ns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants