mirror of https://github.com/knative/pkg.git
make METRICS_DOMAIN optional when backend is not OpenCensus (#2617)
This commit is contained in:
parent
b2a3a39d92
commit
ff956846a1
|
|
@ -124,12 +124,7 @@ func (mc *metricsConfig) record(ctx context.Context, mss []stats.Measurement, ro
|
|||
|
||||
func createMetricsConfig(_ context.Context, ops ExporterOptions) (*metricsConfig, error) {
|
||||
var mc metricsConfig
|
||||
|
||||
if ops.Domain == "" {
|
||||
return nil, errors.New("metrics domain cannot be empty")
|
||||
}
|
||||
mc.domain = ops.Domain
|
||||
|
||||
if ops.Component == "" {
|
||||
return nil, errors.New("metrics component name cannot be empty")
|
||||
}
|
||||
|
|
@ -159,6 +154,9 @@ func createMetricsConfig(_ context.Context, ops ExporterOptions) (*metricsConfig
|
|||
|
||||
switch mc.backendDestination {
|
||||
case openCensus:
|
||||
if ops.Domain == "" {
|
||||
return nil, errors.New("metrics domain cannot be empty")
|
||||
}
|
||||
mc.collectorAddress = ops.ConfigMap[collectorAddressKey]
|
||||
if isSecure := ops.ConfigMap[collectorSecureKey]; isSecure != "" {
|
||||
var err error
|
||||
|
|
@ -221,22 +219,7 @@ func Domain() string {
|
|||
if domain := os.Getenv(DomainEnv); domain != "" {
|
||||
return domain
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf(`The environment variable %q is not set
|
||||
|
||||
If this is a process running on Kubernetes, then it should be specifying
|
||||
this via:
|
||||
|
||||
env:
|
||||
- name: %s
|
||||
value: knative.dev/some-repository
|
||||
|
||||
If this is a Go unit test consuming metric.Domain() then it should add the
|
||||
following import:
|
||||
|
||||
import (
|
||||
_ "knative.dev/pkg/metrics/testing"
|
||||
)`, DomainEnv, DomainEnv))
|
||||
return ""
|
||||
}
|
||||
|
||||
// prometheusPort returns the TCP port number configured via the environment
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ var (
|
|||
name: "emptyDomain",
|
||||
ops: ExporterOptions{
|
||||
ConfigMap: map[string]string{
|
||||
BackendDestinationKey: string(prometheus),
|
||||
BackendDestinationKey: string(openCensus),
|
||||
},
|
||||
Component: testComponent,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue