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

Expose wider collector configuration #31

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

group :development, :test do
gem 'bosh-template', '2.2.1'
Expand Down
34 changes: 29 additions & 5 deletions jobs/otel-collector-windows/spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,36 @@ properties:
enabled:
description: "Enable OTel Collector"
default: true
ingress.grpc.port:
description: "Port the collector is listening on to receive OTLP over gRPC"
default: 9100
config:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @acrmp,

Generally I'm all in about this change, but I wonder if we should do it this way, that we practically embed the Otel Collector config in the spec or we provide provide a parameter which can define the path to the Otel collector config yaml file.

If we use some manager to manager the fleet of Otel collectors which we have based on OpAMP, they can push configuration to the clients (Otel collectors), it might be more clear, readable, practical for further processing (merge of local and remote config) if the configuration is in a separate file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chombium Can you expand on how you would see this working? Were you thinking of doing config merging outside of this release?

We're still exploring how we might want to distribute configuration. One option is that we could do something similar to what we do for the prom scraper and load configs that match a certain file name glob. A downside is that otel config changes would currently require BOSH to roll all the VMs.

We've looked into OpAMP a little. There still seem to be a few rough edges at the moment. For example see this recent issue we opened:
open-telemetry/opentelemetry-collector-contrib#33799

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @acrmp, @mkocher sorry for the late reply.... :-/

I was thinking of having the Otel collector config in a separate file for better separation, but it doesn't hurt if it's inside the job spec. At the end if we use an OpAMP server for managing the configuration, the sever would ping the Otel Collector that there is new config available and its up to the collector to decide when it will download and apply the new config. I'm not against your solution at all ;)

description: "Collector configuration"
default: {}
example: |
receivers:
otlp/placeholder:

processors:
batch:

exporters:
otlp:
endpoint: otelcol:4317

service:
pipelines:
traces:
receivers: [otlp/placeholder]
processors: [batch]
exporters: [otlp]
metrics:
receivers: [otlp/placeholder]
processors: [batch]
exporters: [otlp]
ingress.grpc.address:
description: "Address to listen on to receive OTLP over gRPC"
default: 127.0.0.1
ingress.grpc.port:
description: "Port the collector is listening on to receive OTLP over gRPC"
default: 9100
ingress.grpc.tls.ca_cert:
description: "CA root required for key/cert verification in gRPC ingress"
ingress.grpc.tls.cert:
Expand All @@ -35,15 +59,15 @@ properties:
description: "Port to serve the collector's internal metrics"
default: 14830
metric_exporters:
description: "Exporter configuration for aggregate metric egress"
description: "Exporter configuration for aggregate metric egress. Deprecated, please use 'config' property."
default: {}
example: |
otlp:
endpoint: otelcol:4317
otlp/2:
endpoint: otelcol:4318
trace_exporters:
description: "Exporter configuration for aggregate trace egress"
description: "Exporter configuration for aggregate trace egress. Deprecated, please use 'config' property."
default: {}
example: |
otlp/trace:
Expand Down
134 changes: 95 additions & 39 deletions jobs/otel-collector-windows/templates/config.yml.erb
Original file line number Diff line number Diff line change
@@ -1,61 +1,117 @@
<%=
metric_exporters = p('metric_exporters')
unless metric_exporters.respond_to?(:keys)
metric_exporters = YAML::load(metric_exporters)
def config
@config ||= begin
cfg = retrieve_property('config')
cfg = handle_old_properties(cfg) if cfg.empty?
cfg
end
end

trace_exporters = p('trace_exporters')
unless trace_exporters.respond_to?(:keys)
trace_exporters = YAML::load(trace_exporters)
def check_for_new_and_old_properties!
both_provided = !p('config').empty? && (!p('metric_exporters').empty? || !p('trace_exporters').empty?)
return unless both_provided

raise "Can not provide 'config' property when deprecated 'metric_exporters' or 'trace_exporters' properties are provided"
end

def retrieve_property(name)
if p(name).respond_to?(:keys)
p(name)
else
YAML.safe_load(p(name))
end
end

def handle_old_properties(cfg)
metric_exporters = retrieve_property('metric_exporters')
trace_exporters = retrieve_property('trace_exporters')
raise 'Exporter names must be unique' unless (trace_exporters.keys - metric_exporters.keys) == trace_exporters.keys

cfg['exporters'] = metric_exporters.merge(trace_exporters)
cfg['service'] = { 'pipelines' => {} }

if metric_exporters.any?
cfg['service']['pipelines']['metrics'] = {
'receivers' => ['otlp/cf-local'],
'exporters' => metric_exporters.keys
}
end

if trace_exporters.any?
cfg['service']['pipelines']['traces'] = {
'receivers' => ['otlp/cf-local'],
'exporters' => trace_exporters.keys
}
end

cfg
end

