This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start adding pipeline to collector This is the basis to do the work for actually implementing OC collector in the short run. At first enable receivers: 1. OC Receiver 2. Jaeger 3. Zipkin The queue processor is added but not connected to exporters by default, although there are options to do so. As previously indicated before there is some duplication of code with the agent, this should be reduced as we implement the interfaces and project coalesce around certain patterns. The queue is missing its metrics and those will be added soon.
- Loading branch information
Paulo Janotti
authored
Nov 17, 2018
1 parent
fe3e416
commit 4f3bb2c
Showing
22 changed files
with
1,485 additions
and
79 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,138 @@ | ||
// Copyright 2018, OpenCensus 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 builder handles the options to build the OpenCensus collector | ||
// pipeline. | ||
package builder | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
receiversRoot = "receivers" | ||
jaegerEntry = "jaeger" | ||
opencensusEntry = "opencensus" | ||
zipkinEntry = "zipkin" | ||
) | ||
|
||
// JaegerReceiverCfg holds configuration for Jaeger receivers. | ||
type JaegerReceiverCfg struct { | ||
// ThriftTChannelPort is the port that the relay receives on for jaeger thrift tchannel requests | ||
ThriftTChannelPort int `mapstructure:"thrift-tchannel-port"` | ||
// ThriftHTTPPort is the port that the relay receives on for jaeger thrift http requests | ||
ThriftHTTPPort int `mapstructure:"thrift-http-port"` | ||
} | ||
|
||
// JaegerReceiverEnabled checks if the Jaeger receiver is enabled, via a command-line flag, environment | ||
// variable, or configuration file. | ||
func JaegerReceiverEnabled(v *viper.Viper, cmdFlag string) bool { | ||
return featureEnabled(v, cmdFlag, receiversRoot, jaegerEntry) | ||
} | ||
|
||
// NewDefaultJaegerReceiverCfg returns an instance of JaegerReceiverCfg with default values | ||
func NewDefaultJaegerReceiverCfg() *JaegerReceiverCfg { | ||
opts := &JaegerReceiverCfg{ | ||
ThriftTChannelPort: 14267, | ||
ThriftHTTPPort: 14268, | ||
} | ||
return opts | ||
} | ||
|
||
// InitFromViper returns a JaegerReceiverCfg according to the configuration. | ||
func (cfg *JaegerReceiverCfg) InitFromViper(v *viper.Viper) (*JaegerReceiverCfg, error) { | ||
return cfg, initFromViper(cfg, v, receiversRoot, jaegerEntry) | ||
} | ||
|
||
// OpenCensusReceiverCfg holds configuration for OpenCensus receiver. | ||
type OpenCensusReceiverCfg struct { | ||
// Port is the port that the receiver will use | ||
Port int `mapstructure:"port"` | ||
} | ||
|
||
// OpenCensusReceiverEnabled checks if the OpenCensus receiver is enabled, via a command-line flag, environment | ||
// variable, or configuration file. | ||
func OpenCensusReceiverEnabled(v *viper.Viper, cmdFlag string) bool { | ||
return featureEnabled(v, cmdFlag, receiversRoot, opencensusEntry) | ||
} | ||
|
||
// NewDefaultOpenCensusReceiverCfg returns an instance of OpenCensusReceiverCfg with default values | ||
func NewDefaultOpenCensusReceiverCfg() *OpenCensusReceiverCfg { | ||
opts := &OpenCensusReceiverCfg{ | ||
Port: 55678, | ||
} | ||
return opts | ||
} | ||
|
||
// InitFromViper returns a OpenCensusReceiverCfg according to the configuration. | ||
func (cfg *OpenCensusReceiverCfg) InitFromViper(v *viper.Viper) (*OpenCensusReceiverCfg, error) { | ||
return cfg, initFromViper(cfg, v, receiversRoot, opencensusEntry) | ||
} | ||
|
||
// ZipkinReceiverCfg holds configuration for Zipkin receiver. | ||
type ZipkinReceiverCfg struct { | ||
// Port is the port that the receiver will use | ||
Port int `mapstructure:"port"` | ||
} | ||
|
||
// ZipkinReceiverEnabled checks if the Zipkin receiver is enabled, via a command-line flag, environment | ||
// variable, or configuration file. | ||
func ZipkinReceiverEnabled(v *viper.Viper, cmdFlag string) bool { | ||
return featureEnabled(v, cmdFlag, receiversRoot, zipkinEntry) | ||
} | ||
|
||
// NewDefaultZipkinReceiverCfg returns an instance of ZipkinReceiverCfg with default values | ||
func NewDefaultZipkinReceiverCfg() *ZipkinReceiverCfg { | ||
opts := &ZipkinReceiverCfg{ | ||
Port: 9411, | ||
} | ||
return opts | ||
} | ||
|
||
// InitFromViper returns a ZipkinReceiverCfg according to the configuration. | ||
func (cfg *ZipkinReceiverCfg) InitFromViper(v *viper.Viper) (*ZipkinReceiverCfg, error) { | ||
return cfg, initFromViper(cfg, v, receiversRoot, zipkinEntry) | ||
} | ||
|
||
// Helper functions | ||
|
||
func initFromViper(cfg interface{}, v *viper.Viper, labels ...string) error { | ||
v = getViperSub(v, labels...) | ||
if v == nil { | ||
return nil | ||
} | ||
if err := v.Unmarshal(cfg); err != nil { | ||
return fmt.Errorf("Failed to read configuration for %s %v", strings.Join(labels, ": "), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getViperSub(v *viper.Viper, labels ...string) *viper.Viper { | ||
for _, label := range labels { | ||
v = v.Sub(label) | ||
if v == nil { | ||
return nil | ||
} | ||
} | ||
|
||
return v | ||
} | ||
|
||
func featureEnabled(v *viper.Viper, cmdFlag string, labels ...string) bool { | ||
return v.GetBool(cmdFlag) || (getViperSub(v, labels...) != nil) | ||
} |
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,80 @@ | ||
// Copyright 2018, OpenCensus 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 builder | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func TestReceiversEnabledByPresenceWithDefaultSettings(t *testing.T) { | ||
v, err := loadViperFromFile("./testdata/receivers_enabled.yaml") | ||
if err != nil { | ||
t.Fatalf("Failed to load viper from test file: %v", err) | ||
} | ||
|
||
jaegerEnabled, opencensusEnabled, zipkinEnabled := JaegerReceiverEnabled(v, "j"), OpenCensusReceiverEnabled(v, "oc"), ZipkinReceiverEnabled(v, "z") | ||
if !jaegerEnabled || !opencensusEnabled || !zipkinEnabled { | ||
t.Fatalf("Some of the expected receivers were not enabled j:%v oc:%v z:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled) | ||
} | ||
|
||
wj := NewDefaultJaegerReceiverCfg() | ||
gj, err := wj.InitFromViper(v) | ||
if err != nil { | ||
t.Errorf("Failed to InitFromViper for Jaeger receiver: %v", err) | ||
} else if !reflect.DeepEqual(wj, gj) { | ||
t.Errorf("Incorrect config for Jaeger receiver, want %v got %v", wj, gj) | ||
} | ||
|
||
woc := NewDefaultOpenCensusReceiverCfg() | ||
goc, err := woc.InitFromViper(v) | ||
if err != nil { | ||
t.Errorf("Failed to InitFromViper for OpenCensus receiver: %v", err) | ||
} else if !reflect.DeepEqual(woc, goc) { | ||
t.Errorf("Incorrect config for OpenCensus receiver, want %v got %v", woc, goc) | ||
} | ||
|
||
wz := NewDefaultZipkinReceiverCfg() | ||
gz, err := wz.InitFromViper(v) | ||
if err != nil { | ||
t.Errorf("Failed to InitFromViper for Zipkin receiver: %v", err) | ||
} else if !reflect.DeepEqual(wz, gz) { | ||
t.Errorf("Incorrect config for Zipkin receiver, want %v got %v", wz, gz) | ||
} | ||
} | ||
|
||
func TestReceiversDisabledByPresenceWithDefaultSettings(t *testing.T) { | ||
v, err := loadViperFromFile("./testdata/receivers_disabled.yaml") | ||
if err != nil { | ||
t.Fatalf("Failed to load viper from test file: %v", err) | ||
} | ||
|
||
jaegerEnabled, opencensusEnabled, zipkinEnabled := JaegerReceiverEnabled(v, "j"), OpenCensusReceiverEnabled(v, "oc"), ZipkinReceiverEnabled(v, "z") | ||
if jaegerEnabled || opencensusEnabled || zipkinEnabled { | ||
t.Fatalf("Not all receivers were disabled j:%v oc:%v z:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled) | ||
} | ||
} | ||
|
||
func loadViperFromFile(file string) (*viper.Viper, error) { | ||
v := viper.New() | ||
v.SetConfigFile(file) | ||
err := v.ReadInConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return v, nil | ||
} |
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,5 @@ | ||
# No receivers enabled, all commented out | ||
receivers: | ||
# jaeger: {} | ||
# opencensus: {} | ||
# zipkin: {} |
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,5 @@ | ||
# Enable receivers with default configuration | ||
receivers: | ||
jaeger: {} | ||
opencensus: {} | ||
zipkin: {} |
Oops, something went wrong.