Skip to content

Commit 273a773

Browse files
authored
Enable otel opamp (#93)
* Configuring opamp * Formatting * Using http basic auth * Exposing opamp port * Using new processor name * Choosing traces processor name based on the version * Testing that opamp is running in edot mode * Testing that opamp is running in edot mode * Supporting opamp in podman script * Adding more config to opamp on podman * Using basic auth for opamp on podman * Adding compare_versions() to both scripts * Moving opamp test to its own function * Avoiding escaping vars * Renaming var * Using env var for local password in start-local-podman.sh
1 parent e8d0b17 commit 273a773

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

start-local-podman.sh

100644100755
Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ is_valid_version() {
8888
echo "$1" | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$'
8989
}
9090

91+
# Compare versions
92+
# parameter 1: version to compare
93+
# parameter 2: version to compare
94+
compare_versions() {
95+
v1=$1
96+
v2=$2
97+
98+
original_ifs="$IFS"
99+
IFS='.'
100+
# shellcheck disable=SC2086
101+
set -- $v1; v1_major=${1:-0}; v1_minor=${2:-0}; v1_patch=${3:-0}
102+
IFS='.'
103+
# shellcheck disable=SC2086
104+
set -- $v2; v2_major=${1:-0}; v2_minor=${2:-0}; v2_patch=${3:-0}
105+
IFS="$original_ifs"
106+
107+
[ "$v1_major" -lt "$v2_major" ] && echo "lt" && return 0
108+
[ "$v1_major" -gt "$v2_major" ] && echo "gt" && return 0
109+
110+
[ "$v1_minor" -lt "$v2_minor" ] && echo "lt" && return 0
111+
[ "$v1_minor" -gt "$v2_minor" ] && echo "gt" && return 0
112+
113+
[ "$v1_patch" -lt "$v2_patch" ] && echo "lt" && return 0
114+
[ "$v1_patch" -gt "$v2_patch" ] && echo "gt" && return 0
115+
116+
echo "eq"
117+
}
118+
91119
# Get the latest stable version of Elasticsearch
92120
# Note: It removes all the beta or candidate releases from the list
93121
# but includes the GA releases (e.g. new major)
@@ -507,7 +535,25 @@ create_edot_config() {
507535
mkdir -p "$installation_folder/config/edot-collector"
508536
fi
509537

510-
cat > "$installation_folder/config/edot-collector/config.yaml" <<'EOM'
538+
trace_processor_name="elasticapm"
539+
if [ "$(compare_versions "$es_version" "9.2.0")" = "lt" ];then
540+
trace_processor_name="elastictrace"
541+
fi
542+
# shellcheck disable=SC2016
543+
es_local_api_key_var='${ES_LOCAL_API_KEY}'
544+
# shellcheck disable=SC2016
545+
es_local_password_var='${ES_LOCAL_PASSWORD}'
546+
cat > "$installation_folder/config/edot-collector/config.yaml" <<EOM
547+
extensions:
548+
apmconfig:
549+
source:
550+
elasticsearch:
551+
endpoint: http://elastic:${es_local_password_var}@elasticsearch:9200
552+
cache_duration: 10s
553+
opamp:
554+
protocols:
555+
http:
556+
endpoint: 0.0.0.0:4320
511557
receivers:
512558
# Receives data from other Collectors in Agent mode
513559
otlp:
@@ -528,20 +574,21 @@ processors:
528574
batch/metrics:
529575
send_batch_max_size: 0 # Explicitly set to 0 to avoid splitting metrics requests
530576
timeout: 1s
531-
elastictrace: {} # Elastic Trace Processor
577+
${trace_processor_name}: {}
532578
533579
exporters:
534580
debug: {}
535581
elasticsearch/otel:
536582
endpoints:
537583
- http://elasticsearch:9200
538-
api_key: ${ES_LOCAL_API_KEY}
584+
api_key: ${es_local_api_key_var}
539585
tls:
540586
insecure_skip_verify: true
541587
mapping:
542588
mode: otel
543589
544590
service:
591+
extensions: [ apmconfig ]
545592
pipelines:
546593
metrics:
547594
receivers: [otlp]
@@ -553,7 +600,7 @@ service:
553600
exporters: [debug, elasticapm, elasticsearch/otel]
554601
traces:
555602
receivers: [otlp]
556-
processors: [batch, elastictrace]
603+
processors: [batch, ${trace_processor_name}]
557604
exporters: [debug, elasticapm, elasticsearch/otel]
558605
metrics/aggregated-otel-metrics:
559606
receivers:
@@ -795,6 +842,7 @@ create_edot_container() {
795842
--network-alias edot-collector \
796843
-p "4317:4317" \
797844
-p "4318:4318" \
845+
-p "4320:4320" \
798846
-v "${edot_config_host_path}:/etc/otelcol-contrib/config.yaml:ro" \
799847
--env-file "$script_dir/.env" \
800848
"${image}" \
@@ -1481,6 +1529,7 @@ success() {
14811529
echo "🔌 Elasticsearch API endpoint: http://localhost:9200"
14821530
if [ "$edot" = "true" ]; then
14831531
echo "🔭 OTLP endpoints: gRPC http://localhost:4317 and HTTP http://localhost:4318"
1532+
echo "🔭 OpAMP endpoint: http://localhost:4320/v1/opamp"
14841533
fi
14851534

14861535
# Load ES_LOCAL_API_KEY environment variable.

start-local.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,29 @@ EOM
735735
}
736736

737737
add_edot_config_in_docker_compose() {
738+
trace_processor_name="elasticapm"
739+
if [ "$(compare_versions "$es_version" "9.2.0")" = "lt" ];then
740+
trace_processor_name="elastictrace"
741+
fi
742+
# shellcheck disable=SC2016
743+
es_local_password_var='${ES_LOCAL_PASSWORD}'
738744
# Add the OTLP configs in docker-compose.yml
739-
cat >> docker-compose.yml <<-'EOM'
745+
cat >> docker-compose.yml <<-EOM
740746
configs:
741747
# This is the minimal yaml configuration needed to listen on all interfaces
742748
# for OTLP logs, metrics and traces, exporting to Elasticsearch.
743749
edot-collector-config:
744750
content: |
751+
extensions:
752+
apmconfig:
753+
source:
754+
elasticsearch:
755+
endpoint: http://elastic:${es_local_password_var}@elasticsearch:9200
756+
cache_duration: 10s
757+
opamp:
758+
protocols:
759+
http:
760+
endpoint: 0.0.0.0:4320
745761
receivers:
746762
# Receives data from other Collectors in Agent mode
747763
otlp:
@@ -762,21 +778,22 @@ configs:
762778
batch/metrics:
763779
send_batch_max_size: 0 # Explicitly set to 0 to avoid splitting metrics requests
764780
timeout: 1s
765-
elastictrace: {} # Elastic Trace Processor
781+
${trace_processor_name}: {}
766782
767783
exporters:
768784
debug: {}
769785
elasticsearch/otel:
770786
endpoints:
771787
- http://elasticsearch:9200
772788
user: elastic
773-
password: ${ES_LOCAL_PASSWORD}
789+
password: ${es_local_password_var}
774790
tls:
775791
insecure_skip_verify: true
776792
mapping:
777793
mode: otel
778794
779795
service:
796+
extensions: [ apmconfig ]
780797
pipelines:
781798
metrics:
782799
receivers: [otlp]
@@ -788,7 +805,7 @@ configs:
788805
exporters: [debug, elasticapm, elasticsearch/otel]
789806
traces:
790807
receivers: [otlp]
791-
processors: [batch, elastictrace]
808+
processors: [batch, ${trace_processor_name}]
792809
exporters: [debug, elasticapm, elasticsearch/otel]
793810
metrics/aggregated-otel-metrics:
794811
receivers:
@@ -818,6 +835,7 @@ add_edot_service_in_docker_composer() {
818835
ports:
819836
- "4317:4317" # grpc
820837
- "4318:4318" # http
838+
- "4320:4320" # opamp
821839
healthcheck:
822840
test: ["CMD-SHELL", "bash -c 'echo -n > /dev/tcp/127.0.0.1/4317'"]
823841
retries: 300
@@ -1058,6 +1076,7 @@ success() {
10581076
echo "🔌 Elasticsearch API endpoint: http://localhost:9200"
10591077
if [ "$edot" = "true" ]; then
10601078
echo "🔭 OTLP endpoints: gRPC http://localhost:4317 and HTTP http://localhost:4318"
1079+
echo "🔭 OpAMP endpoint: http://localhost:4320/v1/opamp"
10611080
fi
10621081
if [ -n "$api_key" ]; then
10631082
echo "🔑 API key: $api_key"

tests/install_edot_test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ function test_edot_collector_is_running() {
5555
assert_equals "200" "$result"
5656
}
5757

58+
function test_edot_opamp_is_running() {
59+
result=$(curl http://localhost:4320/v1/opamp \
60+
-H 'content-type:application/x-protobuf' \
61+
-d '' \
62+
-o /dev/null -sw "%{http_code}\n")
63+
64+
assert_equals "200" "$result"
65+
}

0 commit comments

Comments
 (0)