/** * Callback function to use with INI-H. * @arg user Opaque user value. We use the statsite_config pointer * @arg section The INI seciton * @arg name The config name * @arg value The config value * @return 1 on success. */ static int config_callback(void* user, const char* section, const char* name, const char* value) { // Specially handle histogram sections if (strncasecmp("histogram", section, 9) == 0) { return histogram_callback(user, section, name, value); } // Ignore any non-statsite sections if (strcasecmp("statsite", section) != 0) { return 0; } // Cast the user handle statsite_config *config = (statsite_config*)user; // Switch on the config #define NAME_MATCH(param) (strcasecmp(param, name) == 0) // Handle the int cases if (NAME_MATCH("port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("tcp_port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("udp_port")) { return value_to_int(value, &config->udp_port); } else if (NAME_MATCH("flush_interval")) { return value_to_int(value, &config->flush_interval); } else if (NAME_MATCH("daemonize")) { return value_to_bool(value, &config->daemonize); } else if (NAME_MATCH("binary_stream")) { return value_to_bool(value, &config->binary_stream); // Handle the double cases } else if (NAME_MATCH("timer_eps")) { return value_to_double(value, &config->timer_eps); } else if (NAME_MATCH("set_eps")) { return value_to_double(value, &config->set_eps); // Copy the string values } else if (NAME_MATCH("log_level")) { config->log_level = strdup(value); } else if (NAME_MATCH("stream_cmd")) { config->stream_cmd = strdup(value); } else if (NAME_MATCH("pid_file")) { config->pid_file = strdup(value); } else if (NAME_MATCH("input_counter")) { config->input_counter = strdup(value); } else if (NAME_MATCH("bind_address")) { config->bind_address = strdup(value); // Unknown parameter? } else { // Log it, but ignore syslog(LOG_NOTICE, "Unrecognized config parameter: %s", value); } // Success return 1; }
/** * Callback function to use with INIH for parsing histogram configs * @arg user Opaque value. Actually a statsite_config pointer * @arg name The config name * @value = The config value * @return 1 on success */ static int histogram_callback(void* user, const char* section, const char* name, const char* value) { // Make sure we don't change sections with an unfinished config if (in_progress && strcasecmp(histogram_section, section)) { syslog(LOG_WARNING, "Unfinished configuration for section: %s", histogram_section); return 0; } // Ensure we have something in progress if (!in_progress) { in_progress = calloc(1, sizeof(histogram_config)); histogram_section = strdup(section); } // Cast the user handle statsite_config *config = (statsite_config*)user; // Switch on the config #define NAME_MATCH(param) (strcasecmp(param, name) == 0) int res = 1; if (NAME_MATCH("prefix")) { in_progress->parts |= 1; in_progress->prefix = strdup(value); } else if (NAME_MATCH("min")) { in_progress->parts |= 1 << 1; res = value_to_double(value, &in_progress->min_val); } else if (NAME_MATCH("max")) { in_progress->parts |= 1 << 2; res = value_to_double(value, &in_progress->max_val); } else if (NAME_MATCH("width")) { in_progress->parts |= 1 << 3; res = value_to_double(value, &in_progress->bin_width); } else { syslog(LOG_NOTICE, "Unrecognized histogram config parameter: %s", value); } // Check if this config is done, and push into the list of configs if (in_progress->parts == 15) { in_progress->next = config->hist_configs; config->hist_configs = in_progress; in_progress = NULL; free(histogram_section); histogram_section = NULL; } return res; }
/** * Callback function to use with INI-H. * @arg user Opaque user value. We use the statsite_config pointer * @arg section The INI seciton * @arg name The config name * @arg value The config value * @return 1 on success. */ static int config_callback(void* user, const char* section, const char* name, const char* value) { // Specially handle histogram sections if (strncasecmp("histogram", section, 9) == 0) { return histogram_callback(user, section, name, value); } if (strncasecmp("sink", section, 4) == 0) { return sink_callback(user, section, name, value); } // Ignore any non-statsite sections if (strcasecmp("statsite", section) != 0) { syslog(LOG_NOTICE, "Unknown values in section ignored: %s", section); return 0; } // Cast the user handle statsite_config *config = (statsite_config*)user; // Handle the int cases if (NAME_MATCH("port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("tcp_port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("udp_port")) { return value_to_int(value, &config->udp_port); } else if (NAME_MATCH("flush_interval")) { return value_to_int(value, &config->flush_interval); } else if (NAME_MATCH("parse_stdin")) { return value_to_bool(value, &config->parse_stdin); } else if (NAME_MATCH("daemonize")) { return value_to_bool(value, &config->daemonize); } else if (NAME_MATCH("use_type_prefix")) { return value_to_bool(value, &config->use_type_prefix); } else if (NAME_MATCH("extended_counters")) { return value_to_bool(value, &config->extended_counters); } else if (NAME_MATCH("prefix_binary_stream")) { return value_to_bool(value, &config->prefix_binary_stream); // Handle the double cases } else if (NAME_MATCH("timer_eps")) { return value_to_double(value, &config->timer_eps); } else if (NAME_MATCH("set_eps")) { return value_to_double(value, &config->set_eps); // Handle quantiles as a comma-separated list of doubles } else if (NAME_MATCH("quantiles")) { return value_to_list_of_doubles(value, &config->quantiles, &config->num_quantiles); // Copy the string values } else if (NAME_MATCH("log_level")) { config->log_level = strdup(value); } else if (NAME_MATCH("log_facility")) { config->log_facility = strdup(value); } else if (NAME_MATCH("pid_file")) { config->pid_file = strdup(value); } else if (NAME_MATCH("input_counter")) { config->input_counter = strdup(value); } else if (NAME_MATCH("bind_address")) { config->bind_address = strdup(value); } else if (NAME_MATCH("global_prefix")) { config->global_prefix = strdup(value); } else if (NAME_MATCH("counts_prefix")) { config->prefixes[COUNTER] = strdup(value); } else if (NAME_MATCH("gauges_prefix")) { config->prefixes[GAUGE] = strdup(value); } else if (NAME_MATCH("timers_prefix")) { config->prefixes[TIMER] = strdup(value); } else if (NAME_MATCH("sets_prefix")) { config->prefixes[SET] = strdup(value); } else if (NAME_MATCH("kv_prefix")) { config->prefixes[KEY_VAL] = strdup(value); // Copy the multi-case variables } else if (NAME_MATCH("log_facility")) { return name_to_facility(value, &config->syslog_log_facility); // Unknown parameter? } else { // Log it, but ignore syslog(LOG_NOTICE, "Unrecognized config parameter: %s", name); } // Success return 1; }
/** * Callback function to use with INI-H. * @arg user Opaque user value. We use the hlld_config pointer * @arg section The INI seciton * @arg name The config name * @arg value The config value * @return 1 on success. */ static int config_callback(void* user, const char* section, const char* name, const char* value) { // Ignore any non-hlld sections if (strcasecmp("hlld", section) != 0) { return 0; } // Cast the user handle hlld_config *config = (hlld_config*)user; // Switch on the config #define NAME_MATCH(param) (strcasecmp(param, name) == 0) // Handle the int cases if (NAME_MATCH("port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("tcp_port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("udp_port")) { return value_to_int(value, &config->udp_port); } else if (NAME_MATCH("flush_interval")) { return value_to_int(value, &config->flush_interval); } else if (NAME_MATCH("cold_interval")) { return value_to_int(value, &config->cold_interval); } else if (NAME_MATCH("in_memory")) { return value_to_int(value, &config->in_memory); } else if (NAME_MATCH("use_mmap")) { return value_to_int(value, &config->use_mmap); } else if (NAME_MATCH("workers")) { return value_to_int(value, &config->worker_threads); } else if (NAME_MATCH("default_precision")) { int res = value_to_int(value, &config->default_precision); // Compute expected error given precision config->default_eps = hll_error_for_precision(config->default_precision); return res; // Handle the double cases } else if (NAME_MATCH("default_eps")) { int res = value_to_double(value, &config->default_eps); // Compute required precision given error config->default_precision = hll_precision_for_error(config->default_eps); // Compute error given precision. This is kinda strange but it is done // since its not possible to hit all epsilons perfectly, but we try to get // the eps provided to be the upper bound. This value is the actual eps. config->default_eps = hll_error_for_precision(config->default_precision); return res; // Copy the string values } else if (NAME_MATCH("data_dir")) { config->data_dir = strdup(value); } else if (NAME_MATCH("log_level")) { config->log_level = strdup(value); // Unknown parameter? } else { // Log it, but ignore syslog(LOG_NOTICE, "Unrecognized config parameter: %s", value); } // Success return 1; }
yu_alloc_ctx_free(&mctx); #define LIST_VALUE_TESTS(X) \ X(double, "Doubles can be stored inline") \ X(fixnum, "Small ints can be stored inline") \ X(bool, "Booleans can be stored inline") \ X(ptr, "Boxed values should be heap-allocated and a pointer stored") \ X(value_type, "Value type should be not depend on whether or not the value is boxed") \ X(gray_bit, "Boxed values should maintain a gray bit") \ X(hash, "Value hashes should be well-distributed") \ X(hash_tuple, "Hashes from equal tuples should be equal") \ X(equal, "Only equal values should be equal") TEST(double) value_t x = value_from_double(42.101010); PT_ASSERT_EQ(value_to_double(x), 42.101010); END(double) TEST(fixnum) value_t x = value_from_int(322); PT_ASSERT_EQ(value_to_int(x), 322); END(fixnum) TEST(bool) value_t x = value_true(); PT_ASSERT(value_to_bool(x)); x = value_false(); PT_ASSERT(!value_to_bool(x)); END(bool) TEST(ptr)