Changeset 37e31fd9f0e6a806307056bdfcd2f642317d283f

Show
Ignore:
Timestamp:
07/07/11 05:49:06 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1310017746 -0400
git-parent:

[5ffe3ebc271cae0acdd3e485d0291e190b82578d]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1310017746 -0400
Message:

make the protobuf stuff consitent with the S/M record leaders.
fix up some code here and there.
extract the encapsulation into a helper file as we'll need it in
stratcond. Implement a de-encapsulation method.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    r17461d6 r37e31fd  
    6767        noit_console.o noit_console_state.o noit_console_telnet.o \ 
    6868        noit_console_complete.o noit_check_resolver.o \ 
    69         noit_check_tools_shared.o
     69        noit_check_tools_shared.o noit_check_log_helpers.o
    7070        noit_check.o noit_check_log.o noit_check_tools.o \ 
    7171        noit_module.o noit_conf.o noit_conf_checks.o noit_tokenizer.o \ 
     
    8484        noit_conf.o noit_http.o noit_rest.o noit_tokenizer.o \ 
    8585        noit_capabilities_listener.o noit_module.o \ 
    86         noit_check_tools_shared.o
     86        noit_check_tools_shared.o noit_check_log_helpers.o
    8787        stratcon_realtime_http.o \ 
    8888        stratcon_jlog_streamer.o stratcon_datastore.o \ 
  • src/noit_check_log.c

    r5ffe3eb r37e31fd  
    4242 
    4343#include "bundle.pb-c.h" 
    44 #include <zlib.h> 
    45 #include "utils/noit_b64.h" 
     44#include "noit_check_log_helpers.h" 
    4645 
    4746/* Log format is tab delimited: 
     
    316315 
    317316static int 
    318 _noit_check_compress_b64(char *buf_in, 
    319                          uLong len_in, 
    320                          char ** buf_out, 
    321                          uLong * len_out) { 
    322   uLong initial_dlen, dlen; 
    323   char *compbuff, *b64buff; 
    324  
    325   // Compress saves 25% of space (ex 470 -> 330) 
    326   if (use_compression) { 
    327     /* Compress */ 
    328     initial_dlen = dlen = compressBound(len_in); 
    329     compbuff = malloc(initial_dlen); 
    330     if(!compbuff) return -1; 
    331     if(Z_OK != compress2((Bytef *)compbuff, &dlen, 
    332                          (Bytef *)buf_in, len_in, 9)) { 
    333       noitL(noit_error, "Error compressing bundled metrics.\n"); 
    334       free(compbuff); 
    335       return -1; 
    336     } 
    337   } else { 
    338     // Or don't 
    339     dlen = len_in; 
    340     compbuff = buf_in; 
    341   } 
    342  
    343   /* Encode */ 
    344   // Problems with the calculation? 
    345   initial_dlen = ((dlen + 2) / 3 * 4); 
    346   b64buff = malloc(initial_dlen); 
    347   if (!b64buff) { 
    348     if (use_compression) { 
    349       // Free only if we malloc'd 
    350       free(compbuff); 
    351     } 
    352     return -1; 
    353   } 
    354   dlen = noit_b64_encode((unsigned char *)compbuff, dlen, 
    355                          (char *)b64buff, initial_dlen); 
    356   if (use_compression) { 
    357     // Free only if we malloc'd 
    358     free(compbuff); 
    359   } 
    360   if(dlen == 0) { 
    361     noitL(noit_error, "Error base64'ing bundled metrics.\n"); 
    362     free(b64buff); 
    363     return -1; 
    364   } 
    365   *buf_out = b64buff; 
    366   *len_out = dlen; 
    367   return 0; 
    368 } 
    369  
    370  
    371 static int 
    372317_noit_check_log_bundle_serialize(noit_log_stream_t ls, noit_check_t *check) { 
    373318  int rv = 0; 
     
    377322  const char *key; 
    378323  int klen, i=0, size, j; 
    379   uLong out_size; 
     324  unsigned int out_size; 
    380325  stats_t *c; 
    381326  void *vm; 
    382327  char *buf, *out_buf; 
     328  noit_compression_type_t comp; 
    383329  Bundle bundle = BUNDLE__INIT; 
    384330  SETUP_LOG(bundle, ); 
     
    417363 
    418364  // Compress + B64 
    419   _noit_check_compress_b64(buf, size, &out_buf, &out_size); 
     365  comp = use_compression ? NOIT_COMPRESS_ZLIB : NOIT_COMPRESS_NONE; 
     366  noit_check_log_bundle_compress_b64(comp, buf, size, &out_buf, &out_size); 
    420367  noit_log(ls, &(c->whence), __FILE__, __LINE__, 
    421            "B%c\t%lu.%03lu\t%s\t%s\t%s\t%s\t%.*s\n", 
     368           "B%c\t%lu.%03lu\t%s\t%s\t%s\t%s\t%d\t%.*s\n", 
    422369           use_compression ? '1' : '2', 
    423370           SECPART(&(c->whence)), MSECPART(&(c->whence)), 
    424            uuid_str, check->name, check->module, check->target
     371           uuid_str, check->target, check->module, check->name, size
    425372           (unsigned int)out_size, out_buf); 
    426373