From f0789427fe96535822dc4def1b257af86dacdf0c Mon Sep 17 00:00:00 2001 From: michalbiesek Date: Thu, 20 Jul 2023 18:39:10 +0200 Subject: [PATCH] Add support for payload destination in CLI/cfg - allows to change payload destination to event transport - by default the payloads will go to directory - it is possible to change this behaviour via: - `--payloadsdest` argument in `scope` CLI - `SCOPE_PAYLOAD_DEST` environment variable - allowed values are for the above are "event", "dir" Closes #1594 --- cli/cmd/attach.go | 2 + cli/cmd/rules.go | 2 + cli/cmd/run.go | 2 + cli/cmd/util.go | 1 + cli/libscope/config.go | 1 + cli/run/run.go | 1 + cli/run/scopeconfig.go | 9 ++ conf/scope.yml | 15 +++ docs/Help.md | 5 + docs/schemas/definitions/data.schema.json | 6 ++ docs/schemas/event_start_msg.schema.json | 5 +- src/cfg.c | 14 +++ src/cfg.h | 2 + src/cfgutils.c | 42 +++++++- src/ctl.c | 36 +++---- src/ctl.h | 8 +- src/ipc_resp.c | 4 +- src/report.c | 99 ++++++++++--------- src/scopetypes.h | 3 +- src/state.c | 15 --- src/state.h | 2 - src/wrap.c | 2 +- test/integration/cli/test_inspect.sh | 6 +- test/integration/payload/scope-test | 28 +++--- test/integration/transport/scope-test | 10 +- .../fluentbit/services/nginx/config/scope.yml | 15 +++ test/manual/payload/conf_1/scope.yml | 15 +++ test/manual/payload/conf_2/scope.yml | 15 +++ test/manual/payload/conf_3/scope.yml | 15 +++ test/manual/send_event/conf_1/scope.yml | 15 +++ test/unit/library/cfgutilstest.c | 32 ++++++ website/src/pages/docs/cli-reference.md | 4 + website/src/pages/docs/cli-using.md | 2 +- 33 files changed, 323 insertions(+), 110 deletions(-) diff --git a/cli/cmd/attach.go b/cli/cmd/attach.go index ad2ff91f1..b096c1541 100644 --- a/cli/cmd/attach.go +++ b/cli/cmd/attach.go @@ -69,6 +69,8 @@ be set to sockets with unix:///var/run/mysock, tcp://hostname:port, udp://hostna helpErrAndExit(cmd, "Cannot specify --verbosity and --userconfig") } else if rc.Payloads && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --payloads and --userconfig") + } else if rc.PayloadsDest != "" && rc.UserConfig != "" { + helpErrAndExit(cmd, "Cannot specify --payloadsdest and --userconfig") } else if rc.Loglevel != "" && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --loglevel and --userconfig") } else if rc.Backtrace && rc.UserConfig != "" { diff --git a/cli/cmd/rules.go b/cli/cmd/rules.go index fcfe98c04..7b81818b6 100644 --- a/cli/cmd/rules.go +++ b/cli/cmd/rules.go @@ -86,6 +86,8 @@ var rulesCmd = &cobra.Command{ helpErrAndExit(cmd, "Cannot specify --verbosity and --userconfig") } else if rc.Payloads && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --payloads and --userconfig") + } else if rc.PayloadsDest != "" && rc.UserConfig != "" { + helpErrAndExit(cmd, "Cannot specify --payloadsdest and --userconfig") } else if rc.Loglevel != "" && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --loglevel and --userconfig") } else if rc.Backtrace && rc.UserConfig != "" { diff --git a/cli/cmd/run.go b/cli/cmd/run.go index 1c78d8359..2d4f12ca8 100644 --- a/cli/cmd/run.go +++ b/cli/cmd/run.go @@ -63,6 +63,8 @@ The --*dest flags accept file names like /tmp/scope.log; URLs like file:///tmp/s helpErrAndExit(cmd, "Cannot specify --verbosity and --userconfig") } else if rc.Payloads && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --payloads and --userconfig") + } else if rc.PayloadsDest != "" && rc.UserConfig != "" { + helpErrAndExit(cmd, "Cannot specify --payloadsdest and --userconfig") } else if rc.Loglevel != "" && rc.UserConfig != "" { helpErrAndExit(cmd, "Cannot specify --loglevel and --userconfig") } else if rc.Backtrace && rc.UserConfig != "" { diff --git a/cli/cmd/util.go b/cli/cmd/util.go index 362226c6e..ce81d1ae5 100644 --- a/cli/cmd/util.go +++ b/cli/cmd/util.go @@ -59,6 +59,7 @@ func metricAndEventDestFlags(cmd *cobra.Command, rc *run.Config) { func runCmdFlags(cmd *cobra.Command, rc *run.Config) { cmd.Flags().IntVarP(&rc.Verbosity, "verbosity", "v", 4, "Set scope metric verbosity") cmd.Flags().BoolVarP(&rc.Payloads, "payloads", "p", false, "Capture payloads of network transactions") + cmd.Flags().StringVarP(&rc.PayloadsDest, "payloadsdest", "", "dir", "Set destination for payloads (dir|event)") cmd.Flags().StringVar(&rc.Loglevel, "loglevel", "", "Set scope library log level (debug, warning, info, error, none)") cmd.Flags().StringVarP(&rc.LibraryPath, "librarypath", "l", "", "Set path for dynamic libraries") cmd.Flags().StringVarP(&rc.UserConfig, "userconfig", "u", "", "Scope an application with a user specified config file; overrides all other settings.") diff --git a/cli/libscope/config.go b/cli/libscope/config.go index 33bc8dcfe..ec2f668fa 100644 --- a/cli/libscope/config.go +++ b/cli/libscope/config.go @@ -67,6 +67,7 @@ type ScopeEventConfig struct { // ScopePayloadConfig represents how to capture payloads type ScopePayloadConfig struct { Enable BoolString `mapstructure:"enable" json:"enable" yaml:"enable"` + Type string `mapstructure:"type" json:"type" yaml:"type"` Dir string `mapstructure:"dir" json:"dir" yaml:"dir"` } diff --git a/cli/run/run.go b/cli/run/run.go index 1148bc2d1..dda8d2775 100644 --- a/cli/run/run.go +++ b/cli/run/run.go @@ -15,6 +15,7 @@ type Config struct { WorkDir string Verbosity int Payloads bool + PayloadsDest string MetricsDest string EventsDest string MetricsFormat string diff --git a/cli/run/scopeconfig.go b/cli/run/scopeconfig.go index 62b860bdf..1799c47bc 100644 --- a/cli/run/scopeconfig.go +++ b/cli/run/scopeconfig.go @@ -191,10 +191,19 @@ func (c *Config) configFromRunOpts() error { if c.Payloads { c.sc.Payload = libscope.ScopePayloadConfig{ Enable: "true", + Type: "dir", Dir: filepath.Join(c.WorkDir, "payloads"), } } + if c.PayloadsDest != "" { + if c.PayloadsDest != "dir" && c.PayloadsDest != "event" { + return fmt.Errorf("invalid payload destination %s", c.PayloadsDest) + } + c.sc.Payload.Type = "event" + // TODO should we empty c.sc.Payload.Dir as well ? + } + if c.MetricsFormat != "" { if c.MetricsFormat != "ndjson" && c.MetricsFormat != "statsd" { return fmt.Errorf("invalid metrics format %s", c.MetricsFormat) diff --git a/conf/scope.yml b/conf/scope.yml index 8290f62b9..6e69508e8 100644 --- a/conf/scope.yml +++ b/conf/scope.yml @@ -604,6 +604,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -612,6 +625,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting up the AppScope library diff --git a/docs/Help.md b/docs/Help.md index 91faf12c2..4ac44c1d6 100644 --- a/docs/Help.md +++ b/docs/Help.md @@ -243,6 +243,11 @@ Environment Variables: Default is /tmp SCOPE_PAYLOAD_ENABLE Flag that enables payload capture. true,false Default is false. + SCOPE_PAYLOAD_DEST + Specifies a payload destination. Possible values, are: + - 'dir' - payload files are captured in the directory + - 'event' - payload files are captured in same destination as event + Default is dir. SCOPE_PAYLOAD_DIR Specifies a directory where payload capture files can be written. Default is /tmp diff --git a/docs/schemas/definitions/data.schema.json b/docs/schemas/definitions/data.schema.json index 60f9fc252..fd17cdbea 100644 --- a/docs/schemas/definitions/data.schema.json +++ b/docs/schemas/definitions/data.schema.json @@ -448,6 +448,12 @@ "type": "string", "enum": ["true", "false"] }, + "payload_type": { + "title": "type", + "description": "Specifies the transport mechanism on which t emit the network payloads. See `scope.yml`.", + "type": "string", + "enum": ["dir", "event"] + }, "pid": { "title": "pid", "description": "The process ID of the scoped app.", diff --git a/docs/schemas/event_start_msg.schema.json b/docs/schemas/event_start_msg.schema.json index 038f42a4d..4c52943d3 100644 --- a/docs/schemas/event_start_msg.schema.json +++ b/docs/schemas/event_start_msg.schema.json @@ -4,7 +4,7 @@ "type": "object", "title": "AppScope Start message", "description": "Structure of the process-start message", - "examples": [{"format":"ndjson","info":{"process":{"libscopever":"v1.3.0","pid":35673,"ppid":3390,"gid":1000,"groupname":"test_user","uid":1000,"username":"test_user","hostname":"test_user","procname":"ls","cmd":"ls --color=auto","id":"test_user-ls-ls --color=auto","cgroup":"9:cpuset:/","machine_id":"a1e2ada5a5b1b273b4b5c0c2c1c4f5d1","uuid":"da845a9b-a55d-4c42-893d-08b54ee6e999"},"configuration":{"current":{"metric":{"enable":"true","transport":{"type":"udp","host":"127.0.0.1","port":"8125","tls":{"enable":"false","validateserver":"true","cacertpath":""}},"format":{"type":"statsd","statsdprefix":"","statsdmaxlen":512,"verbosity":4},"watch":[{"type":"fs"},{"type":"net"},{"type":"http"},{"type":"dns"},{"type":"process"},{"type":"statsd"}]},"libscope":{"log":{"level":"info","transport":{"type":"file","path":"/tmp/scope.log","buffering":"line"}},"snapshot":{"coredump":"false","backtrace":"false"},"configevent":"true","summaryperiod":10,"commanddir":"/tmp"},"event":{"enable":"true","transport":{"type":"tcp","host":"127.0.0.1","port":"9109","tls":{"enable":"false","validateserver":"true","cacertpath":""}},"format":{"type":"ndjson","maxeventpersec":10000,"enhancefs":"true"},"watch":[{"type":"file","name":"(\\/logs?\\/)|(\\.log$)|(\\.log[.\\d])","field":".*","value":".*"},{"type":"console","name":"(stdout)|(stderr)","field":".*","value":".*","allowbinary":"true"},{"type":"http","name":".*","field":".*","value":".*","headers":[]},{"type":"net","name":".*","field":".*","value":".*"},{"type":"fs","name":".*","field":".*","value":".*"},{"type":"dns","name":".*","field":".*","value":".*"}]},"payload":{"enable":"false","dir":"/tmp"},"tags":{},"protocol":[],"cribl":{"enable":"false","transport":{"type":"edge"},"authtoken":""}}},"environment":{}}}], + "examples": [{"format":"ndjson","info":{"process":{"libscopever":"v1.3.0","pid":35673,"ppid":3390,"gid":1000,"groupname":"test_user","uid":1000,"username":"test_user","hostname":"test_user","procname":"ls","cmd":"ls --color=auto","id":"test_user-ls-ls --color=auto","cgroup":"9:cpuset:/","machine_id":"a1e2ada5a5b1b273b4b5c0c2c1c4f5d1","uuid":"da845a9b-a55d-4c42-893d-08b54ee6e999"},"configuration":{"current":{"metric":{"enable":"true","transport":{"type":"udp","host":"127.0.0.1","port":"8125","tls":{"enable":"false","validateserver":"true","cacertpath":""}},"format":{"type":"statsd","statsdprefix":"","statsdmaxlen":512,"verbosity":4},"watch":[{"type":"fs"},{"type":"net"},{"type":"http"},{"type":"dns"},{"type":"process"},{"type":"statsd"}]},"libscope":{"log":{"level":"info","transport":{"type":"file","path":"/tmp/scope.log","buffering":"line"}},"snapshot":{"coredump":"false","backtrace":"false"},"configevent":"true","summaryperiod":10,"commanddir":"/tmp"},"event":{"enable":"true","transport":{"type":"tcp","host":"127.0.0.1","port":"9109","tls":{"enable":"false","validateserver":"true","cacertpath":""}},"format":{"type":"ndjson","maxeventpersec":10000,"enhancefs":"true"},"watch":[{"type":"file","name":"(\\/logs?\\/)|(\\.log$)|(\\.log[.\\d])","field":".*","value":".*"},{"type":"console","name":"(stdout)|(stderr)","field":".*","value":".*","allowbinary":"true"},{"type":"http","name":".*","field":".*","value":".*","headers":[]},{"type":"net","name":".*","field":".*","value":".*"},{"type":"fs","name":".*","field":".*","value":".*"},{"type":"dns","name":".*","field":".*","value":".*"}]},"payload":{"enable":"false","type":"dir","dir":"/tmp"},"tags":{},"protocol":[],"cribl":{"enable":"false","transport":{"type":"edge"},"authtoken":""}}},"environment":{}}}], "required": [ "format", "info" @@ -487,6 +487,9 @@ "enable": { "$ref": "definitions/data.schema.json#/$defs/enable" }, + "type": { + "$ref": "definitions/data.schema.json#/$defs/payload_type" + }, "dir": { "$ref": "definitions/data.schema.json#/$defs/dir" } diff --git a/src/cfg.c b/src/cfg.c index 9e9e550e7..96d2f8b63 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -65,6 +65,7 @@ struct _config_t struct { unsigned int enable; + bool dirEnable; // TODO: This should be modified if we decide for full transport support payload channel char *dir; } pay; @@ -230,6 +231,7 @@ cfgCreateDefault(void) c->log.level = DEFAULT_LOG_LEVEL; c->pay.enable = DEFAULT_PAYLOAD_ENABLE; + c->pay.dirEnable = DEFAULT_PAYLOAD_DIR_ENABLE; c->pay.dir = (DEFAULT_PAYLOAD_DIR) ? scope_strdup(DEFAULT_PAYLOAD_DIR) : NULL; c->tags = DEFAULT_CUSTOM_TAGS; @@ -622,6 +624,11 @@ cfgPayEnable(config_t *cfg) return (cfg) ? cfg->pay.enable : DEFAULT_PAYLOAD_ENABLE; } +unsigned int +cfgPayDirEnable(config_t *cfg) { + return (cfg) ? cfg->pay.dirEnable : DEFAULT_PAYLOAD_DIR_ENABLE; +} + const char * cfgPayDir(config_t *cfg) { @@ -1009,6 +1016,13 @@ cfgPayEnableSet(config_t *cfg, unsigned int val) cfg->pay.enable = val; } +void +cfgPayDirEnableSet(config_t *cfg, unsigned int val) +{ + if (!cfg || val > 1) return; + cfg->pay.dirEnable = val; +} + void cfgPayDirSet(config_t *cfg, const char *dir) { diff --git a/src/cfg.h b/src/cfg.h index 8ae8eda5a..ad0ce39de 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -45,6 +45,7 @@ custom_tag_t** cfgCustomTags(config_t*); const char* cfgCustomTagValue(config_t*, const char*); cfg_log_level_t cfgLogLevel(config_t*); unsigned int cfgPayEnable(config_t*); +unsigned int cfgPayDirEnable(config_t *); const char * cfgPayDir(config_t*); const char * cfgEvtFormatHeader(config_t *, int); unsigned cfgEvtAllowBinaryConsole(config_t *); @@ -85,6 +86,7 @@ void cfgTransportTlsCACertPathSet(config_t *, which_transport_t, void cfgCustomTagAdd(config_t*, const char*, const char*); void cfgLogLevelSet(config_t*, cfg_log_level_t); void cfgPayEnableSet(config_t*, unsigned int); +void cfgPayDirEnableSet(config_t *, unsigned int); void cfgPayDirSet(config_t*, const char *); void cfgEvtFormatHeaderSet(config_t *, const char *); void cfgEvtAllowBinaryConsoleSet(config_t *, unsigned); diff --git a/src/cfgutils.c b/src/cfgutils.c index 4bcd9ebfb..a5e840e2b 100644 --- a/src/cfgutils.c +++ b/src/cfgutils.c @@ -73,6 +73,7 @@ #define PAYLOAD_NODE "payload" #define ENABLE_NODE "enable" +#define TYPE_NODE "type" #define DIR_NODE "dir" #define CRIBL_NODE "cribl" @@ -167,6 +168,12 @@ enum_map_t boolMap[] = { {NULL, -1} }; +enum_map_t payTypeMap[] = { + {"dir", TRUE}, + {"event", FALSE}, + {NULL, -1} +}; + // forward declarations void cfgMtcEnableSetFromStr(config_t*, const char*); void cfgMtcFormatSetFromStr(config_t*, const char*); @@ -194,6 +201,7 @@ void cfgCustomTagAddFromStr(config_t*, const char*, const char*); void cfgLogLevelSetFromStr(config_t*, const char*); void cfgPayEnableSetFromStr(config_t*, const char*); void cfgPayDirSetFromStr(config_t*, const char*); +void cfgPayTypeSetFromStr(config_t *, const char *); void cfgAuthTokenSetFromStr(config_t*, const char*); void cfgEvtFormatHeaderSetFromStr(config_t *, const char *); void cfgCriblEnableSetFromStr(config_t *, const char *); @@ -530,6 +538,8 @@ processEnvStyleInput(config_t *cfg, const char *env_line) cfgTransportTlsCACertPathSetFromStr(cfg, CFG_LOG, value); } else if (!scope_strcmp(env_name, "SCOPE_PAYLOAD_ENABLE")) { cfgPayEnableSetFromStr(cfg, value); + } else if (!scope_strcmp(env_name, "SCOPE_PAYLOAD_DEST")) { + cfgPayTypeSetFromStr(cfg, value); } else if (!scope_strcmp(env_name, "SCOPE_PAYLOAD_DIR")) { cfgPayDirSetFromStr(cfg, value); } else if (!scope_strcmp(env_name, "SCOPE_CMD_DBG_PATH")) { @@ -957,6 +967,18 @@ cfgPayDirSetFromStr(config_t *cfg, const char *value) cfgPayDirSet(cfg, value); } +void +cfgPayTypeSetFromStr(config_t *cfg, const char *value) +{ + if (!cfg || !value) return; + // see if value equals "dir"/"event" + if (scope_strncmp(value, "event", C_STRLEN("event")) == 0) { + cfgPayDirEnableSet(cfg, FALSE); + } else if (scope_strncmp(value, "dir", C_STRLEN("dir")) == 0) { + cfgPayDirEnableSet(cfg, TRUE); + } +} + void cfgCriblEnableSetFromStr(config_t *cfg, const char *value) { @@ -1629,6 +1651,14 @@ processPayloadEnable(config_t *config, yaml_document_t *doc, yaml_node_t *node) if (value) scope_free(value); } +static void +processPayloadType(config_t *config, yaml_document_t *doc, yaml_node_t *node) +{ + char* value = stringVal(node); + cfgPayTypeSetFromStr(config, value); + if (value) scope_free(value); +} + static void processPayloadDir(config_t *config, yaml_document_t *doc, yaml_node_t *node) { @@ -1644,6 +1674,7 @@ processPayload(config_t *config, yaml_document_t *doc, yaml_node_t *node) parse_table_t t[] = { {YAML_SCALAR_NODE, ENABLE_NODE, processPayloadEnable}, + {YAML_SCALAR_NODE, TYPE_NODE, processPayloadType}, {YAML_SCALAR_NODE, DIR_NODE, processPayloadDir}, {YAML_NO_NODE, NULL, NULL} }; @@ -2560,6 +2591,8 @@ createPayloadJson(config_t *cfg) if (!cJSON_AddStringToObjLN(root, ENABLE_NODE, valToStr(boolMap, cfgPayEnable(cfg)))) goto err; + if (!cJSON_AddStringToObjLN(root, TYPE_NODE, + valToStr(payTypeMap, cfgPayDirEnable(cfg)))) goto err; if (!cJSON_AddStringToObjLN(root, DIR_NODE, cfgPayDir(cfg))) goto err; @@ -2863,8 +2896,13 @@ initCtl(config_t *cfg) */ payload_status_t payloadStatus = PAYLOAD_STATUS_DISABLE; if (cfgPayEnable(cfg) || protocolDefinitionsUsePayloads()) { - if (cfgLogStreamEnable(cfg) && !payloadToDiskForced() ) { - payloadStatus = PAYLOAD_STATUS_CRIBL; + bool payloadOnDisk = cfgPayDirEnable(cfg); + if (payloadOnDisk == FALSE) { + if (cfgLogStreamEnable(cfg)) { + payloadStatus = PAYLOAD_STATUS_CRIBL; + } else if (cfgEvtEnable(cfg)) { + payloadStatus = PAYLOAD_STATUS_CTL; + } } else { payloadStatus = PAYLOAD_STATUS_DISK; } diff --git a/src/ctl.c b/src/ctl.c index bd15be49b..b3e10b225 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -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); } diff --git a/src/ctl.h b/src/ctl.h index ed66e4803..fce3bc9aa 100644 --- a/src/ctl.h +++ b/src/ctl.h @@ -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; /** @@ -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); diff --git a/src/ipc_resp.c b/src/ipc_resp.c index 8dad11d61..91b5f5635 100644 --- a/src/ipc_resp.c +++ b/src/ipc_resp.c @@ -327,7 +327,7 @@ payloadTransportEnabled(void) { */ static transport_status_t payloadTransportStatus(void) { - return ctlConnectionStatus(g_ctl, CFG_LS); + return ctlPayloadConnectionStatus(g_ctl); } /* @@ -351,7 +351,7 @@ eventsTransportEnabled(void) { */ static transport_status_t eventsTransportStatus(void) { - return ctlConnectionStatus(g_ctl, CFG_CTL); + return ctlConnectionStatus(g_ctl); } /* diff --git a/src/report.c b/src/report.c index f0fc655c9..adaf7131a 100644 --- a/src/report.c +++ b/src/report.c @@ -3607,60 +3607,71 @@ doPayload() char *bdata = NULL; payload_status_t payStatus = ctlPayStatus(g_ctl); - if (payStatus == PAYLOAD_STATUS_CRIBL) { - bdata = scope_calloc(1, hlen + pinfo->len); - if (bdata) { - scope_memmove(bdata, pay, hlen); - scope_strncat(bdata, "\n", hlen); - scope_memmove(&bdata[hlen], pinfo->data, pinfo->len); - cmdSendPayload(g_ctl, bdata, hlen + pinfo->len); - } - } else if (payStatus == PAYLOAD_STATUS_DISK) { - int fd; - char path[PATH_MAX]; - - ///tmp//.in - switch (pinfo->src) { - case NETTX: - case TLSTX: - scope_snprintf(path, PATH_MAX, "%s/%d_%s:%s_%s:%s.out", - ctlPayDir(g_ctl), g_proc.pid, rip, rport, lip, lport); - break; - - case NETRX: - case TLSRX: - scope_snprintf(path, PATH_MAX, "%s/%d_%s:%s_%s:%s.in", - ctlPayDir(g_ctl), g_proc.pid, rip, rport, lip, lport); - break; - - default: - scope_snprintf(path, PATH_MAX, "%s/%d.na", - ctlPayDir(g_ctl), g_proc.pid); + switch (payStatus) { + case PAYLOAD_STATUS_CRIBL: + case PAYLOAD_STATUS_CTL: { + bdata = scope_calloc(1, hlen + pinfo->len); + if (bdata) { + scope_memmove(bdata, pay, hlen); + scope_strncat(bdata, "\n", hlen); + scope_memmove(&bdata[hlen], pinfo->data, pinfo->len); + cmdSendPayload(g_ctl, bdata, hlen + pinfo->len); + } break; } + case PAYLOAD_STATUS_DISK: { + int fd; + char path[PATH_MAX]; + + ///tmp//.in + switch (pinfo->src) { + case NETTX: + case TLSTX: + scope_snprintf(path, PATH_MAX, "%s/%d_%s:%s_%s:%s.out", + ctlPayDir(g_ctl), g_proc.pid, rip, rport, lip, lport); + break; - if ((fd = scope_open(path, O_WRONLY | O_CREAT | O_APPEND, 0666)) != -1) { - if (checkEnv("SCOPE_PAYLOAD_HEADER", "true")) { - scope_write(fd, pay, rc); + case NETRX: + case TLSRX: + scope_snprintf(path, PATH_MAX, "%s/%d_%s:%s_%s:%s.in", + ctlPayDir(g_ctl), g_proc.pid, rip, rport, lip, lport); + break; + + default: + scope_snprintf(path, PATH_MAX, "%s/%d.na", + ctlPayDir(g_ctl), g_proc.pid); + break; } - size_t to_write = pinfo->len; - size_t written = 0; - int rc; + if ((fd = scope_open(path, O_WRONLY | O_CREAT | O_APPEND, 0666)) != -1) { + if (checkEnv("SCOPE_PAYLOAD_HEADER", "true")) { + scope_write(fd, pay, rc); + } - while (to_write > 0) { - rc = scope_write(fd, &pinfo->data[written], to_write); - if (rc <= 0) { - DBG(NULL); - break; + size_t to_write = pinfo->len; + size_t written = 0; + int rc; + + while (to_write > 0) { + rc = scope_write(fd, &pinfo->data[written], to_write); + if (rc <= 0) { + DBG(NULL); + break; + } + + written += rc; + to_write -= rc; } - written += rc; - to_write -= rc; + scope_close(fd); } - - scope_close(fd); + break; } + case PAYLOAD_STATUS_DISABLE: + break; + default: + DBG(NULL); + break; } if (bdata) scope_free(bdata); diff --git a/src/scopetypes.h b/src/scopetypes.h index c808aa9e2..90e8cc2e1 100644 --- a/src/scopetypes.h +++ b/src/scopetypes.h @@ -158,6 +158,7 @@ typedef struct #define DEFAULT_METRIC_CBUF_SIZE 50 * 1024 #define DEFAULT_PROCESS_START_MSG TRUE #define DEFAULT_PAYLOAD_ENABLE FALSE +#define DEFAULT_PAYLOAD_DIR_ENABLE TRUE #define DEFAULT_PAYLOAD_DIR "/tmp" #define DEFAULT_PAYLOAD_DIR_REPR "dir:///tmp" @@ -221,7 +222,6 @@ typedef struct // SCOPE_SWITCH for internal go debugging // SCOPE_PID provided by library // SCOPE_PAYLOAD_HEADER write payload headers to files -// SCOPE_PAYLOAD_TO_DISK if payloads are enabled, "true" forces writes to payload->dir // SCOPE_ALLOW_CONSTRUCT_DBG allows debug inside the constructor // SCOPE_QUEUE_LENGTH override default circular buffer sizes // SCOPE_START_NOPROFILE cause the start command to ignore updates to /etc/profile.d @@ -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 diff --git a/src/state.c b/src/state.c index 2126f287f..cd2a24717 100644 --- a/src/state.c +++ b/src/state.c @@ -77,18 +77,6 @@ list_t *g_extra_net_info_list = NULL; #define DURATION_FIELD(val) NUMFIELD("duration", (val), 8) #define NUMOPS_FIELD(val) NUMFIELD("numops", (val), 8) -static bool g_force_payloads_to_disk = FALSE; - -void -setPayloadToDiskForced(bool val) { - g_force_payloads_to_disk = val; -} - -bool -payloadToDiskForced(void) { - return g_force_payloads_to_disk; -} - static void destroyNetInfo(void *data) { @@ -313,9 +301,6 @@ initState(void) initHttpState(); initMetricCapture(); - // Some environment variables we don't want to continuously check - setPayloadToDiskForced(checkEnv(SCOPE_PAYLOAD_TO_DISK_ENV, "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 scope_memset(g_http_guard, 0, sizeof(g_http_guard)); diff --git a/src/state.h b/src/state.h index 8ae9986f1..b0ae84c69 100644 --- a/src/state.h +++ b/src/state.h @@ -39,8 +39,6 @@ void initState(void); void resetState(void); void destroyState(void); -void setPayloadToDiskForced(bool); -bool payloadToDiskForced(void); void setVerbosity(unsigned); void addSock(int, int, int); int doBlockConnection(int, const struct sockaddr *); diff --git a/src/wrap.c b/src/wrap.c index bb962aa40..5b14f2863 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -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"); diff --git a/test/integration/cli/test_inspect.sh b/test/integration/cli/test_inspect.sh index 9d6d36423..97a456fb9 100755 --- a/test/integration/cli/test_inspect.sh +++ b/test/integration/cli/test_inspect.sh @@ -258,7 +258,7 @@ endtest # enabled cribl, payload_to_disk enable, expected to see log, events, metrics starttest test_inspect_cribl_enable_payload_disable -SCOPE_PAYLOAD_TO_DISK=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null & +SCOPE_PAYLOAD_DEST="dir" LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null & sleep 2 PYTHON_PID=`pidof python3` @@ -280,7 +280,7 @@ starttest test_inspect_cribl_enable_payload_enable PRE_SCOPE_CRIBL_ENABLE=$SCOPE_CRIBL_ENABLE unset SCOPE_CRIBL_ENABLE -SCOPE_PAYLOAD_ENABLE=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null & +SCOPE_PAYLOAD_DEST="event" SCOPE_PAYLOAD_ENABLE=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null & export SCOPE_CRIBL_ENABLE=$PRE_SCOPE_CRIBL_ENABLE sleep 2 PYTHON_PID=`pidof python3` @@ -305,7 +305,7 @@ starttest test_inspect_cribl_enable_payload_enable_payload_to_disk_enable PRE_SCOPE_CRIBL_ENABLE=$SCOPE_CRIBL_ENABLE unset SCOPE_CRIBL_ENABLE -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 & +SCOPE_PAYLOAD_DEST="dir" SCOPE_PAYLOAD_ENABLE=true LD_PRELOAD=/usr/local/scope/lib/libscope.so python3 -m http.server 1> /dev/null 2> /dev/null & export SCOPE_CRIBL_ENABLE=$PRE_SCOPE_CRIBL_ENABLE sleep 2 PYTHON_PID=`pidof python3` diff --git a/test/integration/payload/scope-test b/test/integration/payload/scope-test index 7f173e071..2b94aa9e4 100755 --- a/test/integration/payload/scope-test +++ b/test/integration/payload/scope-test @@ -62,11 +62,11 @@ get_file_count_with_extension() { # # This test was written to test that the payload feature creates .in and -# .out files to disk when we expect them. Generally, if the payload -# feature is off or payloads are routed to cribl, then we don't expect -# payloads to be written to disk. The only exception: if -# payloads are routed to cribl and SCOPE_PAYLOAD_TO_DISK=true, -# then we expect payloads to be written to disk. +# .out files to disk when we expect them. +# The payload redirection: +# - by default they are redirected to disk +# - "SCOPE_PAYLOAD_DEST" or "--payloaddest" allows to redirect the +# payloads to same destination as defined in event transport. # # At this time, we're not testing the *contents* of the payload files, # or the names of the files, just the existance of them. @@ -87,10 +87,10 @@ endtest starttest payload_off_2 echo "When the payload feature is off, verify that no payload files are" -echo " written to disk, even if SCOPE_PAYLOAD_TO_DISK=true" +echo " written to disk, even if SCOPE_PAYLOAD_DEST=dir" SCOPE_PAYLOAD_ENABLE=false \ SCOPE_CRIBL_ENABLE=true \ -SCOPE_PAYLOAD_TO_DISK=true \ +SCOPE_PAYLOAD_DEST="dir" \ scope run -- curl -Lso /dev/null https://cribl.io FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l) if (( $FILE_COUNT > 0 )); then @@ -100,11 +100,12 @@ cleanup endtest starttest payload_on_to_cribl -echo "When the payload feature is on, and SCOPE_CRIBL_ENABLE=true, verify no" +echo "When the payload feature is on, SCOPE_PAYLOAD_DEST=event and SCOPE_CRIBL_ENABLE=true, verify no" echo " payloads are written to disk (they are sent over the cribl" echo " connection)" SCOPE_PAYLOAD_ENABLE=true \ SCOPE_CRIBL_ENABLE=true \ +SCOPE_PAYLOAD_DEST="event" \ scope run -- curl -Lso /dev/null https://cribl.io FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l) if (( $FILE_COUNT > 0 )); then @@ -115,15 +116,16 @@ endtest starttest payload_on_to_cribl_but_overridden_to_disk echo "When the payload feature is on, and SCOPE_CRIBL_ENABLE=true, verify" -echo " payloads are written to disk if SCOPE_PAYLOAD_TO_DISK=true" +echo " payloads are written to disk if SCOPE_PAYLOAD_DEST=dir" SCOPE_PAYLOAD_ENABLE=true \ SCOPE_CRIBL_ENABLE=true \ -SCOPE_PAYLOAD_TO_DISK=true \ +SCOPE_PAYLOAD_DEST="dir" \ 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_1 @@ -137,15 +139,16 @@ 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 " payloads are written to disk even if SCOPE_PAYLOAD_TO_DISK=false." +echo " payloads are written to disk even if SCOPE_PAYLOAD_DEST=dir." echo " Payloads always go to disk if SCOPE_CRIBL_ENABLE=false" SCOPE_PAYLOAD_ENABLE=true \ SCOPE_CRIBL_ENABLE=false \ -SCOPE_PAYLOAD_TO_DISK=false \ +SCOPE_PAYLOAD_DEST="dir" \ scope run -- curl -Lso /dev/null https://cribl.io FILE_COUNT=$(compgen -G "$SCOPE_PAYLOAD_DIR/*\.out" | wc -l) if (( $FILE_COUNT == 0 )); then @@ -159,6 +162,7 @@ endtest starttest payload_host_app SCOPE_PAYLOAD_ENABLE=true \ SCOPE_CRIBL_ENABLE=false \ +SCOPE_PAYLOAD_DEST="dir" \ 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") diff --git a/test/integration/transport/scope-test b/test/integration/transport/scope-test index 664254be5..e44eda2e2 100755 --- a/test/integration/transport/scope-test +++ b/test/integration/transport/scope-test @@ -188,9 +188,9 @@ if [ "$(wait_for_port 12345)" ]; then echo "When in cribl mode, verify there is only one connections when:" echo " 1) SCOPE_PAYLOAD_ENABLE=true" echo " 2) no protocols are defined" - echo " 3) SCOPE_PAYLOAD_TO_DISK=true" + echo " 3) SCOPE_PAYLOAD_DEST=dest" SCOPE_PAYLOAD_ENABLE=true \ - SCOPE_PAYLOAD_TO_DISK=true \ + SCOPE_PAYLOAD_DEST="dest" \ SCOPE_CRIBL_TLS_CA_CERT_PATH=/tmp/appscope.crt \ scope run -c tls://127.0.0.1:12345 -- /bin/sleep 3 & sleep 1 @@ -208,7 +208,7 @@ if [ "$(wait_for_port 12345)" ]; then echo "When in cribl mode, verify there are two connections when:" echo " 1) SCOPE_PAYLOAD_ENABLE=true" echo " 2) no protocols are defined" - echo " 3) SCOPE_PAYLOAD_TO_DISK is not defined" + echo " 3) SCOPE_PAYLOAD_DEST is not defined" SCOPE_PAYLOAD_ENABLE=true \ SCOPE_CRIBL_TLS_CA_CERT_PATH=/tmp/appscope.crt \ scope run -c tls://127.0.0.1:12345 -- /bin/sleep 3 & @@ -227,7 +227,7 @@ if [ "$(wait_for_port 12345)" ]; then echo "When in cribl mode, verify there are two connections when:" echo " 1) SCOPE_PAYLOAD_ENABLE=false" echo " 2) a protocol has set payload: true" - echo " 3) SCOPE_PAYLOAD_TO_DISK is false" + echo " 3) SCOPE_PAYLOAD_DEST is event" # I'm switching to controlling things with a config file just # because the scope cli doesn't have a way to specify protocol @@ -251,7 +251,7 @@ if [ "$(wait_for_port 12345)" ]; then echo " regex: .*" >> $CFG_FILE echo " payload: true" >> $CFG_FILE - SCOPE_PAYLOAD_TO_DISK=false \ + SCOPE_PAYLOAD_DEST="event" \ scope run -u $CFG_FILE -- /bin/sleep 3 & sleep 1 CON_COUNT=$(lsof -p `pidof sleep` | grep -c 12345) diff --git a/test/manual/fluentbit/services/nginx/config/scope.yml b/test/manual/fluentbit/services/nginx/config/scope.yml index 3b9b1c6db..f08f02bcb 100644 --- a/test/manual/fluentbit/services/nginx/config/scope.yml +++ b/test/manual/fluentbit/services/nginx/config/scope.yml @@ -531,6 +531,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -539,6 +552,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting the the library diff --git a/test/manual/payload/conf_1/scope.yml b/test/manual/payload/conf_1/scope.yml index fc285c7fa..c02e6d9fe 100644 --- a/test/manual/payload/conf_1/scope.yml +++ b/test/manual/payload/conf_1/scope.yml @@ -530,6 +530,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -538,6 +551,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting the the library diff --git a/test/manual/payload/conf_2/scope.yml b/test/manual/payload/conf_2/scope.yml index a9076a31e..e990b02f5 100644 --- a/test/manual/payload/conf_2/scope.yml +++ b/test/manual/payload/conf_2/scope.yml @@ -530,6 +530,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -538,6 +551,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting the the library diff --git a/test/manual/payload/conf_3/scope.yml b/test/manual/payload/conf_3/scope.yml index fc285c7fa..c02e6d9fe 100644 --- a/test/manual/payload/conf_3/scope.yml +++ b/test/manual/payload/conf_3/scope.yml @@ -530,6 +530,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -538,6 +551,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting the the library diff --git a/test/manual/send_event/conf_1/scope.yml b/test/manual/send_event/conf_1/scope.yml index 536194964..338649e4a 100644 --- a/test/manual/send_event/conf_1/scope.yml +++ b/test/manual/send_event/conf_1/scope.yml @@ -530,6 +530,19 @@ payload: # enable: false + # Determine the payload type destination + # Type: string + # Values: "dir", "event" + # Default: "dir" + # Override: $SCOPE_PAYLOAD_DEST + # + # + # This allows to specify the payload destination + # - "event" allows to send the payloads to same location as events + # - "dir" allows to use directory to store payload files + # + type: "dir" + # Directory for payload files # Type: string # Values: (directory path) @@ -538,6 +551,8 @@ payload: # # Consider using a performant filesystem to reduce I/O performance impacts. # + # Applies when dest is "dir". + # dir: '/tmp' # Setting the the library diff --git a/test/unit/library/cfgutilstest.c b/test/unit/library/cfgutilstest.c index 648150f11..5f0265d13 100644 --- a/test/unit/library/cfgutilstest.c +++ b/test/unit/library/cfgutilstest.c @@ -815,6 +815,37 @@ cfgProcessEnvironmentPayEnable(void **state) cfgProcessEnvironment(cfg); } +static void +cfgProcessEnvironmentPayType(void **state) +{ + config_t *cfg = cfgCreateDefault(); + cfgPayDirEnableSet(cfg, FALSE); + assert_int_equal(cfgPayDirEnable(cfg), FALSE); + + // should override current cfg + assert_int_equal(setenv("SCOPE_PAYLOAD_DEST", "dir", 1), 0); + cfgProcessEnvironment(cfg); + assert_int_equal(cfgPayDirEnable(cfg), TRUE); + + assert_int_equal(setenv("SCOPE_PAYLOAD_DEST", "event", 1), 0); + cfgProcessEnvironment(cfg); + assert_int_equal(cfgPayDirEnable(cfg), FALSE); + + // if env is not defined, cfg should not be affected + assert_int_equal(unsetenv("SCOPE_PAYLOAD_DEST"), 0); + cfgProcessEnvironment(cfg); + assert_int_equal(cfgPayDirEnable(cfg), FALSE); + + // unrecognised value should not affect cfg + assert_int_equal(setenv("SCOPE_PAYLOAD_DEST", "blah", 1), 0); + cfgProcessEnvironment(cfg); + assert_int_equal(cfgPayEnable(cfg), FALSE); + + // Just don't crash on null cfg + cfgDestroy(&cfg); + cfgProcessEnvironment(cfg); +} + static void cfgProcessEnvironmentPayDir(void **state) { @@ -3047,6 +3078,7 @@ main(int argc, char *argv[]) cmocka_unit_test_prestate(cfgProcessEnvironmentTransport, &dest_log), cmocka_unit_test(cfgProcessEnvironmentStatsdTags), cmocka_unit_test(cfgProcessEnvironmentPayEnable), + cmocka_unit_test(cfgProcessEnvironmentPayType), cmocka_unit_test(cfgProcessEnvironmentPayDir), cmocka_unit_test(cfgProcessEnvironmentCmdDebugIsIgnored), cmocka_unit_test(cfgProcessCommandsCmdDebugIsProcessed), diff --git a/website/src/pages/docs/cli-reference.md b/website/src/pages/docs/cli-reference.md index b59395492..38e1d1903 100644 --- a/website/src/pages/docs/cli-reference.md +++ b/website/src/pages/docs/cli-reference.md @@ -117,6 +117,7 @@ scope attach --payloads 2000 --metricprefix string Set prefix for StatsD metrics, ignored if metric format isn't statsd -n, --nobreaker Set Cribl to not break streams into events. -p, --payloads Capture payloads of network transactions + --payloadsdest string Set destination for payloads (dir|event) (default "dir") -R, --rootdir Path to root filesystem of target namespace -u, --userconfig string Scope an application with a user specified config file; overrides all other settings. -v, --verbosity int Set scope metric verbosity (default 4) @@ -316,6 +317,7 @@ scope rules --remove chromium --metricformat string Set format of metrics output (statsd|ndjson|prometheus) (default "ndjson") -n, --nobreaker Set Cribl to not break streams into events. -p, --payloads Capture payloads of network transactions + --payloadsdest string Set destination for payloads (dir|event) (default "dir") --remove string Remove an entry from the global rules -R, --rootdir string Path to root filesystem of target namespace --source string Source identifier for a rules entry @@ -630,6 +632,7 @@ scope run -c edge -- top --metricprefix string Set prefix for StatsD metrics, ignored if metric format isn't statsd -n, --nobreaker Set Cribl to not break streams into events. -p, --payloads Capture payloads of network transactions + --payloadsdest string Set destination for payloads (dir|event) (default "dir") -u, --userconfig string Scope an application with a user specified config file; overrides all other settings. -v, --verbosity int Set scope metric verbosity (default 4) ``` @@ -822,6 +825,7 @@ scope watch --interval=10s -- curl https://wttr.in/94105 --metricprefix string Set prefix for StatsD metrics, ignored if metric format isn't statsd -n, --nobreaker Set Cribl to not break streams into events. -p, --payloads Capture payloads of network transactions + --payloadsdest string Set destination for payloads (dir|event) (default "dir") -u, --userconfig string Scope an application with a user specified config file; overrides all other settings. -v, --verbosity int Set scope metric verbosity (default 4) ``` diff --git a/website/src/pages/docs/cli-using.md b/website/src/pages/docs/cli-using.md index 2bd8ee455..642b5d8cf 100644 --- a/website/src/pages/docs/cli-using.md +++ b/website/src/pages/docs/cli-using.md @@ -169,7 +169,7 @@ No events are emitted from files or sockets that exist before AppScope attaches When you scope an app that produces HTTP traffic, you can capture the payloads using the `-p` or `--payloads` option. This is AppScope's **payloads** feature (see the `payload` section in the AppScope [config file](/docs/config)), which is disabled by default, because it can create large amounts of data, and because it captures payloads unencrypted. -When the **payloads** feature is enabled, setting `SCOPE_PAYLOAD_TO_DISK` to `true` guarantees that AppScope will write payloads to the local directory specified in `SCOPE_PAYLOAD_DIR`. +When the **payloads** feature is enabled, setting `SCOPE_PAYLOAD_DEST` to `dir` guarantees that AppScope will write payloads to the local directory specified in `SCOPE_PAYLOAD_DIR`.