Skip to content

Commit

Permalink
Add support for sending payload to event channel
Browse files Browse the repository at this point in the history
Closes: #1594
  • Loading branch information
michalbiesek committed Jul 20, 2023
1 parent e70cb92 commit 95ba0fe
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 35 deletions.
11 changes: 7 additions & 4 deletions src/cfgutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2863,10 +2863,13 @@ initCtl(config_t *cfg)
*/
payload_status_t payloadStatus = PAYLOAD_STATUS_DISABLE;
if (cfgPayEnable(cfg) || protocolDefinitionsUsePayloads()) {
if (cfgLogStreamEnable(cfg) && !payloadToDiskForced() ) {
payloadStatus = PAYLOAD_STATUS_CRIBL;
} else {
payloadStatus = PAYLOAD_STATUS_DISK;
payloadStatus = PAYLOAD_STATUS_DISK;
if (!payloadToDiskForced()) {
if (cfgLogStreamEnable(cfg)) {
payloadStatus = PAYLOAD_STATUS_CRIBL;
} else if (cfgEvtEnable(cfg)) {
payloadStatus = PAYLOAD_STATUS_CTL;
}
}
}
if (payloadStatus == PAYLOAD_STATUS_CRIBL) {
Expand Down
36 changes: 19 additions & 17 deletions src/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,33 +1232,35 @@ ctlEvtGet(ctl_t *ctl)
return ctl ? ctl->evt : NULL;
}

static transport_status_t
ctlPayConnectionStatus(ctl_t * ctl, payload_status_t payStatus) {
transport_status_t
ctlPayloadConnectionStatus(ctl_t *ctl) {
// retrieve the information about source
payload_status_t payStatus = ctlPayStatus(ctl);
transport_status_t status = {
.configString = NULL,
.isConnected = FALSE,
.connectAttemptCount = 0,
.failureString = NULL};

if ((!ctl) || (payStatus != PAYLOAD_STATUS_DISK)) {
return status;
switch (payStatus) {
case PAYLOAD_STATUS_DISABLE:
return status;
case PAYLOAD_STATUS_CRIBL:
return transportConnectionStatus(ctl->paytrans);
case PAYLOAD_STATUS_CTL:
return transportConnectionStatus(ctl->transport);
case PAYLOAD_STATUS_DISK:
status.configString = ctl->payload.dirRepr;
status.isConnected = TRUE;
return status;
default:
DBG(NULL);
return status;
}

status.configString = ctl->payload.dirRepr;
status.isConnected = TRUE;

return status;
}

transport_status_t
ctlConnectionStatus(ctl_t *ctl, which_transport_t who) {
if (who == CFG_LS) {
payload_status_t status = ctlPayStatus(ctl);
if (status == PAYLOAD_STATUS_CRIBL) {
return transportConnectionStatus(ctl->paytrans);
}
return ctlPayConnectionStatus(ctl, status);
}
ctlConnectionStatus(ctl_t *ctl) {
return transportConnectionStatus(ctl->transport);
}

Expand Down
8 changes: 5 additions & 3 deletions src/ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ typedef enum {

typedef enum {
PAYLOAD_STATUS_DISABLE = 0, // payloads are disabled
PAYLOAD_STATUS_CRIBL = 1, // payloads are enabled and will go to cribl
PAYLOAD_STATUS_DISK = 2, // payloads are enabled and will go on disk
PAYLOAD_STATUS_CRIBL = 1, // payloads are enabled and will use cribl transport
PAYLOAD_STATUS_CTL = 2, // payloads are enabled and will use event transport
PAYLOAD_STATUS_DISK = 3, // payloads are enabled and will go on disk
} payload_status_t;

/**
Expand Down Expand Up @@ -133,7 +134,8 @@ void ctlTransportSet(ctl_t *, transport_t *, which_transport_t);
transport_t * ctlTransport(ctl_t *, which_transport_t);
evt_fmt_t * ctlEvtGet(ctl_t *);
void ctlEvtSet(ctl_t *, evt_fmt_t *);
transport_status_t ctlConnectionStatus(ctl_t *, which_transport_t);
transport_status_t ctlConnectionStatus(ctl_t *);
transport_status_t ctlPayloadConnectionStatus(ctl_t *);

// Accessor for performance
bool ctlEvtSourceEnabled(ctl_t *, watch_t);
Expand Down
4 changes: 2 additions & 2 deletions src/ipc_resp.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ payloadTransportEnabled(void) {
*/
static transport_status_t
payloadTransportStatus(void) {
return ctlConnectionStatus(g_ctl, CFG_LS);
return ctlPayloadConnectionStatus(g_ctl);
}

/*
Expand All @@ -351,7 +351,7 @@ eventsTransportEnabled(void) {
*/
static transport_status_t
eventsTransportStatus(void) {
return ctlConnectionStatus(g_ctl, CFG_CTL);
return ctlConnectionStatus(g_ctl);
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/scopetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ typedef struct
// CRIBL_EDGE_FS_ROOT define the location of the host root path inside the Cribl Edge container
#define SCOPE_PID_ENV "SCOPE_PID"
#define PRESERVE_PERF_REPORTING "SCOPE_PERF_PRESERVE"
#define SCOPE_PAYLOAD_TO_DISK_ENV "SCOPE_PAYLOAD_TO_DISK"

// TLS protocol refs that have been useful:
// https://tools.ietf.org/html/rfc5246
Expand Down
2 changes: 1 addition & 1 deletion src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ initState(void)
initMetricCapture();

// Some environment variables we don't want to continuously check
setPayloadToDiskForced(checkEnv(SCOPE_PAYLOAD_TO_DISK_ENV, "true"));
setPayloadToDiskForced(checkEnv("SCOPE_PAYLOAD_TO_DISK", "true"));

// the http guard array is static while the net fs array is dynamically allocated
// will need to change if we want to re-size at runtime
Expand Down
2 changes: 1 addition & 1 deletion src/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ periodic(void *arg)
summaryTime = tv.tv_sec + g_thread.interval;

if (tv.tv_sec >= logReportTime) {
transport_status_t ctlStatus = ctlConnectionStatus(g_ctl, CFG_CTL);
transport_status_t ctlStatus = ctlConnectionStatus(g_ctl);
logOurConnectionStatus(ctlStatus, "event");
transport_status_t mtcStatus = mtcConnectionStatus(g_mtc);
logOurConnectionStatus(mtcStatus, "metric");
Expand Down
4 changes: 2 additions & 2 deletions test/integration/cli/test_inspect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ endtest
# disabled cribl, enabled payloads enabled (via env var) expected to see log, events, metrics, payload
starttest test_inspect_cribl_disable_payload_enable_via_env

SCOPE_CRIBL_ENABLE=false SCOPE_PAYLOAD_ENABLE=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null &
SCOPE_CRIBL_ENABLE=false SCOPE_PAYLOAD_TO_DISK=true SCOPE_PAYLOAD_ENABLE=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null &
sleep 2
PYTHON_PID=`pidof python3`

Expand All @@ -236,7 +236,7 @@ endtest
# in config disabled cribl payloads enabled (via protocol list) expected to see log, events, metrics, payload
starttest test_inspect_cribl_disable_payload_enable_via_config

SCOPE_CONF_PATH=/opt/test/bin/payload_conf.yml LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null &
SCOPE_PAYLOAD_TO_DISK=true SCOPE_CONF_PATH=/opt/test/bin/payload_conf.yml LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null &
sleep 2
PYTHON_PID=`pidof python3`

Expand Down
13 changes: 9 additions & 4 deletions test/integration/payload/scope-test
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,31 @@ FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l)
if (( $FILE_COUNT == 0 )); then
fail "FAILED - expected payload files, but found $FILE_COUNT"
fi
cleanup
endtest

starttest payload_on_but_not_to_cribl_1
echo "When the payload feature is on, and SCOPE_CRIBL_ENABLE=false, verify"
echo "When the payload feature is on, SCOPE_EVENT_ENABLE=false and SCOPE_CRIBL_ENABLE=false, verify"
echo " payloads are written to disk. Payloads always go to disk if"
echo " SCOPE_CRIBL_ENABLE=false"
echo " SCOPE_CRIBL_ENABLE=false and SCOPE_EVENT_ENABLE=false"
SCOPE_PAYLOAD_ENABLE=true \
SCOPE_CRIBL_ENABLE=false \
SCOPE_EVENT_ENABLE=false \
scope run -- curl -Lso /dev/null https://cribl.io
FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l)
if (( $FILE_COUNT == 0 )); then
fail "FAILED - expected payload files, but found $FILE_COUNT"
fi
cleanup
endtest

starttest payload_on_but_not_to_cribl_2
echo "When the payload feature is on, and SCOPE_CRIBL_ENABLE=false, verify"
echo "When the payload feature is on, and SCOPE_EVENT_ENABLE=false and SCOPE_CRIBL_ENABLE=false, verify"
echo " payloads are written to disk even if SCOPE_PAYLOAD_TO_DISK=false."
echo " Payloads always go to disk if SCOPE_CRIBL_ENABLE=false"
echo " Payloads always go to disk if SCOPE_CRIBL_ENABLE=false and SCOPE_EVENT_ENABLE=false"
SCOPE_PAYLOAD_ENABLE=true \
SCOPE_CRIBL_ENABLE=false \
SCOPE_EVENT_ENABLE=false \
SCOPE_PAYLOAD_TO_DISK=false \
scope run -- curl -Lso /dev/null https://cribl.io
FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l)
Expand All @@ -159,6 +163,7 @@ endtest
starttest payload_host_app
SCOPE_PAYLOAD_ENABLE=true \
SCOPE_CRIBL_ENABLE=false \
SCOPE_PAYLOAD_TO_DISK=true \
scope run -- host -t a cribl.io
in_count=$(get_file_count_with_extension $SCOPE_PAYLOAD_DIR "in")
out_count=$(get_file_count_with_extension $SCOPE_PAYLOAD_DIR "out")
Expand Down

0 comments on commit 95ba0fe

Please sign in to comment.