Skip to content

Commit 6fc0d59

Browse files
authored
Trigger trace (#15)
* env.sh - more echo doc/help * src/settings.cc - updates for latest oboe 6.0.0 * oboe/* - new oboe 6.0.0 version * src/settings.cc - bug fixes - set out.version = 2 - create javascript objects for returned object * test/settings - earrange tests - make source check last to verify others correct * src/settings.cc - fix timestamp declaration * oboe/* - new liboboe 6.0.0 * oboe/ latest v6.0.0 * src/settings.cc - comment out debugging code - needs a debug strategy but that will wait * src/settings.cc - add typeProvisioned - ttRequested => typeRequested - return typeProvisioned * add ec2 metadata timeout src/bindings.cc - implement in oboeInit() test/bindings.test.js - verify good and bad values * src/settings.cc add customTriggerMode - allow specifying custom_trigger_mode * verify oboe_init_options_set_defaults() is valid - oboe/* - new oboe 6.0.0 - src/bindings.cc - throw on error * src/bindings.cc - rework oboeInit() code - remove debug option, replace with optional arg - capture processed/valid options - remove unused file options (via commenting) * test - rework env var testing - test/bindings - move env var reading to separate module - move keyMap to separate module - localize test data to test using it when only one - test/lib/env-var-key-map.js - define ENV_NAME => var name, var type - test/lib/env-var-options.js - create class for handling prefixed env vars * oboe/* - new version 6.0.0 * test/ - tweaks bindings.test.js - use logLevel 3, not 100 settings.test.js - allow source of 1 or 6 * package* - bump version 7.0.0-rc1 * .npmignore - add working/ * oboe/* - production 6.0.0 * package*.json - v7.0.0
1 parent b93a552 commit 6fc0d59

18 files changed

+446
-269
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ env.sh
1818
*.tgz
1919
*.tmp
2020
*-notes.md
21+
working/

env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ get_new_oboe() {
4545
echo "$ . env.sh fetch-oboe-version latest"
4646
echo "or:"
4747
echo "$ . env.sh install-oboe-version 4.1.0"
48+
echo "or if wanting to fetch from staging rather than production:"
49+
echo "$ SOURCE=STAGING . env.sh install-oboe-version 6.0.0"
4850
return
4951
fi
5052
if [ $(which wget) ]; then

oboe/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.1
1+
6.0.0
8.46 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
182a50f5f79508ca930025efb08f08df7c6676e9d89979722a0fe670e3a1e7a0
1+
fb77d07c8591e0f92397f67746f11a7345a06e6fa8331fbc8a1e893886cc1e99
4.46 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
36747b266c91303ca4e293b44a6c08ba6b0c85a15b28aff67f67c48b8e5f001b
1+
53bd66867248369ea5ee0d53d55213d9ae9db70152968cee7f52ddfd79d2456d

oboe/liboboe-1.0-x86_64.so.0.0.0

9.36 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
42bada3273f3c802f889cc30610ff1f74c8606592592153905e1a112d465f24c
1+
8a37dc1336d1e294b704571513166525e06467b606715661941e33b8874a5860

oboe/oboe.h

Lines changed: 89 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ extern "C" {
8181
* Default events flush batch size in KB.
8282
*/
8383
#define OBOE_DEFAULT_EVENTS_FLUSH_BATCH_SIZE 2000
84+
/**
85+
* Default EC2 metadata timeout in milliseconds
86+
*/
87+
#define OBOE_DEFAULT_EC2_METADATA_TIMEOUT 1000
8488

8589
#define OBOE_SAMPLE_RESOLUTION 1000000
8690

@@ -167,6 +171,8 @@ typedef struct oboe_init_options {
167171
int token_bucket_capacity; // custom token bucket capacity
168172
int token_bucket_rate; // custom token bucket rate
169173
int file_single; // use single files in file reporter for each event
174+
175+
int ec2_metadata_timeout; // EC2 metadata timeout in milliseconds
170176
} oboe_init_options_t;
171177

172178
typedef struct oboe_span_params {
@@ -183,12 +189,22 @@ typedef struct oboe_span_params {
183189
int do_metrics; // boolean flag whether a (HTTP) span should be sent (1) or not (0)
184190
} oboe_span_params_t;
185191

192+
//
193+
// oboe_get_tracing_decisions input and output structures
194+
//
186195
typedef struct oboe_tracing_decisions_in {
187-
int version;
188-
const char *service_name;
189-
const char *in_xtrace;
190-
int custom_sample_rate;
191-
int custom_tracing_mode;
196+
int version; // the version of this structure
197+
const char *service_name; // custom service name
198+
const char *in_xtrace; // existing X-Trace from passed in HTTP header
199+
int custom_sample_rate; // custom sample rate
200+
int custom_tracing_mode; // custom tracing mode
201+
202+
// v2
203+
int custom_trigger_mode; // custom trigger mode
204+
int request_type; // the request type: OBOE_REQUEST_TYPE_REGULAR, OBOE_REQUEST_TYPE_TRIGGER
205+
const char *header_options; // X-Trace-Options HTTP header value
206+
const char *header_signature; // X-Trace-Options-Signature HTTP header value
207+
time_t header_timestamp; // timestamp from X-Trace-Options header, converted to UNIX timestamp format
192208
} oboe_tracing_decisions_in_t;
193209

194210
typedef struct oboe_tracing_decisions_out {
@@ -197,6 +213,12 @@ typedef struct oboe_tracing_decisions_out {
197213
int sample_source;
198214
int do_sample;
199215
int do_metrics;
216+
217+
// v2
218+
int request_provisioned;
219+
int auth_status;
220+
const char *auth_message;
221+
const char *status_message;
200222
} oboe_tracing_decisions_out_t;
201223

202224
typedef struct oboe_internal_stats {
@@ -367,7 +389,12 @@ int oboe_init(oboe_init_options_t* options);
367389
*/
368390
int oboe_init_reporter(const char *protocol, oboe_init_options_t *options);
369391

370-
void oboe_init_options_set_defaults(oboe_init_options_t *options);
392+
/**
393+
* returns one of these:
394+
* - OBOE_INIT_OPTIONS_SET_DEFAULTS_OK
395+
* - OBOE_INIT_OPTIONS_SET_DEFAULTS_WRONG_VERSION
396+
*/
397+
int oboe_init_options_set_defaults(oboe_init_options_t *options);
371398

372399
/**
373400
* Disconnect or shut down the Oboe reporter, but allow it to be reconnect()ed.
@@ -429,6 +456,7 @@ void oboe_shutdown();
429456
#define OBOE_SETTINGS_FLAG_SAMPLE_START 0x4
430457
#define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH 0x8
431458
#define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH_ALWAYS 0x10
459+
#define OBOE_SETTINGS_FLAG_TRIGGERED_TRACE 0x20
432460
#define OBOE_SETTINGS_MAX_STRLEN 256
433461

434462
#define OBOE_SETTINGS_UNSET -1
@@ -455,9 +483,6 @@ void oboe_shutdown();
455483
#pragma pack(push, 1)
456484
#endif
457485

458-
#define TOKEN_BUCKET_CAPACITY_DEFAULT 16 // bucket capacity (how many tokens fit into the bucket)
459-
#define TOKEN_BUCKET_RATE_PER_SECOND_DEFAULT 8 // rate per second (number of tokens per second)
460-
461486
#define OBOE_SEND_EVENT 0
462487
#define OBOE_SEND_STATUS 1
463488
#define OBOE_SEND_PROFILING 2
@@ -477,7 +502,17 @@ void oboe_shutdown();
477502
#define OBOE_SPAN_NO_REPORTER -4
478503
#define OBOE_SPAN_NOT_READY -5
479504

480-
// these codes are used by oboe_sample_layer_custom(), oboe_tracing_decisions(), oboe_reporter_is_ready()
505+
// these codes are returned by oboe_sample_layer_custom(), oboe_tracing_decisions(),
506+
// oboe_reporter_is_ready(), and referenced in settings_messages.c (to convert
507+
// error codes to messages.)
508+
//
509+
// they are structured such that codes that are <= 0 are successful, i.e., no
510+
// error status needs to be reported to the user, while codes > 0 are errors that
511+
// need to be reported.
512+
513+
#define OBOE_TRACING_DECISIONS_FAILED_AUTH -5
514+
#define OBOE_TRACING_DECISIONS_TRIGGERED_TRACE_EXHAUSTED -4
515+
#define OBOE_TRACING_DECISIONS_TRIGGERED_TRACE_DISABLED -3
481516
#define OBOE_TRACING_DECISIONS_TRACING_DISABLED -2
482517
#define OBOE_TRACING_DECISIONS_XTRACE_NOT_SAMPLED -1
483518
#define OBOE_TRACING_DECISIONS_OK 0
@@ -486,8 +521,31 @@ void oboe_shutdown();
486521
#define OBOE_TRACING_DECISIONS_REPORTER_NOT_READY 3
487522
#define OBOE_TRACING_DECISIONS_NO_VALID_SETTINGS 4
488523
#define OBOE_TRACING_DECISIONS_QUEUE_FULL 5
524+
#define OBOE_TRACING_DECISIONS_BAD_ARG 6
525+
526+
// convert above codes into const char* messages.
527+
const char* oboe_get_tracing_decisions_message(int code);
528+
529+
#define OBOE_TRACING_DECISIONS_AUTH_NOT_CHECKED -2
530+
#define OBOE_TRACING_DECISIONS_AUTH_NOT_PRESENT -1
531+
#define OBOE_TRACING_DECISIONS_AUTH_OK 0
532+
#define OBOE_TRACING_DECISIONS_AUTH_NO_SIG_KEY 1
533+
#define OBOE_TRACING_DECISIONS_AUTH_INVALID_SIG 2
534+
#define OBOE_TRACING_DECISIONS_AUTH_BAD_TIMESTAMP 3
535+
536+
// convert above codes into const char* messages.
537+
const char* oboe_get_tracing_decisions_auth_message (int code);
489538

490-
// these codes are used by oboe_init(), oboe_init_reporter(), _oboe_create_reporter()
539+
#define OBOE_REQUEST_TYPE_NONE -1
540+
#define OBOE_REQUEST_TYPE_REGULAR 0
541+
#define OBOE_REQUEST_TYPE_TRIGGER 1
542+
543+
#define OBOE_INIT_OPTIONS_SET_DEFAULTS_OK 0
544+
#define OBOE_INIT_OPTIONS_SET_DEFAULTS_WRONG_VERSION 1
545+
546+
//
547+
// these codes are returned by oboe_init(), oboe_init_reporter(), _oboe_create_reporter()
548+
//
491549
#define OBOE_INIT_ALREADY_INIT -1
492550
#define OBOE_INIT_OK 0
493551
#define OBOE_INIT_WRONG_VERSION 1
@@ -501,6 +559,17 @@ void oboe_shutdown();
501559
#define OBOE_INIT_SSL_LOAD_CERT 9
502560
#define OBOE_INIT_SSL_REPORTER_CREATE 10
503561

562+
// token buckets
563+
enum TOKEN_BUCKETS {
564+
TOKEN_BUCKET_SAMPLING, // for normal requests
565+
TOKEN_BUCKET_TT_RELAXED, // for triggered traces initiated by Pingdom and
566+
// other trusted sources (relaxed settings)
567+
TOKEN_BUCKET_TT_STRICT, // for triggered traces initiated by CLI and
568+
// other untrusted sources (strict settings)
569+
TOKEN_BUCKET_COUNT // IMPORTANT NOTE: this must be the last element
570+
// inside the enum
571+
};
572+
504573
typedef struct {
505574
uint32_t magic;
506575
uint32_t timestamp;
@@ -510,8 +579,9 @@ typedef struct {
510579
uint32_t ttl;
511580
uint32_t _pad;
512581
char layer[OBOE_SETTINGS_MAX_STRLEN]; // Flawfinder: ignore
513-
double bucket_capacity;
514-
double bucket_rate_per_sec;
582+
double bucket_capacity[TOKEN_BUCKET_COUNT];
583+
double bucket_rate_per_sec[TOKEN_BUCKET_COUNT];
584+
char signature_key[OBOE_SETTINGS_MAX_STRLEN]; // Flawfinder: ignore
515585
} oboe_settings_t;
516586

517587
typedef struct {
@@ -531,6 +601,7 @@ typedef struct {
531601
volatile uint32_t through_count; // # of through traces
532602
volatile uint32_t through_ignored_count; // # of new requests, that are rejected due to start_always_flag == 0
533603
// that have through_always_flag == 1
604+
volatile uint32_t triggered_count; // # of triggered traces
534605
volatile uint32_t last_used_sample_rate;
535606
volatile uint32_t last_used_sample_source;
536607

@@ -541,12 +612,13 @@ typedef struct {
541612
typedef struct {
542613
int tracing_mode; // pushed from server, override from config file
543614
int sample_rate; // pushed from server, override from config file
615+
int trigger_mode; // pushed from server, override from config file
544616
oboe_settings_t *settings; // cached settings, updated by tracelyzer (init to NULL)
545617
int last_auto_sample_rate; // stores last known automatic sampling rate
546618
uint16_t last_auto_flags; // stores last known flags associated with above
547619
uint32_t last_auto_timestamp; // timestamp from last *settings lookup
548620
uint32_t last_refresh; // last refresh time
549-
token_bucket_t bucket;
621+
token_bucket_t bucket[TOKEN_BUCKET_COUNT]; // token buckets for various tasks
550622
} oboe_settings_cfg_t;
551623

552624
int oboe_settings_init_local();
@@ -560,9 +632,10 @@ entry_layer_t* oboe_settings_entry_layer_get(const char* name);
560632
oboe_settings_cfg_t* oboe_settings_cfg_get();
561633
void oboe_settings_cfg_init(oboe_settings_cfg_t *cfg);
562634

563-
void oboe_settings_set(int sample_rate, int tracing_mode);
635+
void oboe_settings_set(int sample_rate, int tracing_mode, int trigger_mode);
564636
void oboe_settings_rate_set(int sample_rate);
565637
void oboe_settings_mode_set(int tracing_mode);
638+
void oboe_settings_trigger_set(int trigger_mode);
566639

567640
int oboe_rand_get_value();
568641

@@ -588,49 +661,7 @@ int oboe_sample_is_enabled(oboe_settings_cfg_t *cfg);
588661
* headers, and, if appropriate, rolls the virtual dice to
589662
* decide if this request should be sampled.
590663
*
591-
* This is designed to be called once per layer per request.
592-
*
593-
* @param service_name Service name used for this request (may be NULL to use default settings)
594-
* @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
595-
* @param sample_rate_out The sample rate used to check if this request should be sampled
596-
* (output - may be zero if not used).
597-
* @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
598-
* should be sampled (output - may be zero if not used).
599-
* @return Non-zero if the given request should be sampled.
600-
*/
601-
int oboe_sample_layer(
602-
const char *service_name,
603-
const char *xtrace,
604-
int *sample_rate_out,
605-
int *sample_source_out
606-
);
607-
608-
/**
609-
* Same as oboe_sample_layer() but accepting custom sample rate and custom tracing mode
610-
*
611-
* @param service_name Service name used for this request (may be NULL to use default settings)
612-
* @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
613-
* @param custom_sample_rate a custom sample rate only used for this request (OBOE_SETTINGS_UNSET won't override)
614-
* @param custom_tracing_mode a custom tracing mode only used for this request (OBOE_SETTINGS_UNSET won't override)
615-
* @param sample_rate_out The sample rate used to check if this request should be sampled
616-
* (output - may be zero if not used).
617-
* @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
618-
* should be sampled (output - may be zero if not used).
619-
* @param flags_out The flags used to check if this request should be sampled
620-
*/
621-
int oboe_sample_layer_custom(
622-
const char *service_name,
623-
const char *in_xtrace,
624-
int custom_sample_rate,
625-
int custom_tracing_mode,
626-
int *sampling_decision_out,
627-
int *sample_rate_out,
628-
int *sample_source_out,
629-
uint16_t *flags_out
630-
);
631-
632-
/**
633-
* wrapper for calling oboe_sample_layer_custom() with input/output structs instead of individual params
664+
* This is designed to be called once per request.
634665
*
635666
* @param in Struct containing all params to help making a tracing decision
636667
* @param out Struct containing all params that get set during decision making

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "appoptics-bindings",
3-
"version": "6.4.0",
3+
"version": "7.0.0",
44
"description": "Bindings to liboboe for the AppOptics APM agent",
55
"author": "Bruce A. MacNaughton <[email protected]>",
66
"contributors": [

0 commit comments

Comments
 (0)