Skip to content
Snippets Groups Projects

Enable head-based sampling and add some scripts for large scale deployment

Merged Zhiqiang Xie requested to merge zxie into main
4 files
+ 31
47
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 17
4
@@ -23,6 +23,7 @@
#include <atomic>
#include <chrono>
#include <map>
#include <iterator>
#include <grpc/support/log.h>
#include <grpcpp/grpcpp.h>
@@ -48,6 +49,8 @@ static struct argp_option options[] = {
{"topology", 't', "FILE", 0, "A topology file. This is required. See config/example_topology.json for an example." },
{"addresses", 'a', "FILE", 0, "An addresses file. This is required. See config/example_addresses.json for an example." },
{"interval", 'i', "NUM", 0, "Interval size in seconds, default 10. Each trace will log the interval when it was generated." },
// only for opentelemetry based tracers
{"sampling", 's', "NUM", 0, "Probability of head-based sampling. Default 1." },
{ 0 }
};
@@ -60,6 +63,7 @@ struct arguments {
char* service_name;
char* topology_filename;
char* addresses_filename;
float sampling;
};
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
@@ -88,6 +92,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
case 'a':
arguments->addresses_filename = arg;
break;
case 's':
arguments->sampling = atof(arg);
case ARGP_KEY_ARG:
if (state->arg_num >= 1)
/* Too many arguments. */
@@ -122,6 +128,7 @@ using opentelemetry::sdk::trace::IdGenerator;
using opentelemetry::sdk::trace::RandomIdGenerator;
bool debug;
float sample_probability;
uint32_t max_requests;
uint32_t initial_requests;
@@ -167,8 +174,8 @@ class HindsightGRPCClient {
request.mutable_otel()->set_trace_id(std::string(tid_buffer, 32));
// special span id
request.mutable_otel()->set_span_id(std::string("ffffffffffffffff"));
// todo: command for head-based sampling policy
request.mutable_otel()->set_sample(true);
// set the sample flag with probability specified by user commands
request.mutable_otel()->set_sample(rand() / sample_probability > RAND_MAX ? false : true);
// truncate the first 64 bits to fit into hindsight
uint64_t trace_id = *((uint64_t*) tid_raw.Id().data());
@@ -233,8 +240,11 @@ class HindsightGRPCClient {
// Submit next call
if (max_requests == 0 || sent_count < max_requests) {
std::string api_name = apis_.begin()->first;
Exec(api_name, flag_r); // The actual RPC call!
// std::string api_name = apis_.begin()->first;
// Exec(api_name, flag_r); // The actual RPC call!
auto api_iter = apis_.begin();
std::advance(api_iter, rand() % apis_.size());
Exec(api_iter->first, flag_r); // The actual RPC call!
} else if (received_count < max_requests) {
continue;
} else {
@@ -305,10 +315,13 @@ int main(int argc, char** argv) {
arguments.topology_filename = NULL;
arguments.addresses_filename = NULL;
arguments.interval = 10;
arguments.sampling = 1;
/* Parse the arguments */
argp_parse (&argp, argc, argv, 0, 0, &arguments);
sample_probability = arguments.sampling;
/* If 'standalone' is specified as the service name, it is a special case */
if (strcmp(arguments.service_name, "standalone") == 0) {
std::cout << "Using the built-in standalone configuration" << std::endl;
Loading