fixup! add: functional tests

This commit is contained in:
Eugene Grebenschikov 2023-06-07 19:58:47 -07:00
parent d29caf3e01
commit 614e77e8fe
5 changed files with 43 additions and 46 deletions

View file

@ -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 \

View file

@ -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)) {

View file

@ -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) = @_;

View file

@ -360,6 +360,7 @@ like($tp_resp_propagate,
sub http_get_traceparent {
my ($path) = @_;
return http(<<EOF);
GET $path HTTP/1.0
Host: localhost
@ -372,7 +373,9 @@ EOF
sub http_get_ssl {
my ($path) = @_;
my $s = get_ssl_socket(8081) or return;
return http_get($path, socket => $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)) {

View file

@ -364,6 +364,7 @@ like($tp_resp_propagate,
sub http_get_traceparent {
my ($path) = @_;
return http(<<EOF);
GET $path HTTP/1.0
Host: localhost
@ -376,7 +377,9 @@ EOF
sub http_get_ssl {
my ($path) = @_;
my $s = get_ssl_socket(8081) or return;
return http_get($path, socket => $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) = @_;