From 614e77e8fea572fdf2139999ef00e86664d8d115 Mon Sep 17 00:00:00 2001 From: Eugene Grebenschikov Date: Wed, 7 Jun 2023 19:58:47 -0700 Subject: [PATCH] fixup! add: functional tests --- ...-build.yml => nginx-otel-module-check.yml} | 14 ++++---- tests/h2_otel.t | 31 ++++++++---------- tests/h2_otel_collector.t | 6 +++- tests/otel.t | 32 ++++++++----------- tests/otel_collector.t | 6 +++- 5 files changed, 43 insertions(+), 46 deletions(-) rename .github/workflows/{nginx-otel-build.yml => nginx-otel-module-check.yml} (86%) diff --git a/.github/workflows/nginx-otel-build.yml b/.github/workflows/nginx-otel-module-check.yml similarity index 86% rename from .github/workflows/nginx-otel-build.yml rename to .github/workflows/nginx-otel-module-check.yml index 4b0b581..8e48863 100644 --- a/.github/workflows/nginx-otel-build.yml +++ b/.github/workflows/nginx-otel-module-check.yml @@ -1,4 +1,4 @@ -name: nginx-otel-module +name: nginx-otel-module-check run-name: ${{ github.actor }} is triggering pipeline on: [push] jobs: @@ -9,8 +9,8 @@ jobs: uses: actions/checkout@v3 - name: Install system dependecies run: | - sudo apt-get update && sudo apt install -y mercurial cmake \ - libc-ares-dev libre2-dev libssl-dev zlib1g-dev + sudo apt-get update && sudo apt install -y cmake \ + libc-ares-dev libre2-dev - name: Checkout and build nginx run: | hg clone http://hg.nginx.org/nginx/ && cd nginx && \ @@ -39,8 +39,10 @@ jobs: uses: actions/download-artifact@v3 with: name: nginx-otel-module-stuff - - name: Install system dependecies - run: sudo apt-get update && sudo apt install -y mercurial curl + - name: Fix rights + run: | + chmod +x nginx/objs/nginx + chmod +x build/_deps/grpc-build/third_party/protobuf/protoc - name: Install perl modules run: sudo cpan IO::Socket::SSL - name: Download otelcol @@ -51,8 +53,6 @@ jobs: tar -xzf otelcol_0.76.1_linux_amd64.tar.gz - name: Checkout nginx-test run: hg clone http://hg.nginx.org/nginx-tests/ - - name: List files before tests - run: ls -lR . - name: Run tests run: | cd tests && PERL5LIB=../nginx-tests/lib TEST_NGINX_UNSAFE=1 \ diff --git a/tests/h2_otel.t b/tests/h2_otel.t index 2824af7..a302b7d 100644 --- a/tests/h2_otel.t +++ b/tests/h2_otel.t @@ -367,6 +367,7 @@ is($tp_headers_propagate->{'x-otel-tracestate'}, sub http2_get { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(); my $sid = $s->new_stream({ path => $path }); @@ -384,6 +385,7 @@ sub http2_get { sub http2_get_traceparent { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(); my $sid = $s->new_stream({ headers => [ @@ -411,6 +413,7 @@ sub http2_get_traceparent { sub http2_get_ssl { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(undef, socket => get_ssl_socket(8082, ['h2'])); @@ -434,7 +437,8 @@ sub get_ssl_socket { SSL => 1, SSL_alpn_protocols => $alpn, SSL_error_trap => sub { die $_[1] } - );} + ); +} sub get_attr { my($attr, $type, $obj) = @_; @@ -457,6 +461,7 @@ sub decode_protobuf { my ($protobuf) = @_; $protobuf = encode_base64($protobuf); + open my $cmd => "echo '$protobuf' | base64 -d | " . '$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '. '--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' . @@ -482,6 +487,7 @@ sub decode_bytes { } elsif ($acc ne '') { $acc .= $c; } + if ($acc =~ /\\(\d{3})/) { $res .= chr(oct($1)); $acc = ''; @@ -504,31 +510,21 @@ sub decode_bytes { sub to_hash { my ($textdata) = @_; - my $out; + %{$out} = (); - my @stack = ($out); - my @lines; - - for (split /\n/, $textdata) { - chomp; - $_ =~ s/^\s+//; - push @lines, $_; - } - my ($attr_count, $span_count) = (0, 0); - - for my $line (@lines) { + for my $line (split /\n/, $textdata) { + chomp $line; + $line =~ s/^\s+//; if ($line =~ /\:/) { my ($k, $v) = split /\: /, $line; $v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/); $stack[scalar(@stack)-1]{$k} = $v; } elsif ($line =~ /\{/) { $line =~ s/\s\{//; - if ($line eq 'attributes') { - $line = 'attribute' . $attr_count++; - } + $line = 'attribute' . $attr_count++ if ($line eq 'attributes'); if ($line eq 'spans') { $line = 'span' . $span_count++; $attr_count = 0; @@ -554,8 +550,7 @@ sub grpc { LocalPort => $p, Listen => 5, Reuse => 1 - ) - or die "Can't create listening socket: $!\n"; + ) or die "Can't create listening socket: $!\n"; $f->{http_start} = sub { if (IO::Select->new($server)->can_read(5)) { diff --git a/tests/h2_otel_collector.t b/tests/h2_otel_collector.t index 87a2019..1f2d301 100644 --- a/tests/h2_otel_collector.t +++ b/tests/h2_otel_collector.t @@ -373,6 +373,7 @@ is($tp_headers_propagate->{'x-otel-tracestate'}, sub http2_get { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(); my $sid = $s->new_stream({ path => $path }); @@ -390,6 +391,7 @@ sub http2_get { sub http2_get_traceparent { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(); my $sid = $s->new_stream({ headers => [ @@ -417,6 +419,7 @@ sub http2_get_traceparent { sub http2_get_ssl { my ($path) = @_; my ($frames, $frame); + my $s = Test::Nginx::HTTP2->new(undef, socket => get_ssl_socket(8082, ['h2'])); @@ -440,7 +443,8 @@ sub get_ssl_socket { SSL => 1, SSL_alpn_protocols => $alpn, SSL_error_trap => sub { die $_[1] } - );} + ); +} sub get_attr { my($attr, $type, $obj) = @_; diff --git a/tests/otel.t b/tests/otel.t index 62d91e5..ba3bde0 100644 --- a/tests/otel.t +++ b/tests/otel.t @@ -360,6 +360,7 @@ like($tp_resp_propagate, sub http_get_traceparent { my ($path) = @_; + return http(< $s); } @@ -381,7 +384,8 @@ sub get_ssl_socket { return http( '', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1 - );} + ); +} sub get_attr { my($attr, $type, $obj) = @_; @@ -404,6 +408,7 @@ sub decode_protobuf { my ($protobuf) = @_; $protobuf = encode_base64($protobuf); + open my $cmd => "echo '$protobuf' | base64 -d | " . '$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '. '--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' . @@ -429,6 +434,7 @@ sub decode_bytes { } elsif ($acc ne '') { $acc .= $c; } + if ($acc =~ /\\(\d{3})/) { $res .= chr(oct($1)); $acc = ''; @@ -451,32 +457,21 @@ sub decode_bytes { sub to_hash { my ($textdata) = @_; - my $out; + %{$out} = (); - - my @stack = ($out); - my @lines; - - for (split /\n/, $textdata) { - chomp; - $_ =~ s/^\s+//; - push @lines, $_; - } - my ($attr_count, $span_count) = (0, 0); - - for my $line (@lines) { + for my $line (split /\n/, $textdata) { + chomp $line; + $line =~ s/^\s+//; if ($line =~ /\:/) { my ($k, $v) = split /\: /, $line; $v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/); $stack[scalar(@stack)-1]{$k} = $v; } elsif ($line =~ /\{/) { $line =~ s/\s\{//; - if ($line eq 'attributes') { - $line = 'attribute' . $attr_count++; - } + $line = 'attribute' . $attr_count++ if ($line eq 'attributes'); if ($line eq 'spans') { $line = 'span' . $span_count++; $attr_count = 0; @@ -502,8 +497,7 @@ sub grpc { LocalPort => $p, Listen => 5, Reuse => 1 - ) - or die "Can't create listening socket: $!\n"; + ) or die "Can't create listening socket: $!\n"; $f->{http_start} = sub { if (IO::Select->new($server)->can_read(5)) { diff --git a/tests/otel_collector.t b/tests/otel_collector.t index bbef276..223e5ec 100644 --- a/tests/otel_collector.t +++ b/tests/otel_collector.t @@ -364,6 +364,7 @@ like($tp_resp_propagate, sub http_get_traceparent { my ($path) = @_; + return http(< $s); } @@ -385,7 +388,8 @@ sub get_ssl_socket { return http( '', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1 - );} + ); +} sub get_attr { my($attr, $type, $obj) = @_;