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

Check otel endpoint update in tap test #63

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
68 changes: 68 additions & 0 deletions t/003_change_endpoint.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use strict;
use warnings;

use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;

my $node = PostgreSQL::Test::Cluster->new('main');

{
package TestWebServer;

use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);

sub handle_request {
print "HTTP/1.0 200 OK\r\n";
}
}
# Start test http server that will receive spans
my $webserver_pid = TestWebServer->new(4318)->background();

$SIG{TERM} = $SIG{INT} = sub {
kill 'INT', $webserver_pid;
die "death by signal";
};

$node->init;
$node->append_conf(
'postgresql.conf',
qq{shared_preload_libraries = 'pg_tracing'
pg_tracing.otel_naptime = 1000
pg_tracing.otel_endpoint = 'http://127.0.100.100:5555'
log_min_messages = info
});

$node->start;

# setup
$node->safe_psql("postgres",
"CREATE EXTENSION pg_tracing;");

# Create one trace
$node->safe_psql("postgres", "/*traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/SELECT 1");

# Sending spans should fail as endpoint is incorrect
ok( $node->poll_query_until('postgres', "SELECT otel_failures >= 1 FROM pg_tracing_info;"),
"Otel failures should be reported");

# Update otel endpoint
$node->append_conf('postgresql.conf', "pg_tracing.otel_endpoint = 'http://localhost:4318'");
$node->reload;

# Sending span should eventually succeed with the new endpoint
ok( $node->poll_query_until('postgres',
"SELECT otel_sent_spans FROM pg_tracing_info;",
4),
"Spans were sent to otel collector");

my $result =
$node->safe_psql('postgres', "SELECT count(*) FROM pg_tracing_peek_spans;");
is($result, qq(0), 'All spans should have been consumed');

# Cleanup
$node->stop;
kill 'INT', $webserver_pid;

done_testing();