-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /api/sampling endpoint in collector
Return metricsFactory from test server init fix import structure fix unwanted change in agent server Add license on new file Signed-off-by: RickyRajinder <singh.sangh@gmail.com> Add tests for errors Refactor collector API handler to extend agent handler Remove unused fields Unexport fields in HttpHandler Update callers of NewAPIHandler Run go fmt Fix lint issues
- Loading branch information
1 parent
3fa8a08
commit 12bf753
Showing
7 changed files
with
280 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) 2019 The Jaeger 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 httpserver | ||
|
||
import ( | ||
"errors" | ||
"net/http/httptest" | ||
|
||
"github.com/uber/jaeger-lib/metrics/metricstest" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/baggage" | ||
"github.com/jaegertracing/jaeger/thrift-gen/sampling" | ||
) | ||
|
||
//TestServer sets up a test HTTP server, with a mock config manager and exports a metrics factory | ||
type TestServer struct { | ||
MetricsFactory *metricstest.Factory | ||
mgr *MockManager | ||
Server *httptest.Server | ||
} | ||
|
||
//WithServer initializes the test server | ||
func WithServer( | ||
mockSamplingResponse *sampling.SamplingStrategyResponse, | ||
mockBaggageResponse []*baggage.BaggageRestriction, | ||
runTest func(server *TestServer), | ||
) { | ||
metricsFactory := metricstest.NewFactory(0) | ||
mgr := &MockManager{ | ||
SamplingResponse: mockSamplingResponse, | ||
BaggageResponse: mockBaggageResponse, | ||
} | ||
realServer := NewHTTPServer(":1", mgr, metricsFactory) | ||
server := httptest.NewServer(realServer.Handler) | ||
defer server.Close() | ||
runTest(&TestServer{ | ||
MetricsFactory: metricsFactory, | ||
mgr: mgr, | ||
Server: server, | ||
}) | ||
} | ||
|
||
//Probabilistic returns a SamplingStrategyResponse with the given probability | ||
func Probabilistic(probability float64) *sampling.SamplingStrategyResponse { | ||
return &sampling.SamplingStrategyResponse{ | ||
StrategyType: sampling.SamplingStrategyType_PROBABILISTIC, | ||
ProbabilisticSampling: &sampling.ProbabilisticSamplingStrategy{ | ||
SamplingRate: probability, | ||
}, | ||
} | ||
} | ||
|
||
//Restrictions returns BaggageRestrictions | ||
func Restrictions(key string, size int32) []*baggage.BaggageRestriction { | ||
return []*baggage.BaggageRestriction{ | ||
{BaggageKey: key, MaxValueLength: size}, | ||
} | ||
} | ||
|
||
//MockManager is a mock ClientConfigManager | ||
type MockManager struct { | ||
SamplingResponse *sampling.SamplingStrategyResponse | ||
BaggageResponse []*baggage.BaggageRestriction | ||
} | ||
|
||
//GetSamplingStrategy returns the sampling strategy pf the mock | ||
func (m *MockManager) GetSamplingStrategy(serviceName string) (*sampling.SamplingStrategyResponse, error) { | ||
if m.SamplingResponse == nil { | ||
return nil, errors.New("no mock response provided") | ||
} | ||
return m.SamplingResponse, nil | ||
} | ||
|
||
//GetBaggageRestrictions returns the baggage restrictions of the mock | ||
func (m *MockManager) GetBaggageRestrictions(serviceName string) ([]*baggage.BaggageRestriction, error) { | ||
if m.BaggageResponse == nil { | ||
return nil, errors.New("no mock response provided") | ||
} | ||
return m.BaggageResponse, nil | ||
} |
Oops, something went wrong.