fixup! add: functional tests
This commit is contained in:
parent
d29caf3e01
commit
614e77e8fe
5 changed files with 43 additions and 46 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
name: nginx-otel-module
|
name: nginx-otel-module-check
|
||||||
run-name: ${{ github.actor }} is triggering pipeline
|
run-name: ${{ github.actor }} is triggering pipeline
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -9,8 +9,8 @@ jobs:
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Install system dependecies
|
- name: Install system dependecies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update && sudo apt install -y mercurial cmake \
|
sudo apt-get update && sudo apt install -y cmake \
|
||||||
libc-ares-dev libre2-dev libssl-dev zlib1g-dev
|
libc-ares-dev libre2-dev
|
||||||
- name: Checkout and build nginx
|
- name: Checkout and build nginx
|
||||||
run: |
|
run: |
|
||||||
hg clone http://hg.nginx.org/nginx/ && cd nginx && \
|
hg clone http://hg.nginx.org/nginx/ && cd nginx && \
|
||||||
|
|
@ -39,8 +39,10 @@ jobs:
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: nginx-otel-module-stuff
|
name: nginx-otel-module-stuff
|
||||||
- name: Install system dependecies
|
- name: Fix rights
|
||||||
run: sudo apt-get update && sudo apt install -y mercurial curl
|
run: |
|
||||||
|
chmod +x nginx/objs/nginx
|
||||||
|
chmod +x build/_deps/grpc-build/third_party/protobuf/protoc
|
||||||
- name: Install perl modules
|
- name: Install perl modules
|
||||||
run: sudo cpan IO::Socket::SSL
|
run: sudo cpan IO::Socket::SSL
|
||||||
- name: Download otelcol
|
- name: Download otelcol
|
||||||
|
|
@ -51,8 +53,6 @@ jobs:
|
||||||
tar -xzf otelcol_0.76.1_linux_amd64.tar.gz
|
tar -xzf otelcol_0.76.1_linux_amd64.tar.gz
|
||||||
- name: Checkout nginx-test
|
- name: Checkout nginx-test
|
||||||
run: hg clone http://hg.nginx.org/nginx-tests/
|
run: hg clone http://hg.nginx.org/nginx-tests/
|
||||||
- name: List files before tests
|
|
||||||
run: ls -lR .
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
cd tests && PERL5LIB=../nginx-tests/lib TEST_NGINX_UNSAFE=1 \
|
cd tests && PERL5LIB=../nginx-tests/lib TEST_NGINX_UNSAFE=1 \
|
||||||
|
|
@ -367,6 +367,7 @@ is($tp_headers_propagate->{'x-otel-tracestate'},
|
||||||
sub http2_get {
|
sub http2_get {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new();
|
my $s = Test::Nginx::HTTP2->new();
|
||||||
|
|
||||||
my $sid = $s->new_stream({ path => $path });
|
my $sid = $s->new_stream({ path => $path });
|
||||||
|
|
@ -384,6 +385,7 @@ sub http2_get {
|
||||||
sub http2_get_traceparent {
|
sub http2_get_traceparent {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new();
|
my $s = Test::Nginx::HTTP2->new();
|
||||||
|
|
||||||
my $sid = $s->new_stream({ headers => [
|
my $sid = $s->new_stream({ headers => [
|
||||||
|
|
@ -411,6 +413,7 @@ sub http2_get_traceparent {
|
||||||
sub http2_get_ssl {
|
sub http2_get_ssl {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new(undef,
|
my $s = Test::Nginx::HTTP2->new(undef,
|
||||||
socket => get_ssl_socket(8082, ['h2']));
|
socket => get_ssl_socket(8082, ['h2']));
|
||||||
|
|
||||||
|
|
@ -434,7 +437,8 @@ sub get_ssl_socket {
|
||||||
SSL => 1,
|
SSL => 1,
|
||||||
SSL_alpn_protocols => $alpn,
|
SSL_alpn_protocols => $alpn,
|
||||||
SSL_error_trap => sub { die $_[1] }
|
SSL_error_trap => sub { die $_[1] }
|
||||||
);}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub get_attr {
|
sub get_attr {
|
||||||
my($attr, $type, $obj) = @_;
|
my($attr, $type, $obj) = @_;
|
||||||
|
|
@ -457,6 +461,7 @@ sub decode_protobuf {
|
||||||
my ($protobuf) = @_;
|
my ($protobuf) = @_;
|
||||||
|
|
||||||
$protobuf = encode_base64($protobuf);
|
$protobuf = encode_base64($protobuf);
|
||||||
|
|
||||||
open my $cmd => "echo '$protobuf' | base64 -d | " .
|
open my $cmd => "echo '$protobuf' | base64 -d | " .
|
||||||
'$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '.
|
'$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '.
|
||||||
'--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' .
|
'--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' .
|
||||||
|
|
@ -482,6 +487,7 @@ sub decode_bytes {
|
||||||
} elsif ($acc ne '') {
|
} elsif ($acc ne '') {
|
||||||
$acc .= $c;
|
$acc .= $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($acc =~ /\\(\d{3})/) {
|
if ($acc =~ /\\(\d{3})/) {
|
||||||
$res .= chr(oct($1));
|
$res .= chr(oct($1));
|
||||||
$acc = '';
|
$acc = '';
|
||||||
|
|
@ -504,31 +510,21 @@ sub decode_bytes {
|
||||||
|
|
||||||
sub to_hash {
|
sub to_hash {
|
||||||
my ($textdata) = @_;
|
my ($textdata) = @_;
|
||||||
|
|
||||||
my $out;
|
my $out;
|
||||||
|
|
||||||
%{$out} = ();
|
%{$out} = ();
|
||||||
|
|
||||||
my @stack = ($out);
|
my @stack = ($out);
|
||||||
my @lines;
|
|
||||||
|
|
||||||
for (split /\n/, $textdata) {
|
|
||||||
chomp;
|
|
||||||
$_ =~ s/^\s+//;
|
|
||||||
push @lines, $_;
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($attr_count, $span_count) = (0, 0);
|
my ($attr_count, $span_count) = (0, 0);
|
||||||
|
for my $line (split /\n/, $textdata) {
|
||||||
for my $line (@lines) {
|
chomp $line;
|
||||||
|
$line =~ s/^\s+//;
|
||||||
if ($line =~ /\:/) {
|
if ($line =~ /\:/) {
|
||||||
my ($k, $v) = split /\: /, $line;
|
my ($k, $v) = split /\: /, $line;
|
||||||
$v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/);
|
$v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/);
|
||||||
$stack[scalar(@stack)-1]{$k} = $v;
|
$stack[scalar(@stack)-1]{$k} = $v;
|
||||||
} elsif ($line =~ /\{/) {
|
} elsif ($line =~ /\{/) {
|
||||||
$line =~ s/\s\{//;
|
$line =~ s/\s\{//;
|
||||||
if ($line eq 'attributes') {
|
$line = 'attribute' . $attr_count++ if ($line eq 'attributes');
|
||||||
$line = 'attribute' . $attr_count++;
|
|
||||||
}
|
|
||||||
if ($line eq 'spans') {
|
if ($line eq 'spans') {
|
||||||
$line = 'span' . $span_count++;
|
$line = 'span' . $span_count++;
|
||||||
$attr_count = 0;
|
$attr_count = 0;
|
||||||
|
|
@ -554,8 +550,7 @@ sub grpc {
|
||||||
LocalPort => $p,
|
LocalPort => $p,
|
||||||
Listen => 5,
|
Listen => 5,
|
||||||
Reuse => 1
|
Reuse => 1
|
||||||
)
|
) or die "Can't create listening socket: $!\n";
|
||||||
or die "Can't create listening socket: $!\n";
|
|
||||||
|
|
||||||
$f->{http_start} = sub {
|
$f->{http_start} = sub {
|
||||||
if (IO::Select->new($server)->can_read(5)) {
|
if (IO::Select->new($server)->can_read(5)) {
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,7 @@ is($tp_headers_propagate->{'x-otel-tracestate'},
|
||||||
sub http2_get {
|
sub http2_get {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new();
|
my $s = Test::Nginx::HTTP2->new();
|
||||||
|
|
||||||
my $sid = $s->new_stream({ path => $path });
|
my $sid = $s->new_stream({ path => $path });
|
||||||
|
|
@ -390,6 +391,7 @@ sub http2_get {
|
||||||
sub http2_get_traceparent {
|
sub http2_get_traceparent {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new();
|
my $s = Test::Nginx::HTTP2->new();
|
||||||
|
|
||||||
my $sid = $s->new_stream({ headers => [
|
my $sid = $s->new_stream({ headers => [
|
||||||
|
|
@ -417,6 +419,7 @@ sub http2_get_traceparent {
|
||||||
sub http2_get_ssl {
|
sub http2_get_ssl {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
my ($frames, $frame);
|
my ($frames, $frame);
|
||||||
|
|
||||||
my $s = Test::Nginx::HTTP2->new(undef,
|
my $s = Test::Nginx::HTTP2->new(undef,
|
||||||
socket => get_ssl_socket(8082, ['h2']));
|
socket => get_ssl_socket(8082, ['h2']));
|
||||||
|
|
||||||
|
|
@ -440,7 +443,8 @@ sub get_ssl_socket {
|
||||||
SSL => 1,
|
SSL => 1,
|
||||||
SSL_alpn_protocols => $alpn,
|
SSL_alpn_protocols => $alpn,
|
||||||
SSL_error_trap => sub { die $_[1] }
|
SSL_error_trap => sub { die $_[1] }
|
||||||
);}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub get_attr {
|
sub get_attr {
|
||||||
my($attr, $type, $obj) = @_;
|
my($attr, $type, $obj) = @_;
|
||||||
|
|
|
||||||
32
tests/otel.t
32
tests/otel.t
|
|
@ -360,6 +360,7 @@ like($tp_resp_propagate,
|
||||||
|
|
||||||
sub http_get_traceparent {
|
sub http_get_traceparent {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
|
|
||||||
return http(<<EOF);
|
return http(<<EOF);
|
||||||
GET $path HTTP/1.0
|
GET $path HTTP/1.0
|
||||||
Host: localhost
|
Host: localhost
|
||||||
|
|
@ -372,7 +373,9 @@ EOF
|
||||||
|
|
||||||
sub http_get_ssl {
|
sub http_get_ssl {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
|
|
||||||
my $s = get_ssl_socket(8081) or return;
|
my $s = get_ssl_socket(8081) or return;
|
||||||
|
|
||||||
return http_get($path, socket => $s);
|
return http_get($path, socket => $s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -381,7 +384,8 @@ sub get_ssl_socket {
|
||||||
|
|
||||||
return http(
|
return http(
|
||||||
'', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1
|
'', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1
|
||||||
);}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub get_attr {
|
sub get_attr {
|
||||||
my($attr, $type, $obj) = @_;
|
my($attr, $type, $obj) = @_;
|
||||||
|
|
@ -404,6 +408,7 @@ sub decode_protobuf {
|
||||||
my ($protobuf) = @_;
|
my ($protobuf) = @_;
|
||||||
|
|
||||||
$protobuf = encode_base64($protobuf);
|
$protobuf = encode_base64($protobuf);
|
||||||
|
|
||||||
open my $cmd => "echo '$protobuf' | base64 -d | " .
|
open my $cmd => "echo '$protobuf' | base64 -d | " .
|
||||||
'$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '.
|
'$PWD/../build/_deps/grpc-build/third_party/protobuf/protoc '.
|
||||||
'--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' .
|
'--decode opentelemetry.proto.trace.v1.ResourceSpans -I ' .
|
||||||
|
|
@ -429,6 +434,7 @@ sub decode_bytes {
|
||||||
} elsif ($acc ne '') {
|
} elsif ($acc ne '') {
|
||||||
$acc .= $c;
|
$acc .= $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($acc =~ /\\(\d{3})/) {
|
if ($acc =~ /\\(\d{3})/) {
|
||||||
$res .= chr(oct($1));
|
$res .= chr(oct($1));
|
||||||
$acc = '';
|
$acc = '';
|
||||||
|
|
@ -451,32 +457,21 @@ sub decode_bytes {
|
||||||
|
|
||||||
sub to_hash {
|
sub to_hash {
|
||||||
my ($textdata) = @_;
|
my ($textdata) = @_;
|
||||||
|
|
||||||
my $out;
|
my $out;
|
||||||
|
|
||||||
%{$out} = ();
|
%{$out} = ();
|
||||||
|
|
||||||
|
|
||||||
my @stack = ($out);
|
my @stack = ($out);
|
||||||
my @lines;
|
|
||||||
|
|
||||||
for (split /\n/, $textdata) {
|
|
||||||
chomp;
|
|
||||||
$_ =~ s/^\s+//;
|
|
||||||
push @lines, $_;
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($attr_count, $span_count) = (0, 0);
|
my ($attr_count, $span_count) = (0, 0);
|
||||||
|
for my $line (split /\n/, $textdata) {
|
||||||
for my $line (@lines) {
|
chomp $line;
|
||||||
|
$line =~ s/^\s+//;
|
||||||
if ($line =~ /\:/) {
|
if ($line =~ /\:/) {
|
||||||
my ($k, $v) = split /\: /, $line;
|
my ($k, $v) = split /\: /, $line;
|
||||||
$v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/);
|
$v = decode_bytes($v) if ($k =~ /trace_id|span_id|parent_span_id/);
|
||||||
$stack[scalar(@stack)-1]{$k} = $v;
|
$stack[scalar(@stack)-1]{$k} = $v;
|
||||||
} elsif ($line =~ /\{/) {
|
} elsif ($line =~ /\{/) {
|
||||||
$line =~ s/\s\{//;
|
$line =~ s/\s\{//;
|
||||||
if ($line eq 'attributes') {
|
$line = 'attribute' . $attr_count++ if ($line eq 'attributes');
|
||||||
$line = 'attribute' . $attr_count++;
|
|
||||||
}
|
|
||||||
if ($line eq 'spans') {
|
if ($line eq 'spans') {
|
||||||
$line = 'span' . $span_count++;
|
$line = 'span' . $span_count++;
|
||||||
$attr_count = 0;
|
$attr_count = 0;
|
||||||
|
|
@ -502,8 +497,7 @@ sub grpc {
|
||||||
LocalPort => $p,
|
LocalPort => $p,
|
||||||
Listen => 5,
|
Listen => 5,
|
||||||
Reuse => 1
|
Reuse => 1
|
||||||
)
|
) or die "Can't create listening socket: $!\n";
|
||||||
or die "Can't create listening socket: $!\n";
|
|
||||||
|
|
||||||
$f->{http_start} = sub {
|
$f->{http_start} = sub {
|
||||||
if (IO::Select->new($server)->can_read(5)) {
|
if (IO::Select->new($server)->can_read(5)) {
|
||||||
|
|
|
||||||
|
|
@ -364,6 +364,7 @@ like($tp_resp_propagate,
|
||||||
|
|
||||||
sub http_get_traceparent {
|
sub http_get_traceparent {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
|
|
||||||
return http(<<EOF);
|
return http(<<EOF);
|
||||||
GET $path HTTP/1.0
|
GET $path HTTP/1.0
|
||||||
Host: localhost
|
Host: localhost
|
||||||
|
|
@ -376,7 +377,9 @@ EOF
|
||||||
|
|
||||||
sub http_get_ssl {
|
sub http_get_ssl {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
|
|
||||||
my $s = get_ssl_socket(8081) or return;
|
my $s = get_ssl_socket(8081) or return;
|
||||||
|
|
||||||
return http_get($path, socket => $s);
|
return http_get($path, socket => $s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -385,7 +388,8 @@ sub get_ssl_socket {
|
||||||
|
|
||||||
return http(
|
return http(
|
||||||
'', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1
|
'', PeerAddr => '127.0.0.1:' . port($port), start => 1, SSL => 1
|
||||||
);}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub get_attr {
|
sub get_attr {
|
||||||
my($attr, $type, $obj) = @_;
|
my($attr, $type, $obj) = @_;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue