From 4b96967571b47d583d848ef26af983979a96d8db Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Thu, 30 Jul 2020 15:53:07 -0700 Subject: [PATCH] Remove deadcode, and confusing sampler interface from API (#999) Signed-off-by: Bogdan Drutu Co-authored-by: Tyler Yahn --- api/trace/always_off_sampler.go | 54 ---------------------------- api/trace/always_off_sampler_test.go | 40 --------------------- api/trace/always_on_sampler.go | 54 ---------------------------- api/trace/always_on_sampler_test.go | 40 --------------------- api/trace/sampler.go | 46 ------------------------ 5 files changed, 234 deletions(-) delete mode 100644 api/trace/always_off_sampler.go delete mode 100644 api/trace/always_off_sampler_test.go delete mode 100644 api/trace/always_on_sampler.go delete mode 100644 api/trace/always_on_sampler_test.go delete mode 100644 api/trace/sampler.go diff --git a/api/trace/always_off_sampler.go b/api/trace/always_off_sampler.go deleted file mode 100644 index b8164839820..00000000000 --- a/api/trace/always_off_sampler.go +++ /dev/null @@ -1,54 +0,0 @@ -// 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 trace - -import ( - "go.opentelemetry.io/otel/api/kv" -) - -const ( - alwaysOffSamplerDescription = "AlwaysOffSampler" -) - -var alwaysOffSamplerDecision = Decision{Sampled: false} - -type alwaysOffSampler struct{} - -// ShouldSample implements Sampler interface. -// It always returns a Decision with Sampled value set to false -// and with Attributes set to an empty slice. -func (ns alwaysOffSampler) ShouldSample( - _ SpanContext, - _ bool, - _ ID, - _ string, - _ SpanKind, - _ []kv.KeyValue, - _ []Link, -) Decision { - return alwaysOffSamplerDecision -} - -// Description implements Sampler interface. -// It returns the description of this sampler. -func (ns alwaysOffSampler) Description() string { - return alwaysOffSamplerDescription -} - -var _ Sampler = alwaysOffSampler{} - -func AlwaysOffSampler() Sampler { - return alwaysOffSampler{} -} diff --git a/api/trace/always_off_sampler_test.go b/api/trace/always_off_sampler_test.go deleted file mode 100644 index 3ae70f34165..00000000000 --- a/api/trace/always_off_sampler_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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 trace - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - - "go.opentelemetry.io/otel/api/kv" -) - -func TestNeverSamperShouldSample(t *testing.T) { - gotD := AlwaysOffSampler().ShouldSample( - SpanContext{}, false, ID{}, "span", SpanKindClient, []kv.KeyValue{}, []Link{}) - wantD := Decision{Sampled: false} - if diff := cmp.Diff(wantD, gotD); diff != "" { - t.Errorf("Decision: +got, -want%v", diff) - } -} - -func TestAlwaysOffSamplerDescription(t *testing.T) { - gotDesc := AlwaysOffSampler().Description() - wantDesc := alwaysOffSamplerDescription - if diff := cmp.Diff(wantDesc, gotDesc); diff != "" { - t.Errorf("Description: +got, -want%v", diff) - } -} diff --git a/api/trace/always_on_sampler.go b/api/trace/always_on_sampler.go deleted file mode 100644 index 99048bacbaa..00000000000 --- a/api/trace/always_on_sampler.go +++ /dev/null @@ -1,54 +0,0 @@ -// 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 trace - -import ( - "go.opentelemetry.io/otel/api/kv" -) - -const ( - alwaysOnSamplerDescription = "AlwaysOnSampler" -) - -var alwaysOnSamplerDecision = Decision{Sampled: true} - -type alwaysOnSampler struct{} - -// ShouldSample implements Sampler interface. -// It always returns a Decision with Sampled value set to true -// and with Attributes set to an empty slice. -func (as alwaysOnSampler) ShouldSample( - _ SpanContext, - _ bool, - _ ID, - _ string, - _ SpanKind, - _ []kv.KeyValue, - _ []Link, -) Decision { - return alwaysOnSamplerDecision -} - -// Description implements Sampler interface. -// It returns the description of this sampler. -func (as alwaysOnSampler) Description() string { - return alwaysOnSamplerDescription -} - -var _ Sampler = alwaysOnSampler{} - -func AlwaysOnSampler() Sampler { - return alwaysOnSampler{} -} diff --git a/api/trace/always_on_sampler_test.go b/api/trace/always_on_sampler_test.go deleted file mode 100644 index ac0f85a2afd..00000000000 --- a/api/trace/always_on_sampler_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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 trace - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - - "go.opentelemetry.io/otel/api/kv" -) - -func TestAlwaysOnSamplerShouldSample(t *testing.T) { - gotD := AlwaysOnSampler().ShouldSample( - SpanContext{}, false, ID{}, "span", SpanKindClient, []kv.KeyValue{}, []Link{}) - wantD := Decision{Sampled: true} - if diff := cmp.Diff(wantD, gotD); diff != "" { - t.Errorf("Decision: +got, -want%v", diff) - } -} - -func TestAlwaysOnSamplerDescription(t *testing.T) { - gotDesc := AlwaysOnSampler().Description() - wantDesc := alwaysOnSamplerDescription - if diff := cmp.Diff(wantDesc, gotDesc); diff != "" { - t.Errorf("Description: +got, -want%v", diff) - } -} diff --git a/api/trace/sampler.go b/api/trace/sampler.go deleted file mode 100644 index 3777b32fae6..00000000000 --- a/api/trace/sampler.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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 trace - -import "go.opentelemetry.io/otel/api/kv" - -type Sampler interface { - // ShouldSample returns a Decision that contains a decision whether to sample - // or not sample the span to be created. Decision is based on a Sampler specific - // algorithm that takes into account one or more input parameters. - ShouldSample( - sc SpanContext, - remote bool, - traceID ID, - spanName string, - spanKind SpanKind, - attributes []kv.KeyValue, - links []Link, - ) Decision - - // Description returns of the sampler. It contains its name or short description - // and its configured properties. - // For example 'ProbabilitySampler:{0.00001}' - Description() string -} - -type Decision struct { - // Sampled is set true if the span should be sampled. - Sampled bool - - // Attributes provides insight into Sample r's decision process. - // It could be empty slice or nil if no attributes are recorded by the sampler. - Attributes []kv.KeyValue -}