unless (trace_exporters.keys-metric_exporters.keys) == trace_exporters.keys
raise "Exporter names must be unique"
def check_for_no_exporters!
raise 'Exporter configuration must be provided' unless config['exporters']
end

if (metric_exporters.keys + trace_exporters.keys).any?{|k| k.include?('/cf-internal')}
raise 'Exporters cannot be defined under cf-internal namespace'
def check_for_no_service_config!
raise 'Service configuration must be provided' unless config['service']
end

if metric_exporters.any?{|k, v| k.start_with?('prometheus') && v['endpoint'] && v['endpoint'].end_with?(':8889')}
raise 'Cannot define prometheus exporter listening on port 8889 (reserved for BBS API port)'
def check_for_use_of_reserved_prefix!
%w[exporters processors].each do |component|
if config[component] && config[component].keys.any? { |k| k.include?('/cf-internal') }
raise "#{component.capitalize} cannot be defined under cf-internal namespace"
end
end
end

config = {
"receivers"=> {
"otlp"=>{
"protocols"=>{
"grpc"=>{
"endpoint"=>"#{p('ingress.grpc.address')}:#{p('ingress.grpc.port')}",
"tls"=>{
"client_ca_file"=>"/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector-ca.crt",
"cert_file"=>"/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector.crt",
"key_file"=>"/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector.key",
"min_version"=>"1.3"
def check_for_use_of_reserved_bbs_api_port!
if config['exporters'] && config['exporters'].any? do |k, v|
k.start_with?('prometheus/') && v['endpoint'] && v['endpoint'].end_with?(':8889')
end
raise 'Cannot define prometheus exporter listening on port 8889 (reserved for BBS API port)'
end
end

def set_internal_receiver_as_only_receiver
config['receivers'] = {
'otlp/cf-internal-local' => {
'protocols' => {
'grpc' => {
'endpoint' => "#{p('ingress.grpc.address')}:#{p('ingress.grpc.port')}",
'tls' => {
'client_ca_file' => '/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector-ca.crt',
'cert_file' => '/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector.crt',
'key_file' => '/var/vcap/jobs/otel-collector-windows/config/certs/otel-collector.key',
'min_version' => '1.3'
}
}
}
}
},
"exporters"=>metric_exporters.merge(trace_exporters),
"service"=>{
"telemetry"=>{
"metrics"=>{
"level"=>p('telemetry.metrics.level'),
"address"=>"127.0.0.1:#{p('telemetry.metrics.port')}"
}
},
"pipelines"=>{}
}
}
end

if metric_exporters.any?
config['service']['pipelines']['metrics'] = {"receivers"=>["otlp"], "exporters"=>metric_exporters.keys}
def set_internal_receiver_on_all_pipelines
config['service']['pipelines'].each_value do |p|
p['receivers'] = ['otlp/cf-internal-local']
end
end

if trace_exporters.any?
config['service']['pipelines']['traces'] = {"receivers"=>["otlp"], "exporters"=>trace_exporters.keys}
def expose_internal_telemetry
config['service']['telemetry'] = {
'metrics' => {
'address' => "127.0.0.1:#{p('telemetry.metrics.port')}",
'level' => p('telemetry.metrics.level')
}
}
end

YAML::dump(config)
check_for_new_and_old_properties!
check_for_no_exporters!
check_for_no_service_config!
check_for_use_of_reserved_prefix!
check_for_use_of_reserved_bbs_api_port!
set_internal_receiver_as_only_receiver
set_internal_receiver_on_all_pipelines
expose_internal_telemetry

YAML.dump(config)
%>
28 changes: 26 additions & 2 deletions jobs/otel-collector/spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ properties:
enabled:
description: "Enable OTel Collector"
default: true
config:
description: "Collector configuration"
default: {}
example: |
receivers:
otlp/placeholder:

processors:
batch:

exporters:
otlp:
endpoint: otelcol:4317

service:
pipelines:
traces:
receivers: [otlp/placeholder]
processors: [batch]
exporters: [otlp]
metrics:
receivers: [otlp/placeholder]
processors: [batch]
exporters: [otlp]
ingress.grpc.address:
description: "Address to listen on to receive OTLP over gRPC"
default: 127.0.0.1
Expand All @@ -36,15 +60,15 @@ properties:
description: "Port to serve the collector's internal metrics"
default: 14830
metric_exporters:
description: "Exporter configuration for aggregate metric egress"
description: "Exporter configuration for aggregate metric egress. Deprecated, please use 'config' property."
default: {}
example: |
otlp:
endpoint: otelcol:4317
otlp/2:
endpoint: otelcol:4318
trace_exporters:
description: "Exporter configuration for aggregate trace egress"
description: "Exporter configuration for aggregate trace egress. Deprecated, please use 'config' property."
default: {}
example: |
otlp/trace:
Expand Down
Loading