Changeset e437d462c935dbd146a664ca0f0119405bf487dc

Show
Ignore:
Timestamp:
08/10/11 17:31:46 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1312997506 -0400
git-parent:

[f91ddca09660d8415b1bcdd88b20946e82b0ef62]

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

Expose the cause of an oncheck fire into lua

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua.c

    rf91ddca re437d46  
    249249} 
    250250static int 
     251noit_lua_get_available(lua_State *L) { 
     252  char av[2] = { '\0', '\0' }; 
     253  noit_check_t *check; 
     254  noit_lua_check_info_t *ci; 
     255  if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 
     256  check = lua_touserdata(L, lua_upvalueindex(1)); 
     257  av[0] = (char)check->stats.current.available; 
     258  lua_pushstring(L, av); 
     259  return 1; 
     260} 
     261static int 
    251262noit_lua_set_available(lua_State *L) { 
    252263  noit_check_t *check; 
     
    257268  ci->current.available = lua_tointeger(L, lua_upvalueindex(2)); 
    258269  return 0; 
     270} 
     271static int 
     272noit_lua_get_state(lua_State *L) { 
     273  char status[2] = { '\0', '\0' }; 
     274  noit_check_t *check; 
     275  noit_lua_check_info_t *ci; 
     276  if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 
     277  check = lua_touserdata(L, lua_upvalueindex(1)); 
     278  status[0] = (char)check->stats.current.state; 
     279  lua_pushstring(L, status); 
     280  return 1; 
    259281} 
    260282static int 
     
    373395        lua_pushcclosure(L, noit_lua_set_available, 2); 
    374396      } 
     397      else if(!strcmp(k, "availability")) { 
     398        lua_pushlightuserdata(L, check); 
     399        lua_pushcclosure(L, noit_lua_get_available, 1); 
     400      } 
    375401      else break; 
    376402      return 1; 
     
    423449      return 1; 
    424450    case 's': 
    425       if(!strcmp(k, "status")) { 
     451      if(!strcmp(k, "state")) { 
     452        lua_pushlightuserdata(L, check); 
     453        lua_pushcclosure(L, noit_lua_get_state, 1); 
     454      } 
     455      else if(!strcmp(k, "status")) { 
    426456        lua_pushlightuserdata(L, check); 
    427457        lua_pushcclosure(L, noit_lua_set_status, 1); 
     
    612642  ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
    613643 
    614   noit_check_set_stats(self, check, &ci->current); 
     644  /* Only set out stats/log if someone has actually performed a check */ 
     645  if(ci->current.state != NP_UNKNOWN || 
     646     ci->current.available != NP_UNKNOWN) 
     647    noit_check_set_stats(self, check, &ci->current); 
    615648  free(ci->current.status); 
    616649} 
     
    755788  noit_lua_setup_module(ci->coro_state, ci->self); 
    756789  noit_lua_setup_check(ci->coro_state, ci->check); 
    757   lua_pushnil(L); 
     790  if(cause) noit_lua_setup_check(ci->coro_state, ci->cause); 
     791  else lua_pushnil(L); 
    758792  noit_lua_resume(ci, 3); 
    759793 
  • src/noit_check.c

    r17461d6 re437d46  
    121121  if(start_offset_ms == -1) 
    122122    start_offset_ms = drand48() * noit_check_max_initial_stutter(); 
    123   if(!(check->flags & NP_TRANSIENT)) { 
     123  if(!(check->flags & NP_TRANSIENT) && check->period) { 
    124124    max = noit_check_max_initial_stutter(); 
    125125    offset = start_offset_ms + drand48() * 1000; 
     
    336336    if(check->oncheck) { 
    337337      /* This service is causally triggered by another service */ 
     338      uuid_t id; 
    338339      char fullcheck[1024]; 
    339340      char *name = check->oncheck; 
     
    341342 
    342343      noitL(noit_debug, "Searching for upstream trigger on %s\n", name); 
     344      parent = NULL; 
     345      if(uuid_parse(check->oncheck, id) == 0) { 
     346        target = ""; 
     347        parent = noit_poller_lookup(id); 
     348      } 
    343349      if((target = strchr(check->oncheck, '`')) != NULL) { 
    344         strlcpy(fullcheck, check->oncheck, target - check->oncheck); 
     350        strlcpy(fullcheck, check->oncheck, target + 1 - check->oncheck); 
    345351        name = target + 1; 
    346352        target = fullcheck; 
     353        parent = noit_poller_lookup_by_name(target, name); 
    347354      } 
    348       else 
    349        target = check->target; 
    350  
    351       parent = noit_poller_lookup_by_name(target, name); 
     355      else { 
     356        target = check->target; 
     357        parent = noit_poller_lookup_by_name(target, name); 
     358      } 
     359 
    352360      if(!parent) { 
    353361        check->flags |= NP_DISABLED; 
     
    861869} 
    862870 
     871static int 
     872bad_check_initiate(noit_module_t *self, noit_check_t *check, 
     873                   int once, noit_check_t *cause) { 
     874  /* self is likely null here -- why it is bad, in fact */ 
     875  /* this is only suitable to call in one-offs */ 
     876  stats_t current; 
     877  char buff[256]; 
     878  if(!once) return -1; 
     879  if(!check) return -1; 
     880  assert(!(check->flags & NP_RUNNING)); 
     881  check->flags |= NP_RUNNING; 
     882  noit_check_stats_clear(&current); 
     883  gettimeofday(&current.whence, NULL); 
     884  current.duration = 0; 
     885  current.available = NP_UNKNOWN; 
     886  current.state = NP_UNKNOWN; 
     887  snprintf(buff, sizeof(buff), "check[%s] implementation offline", 
     888           check->module); 
     889  current.status = buff; 
     890  noit_check_set_stats(self, check, &current); 
     891  check->flags &= ~NP_RUNNING; 
     892  return 0; 
     893} 
    863894void 
    864895noit_check_stats_clear(stats_t *s) { 
     
    11341165    noit_module_t *mod; 
    11351166    mod = noit_module_lookup(dep->check->module); 
    1136     assert(mod); 
    1137     noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 
    1138           dep->check->target, dep->check->name, 
    1139           check->target, check->name); 
    1140     if((dep->check->flags & NP_DISABLED) == 0) 
    1141       if(mod->initiate_check) 
    1142         mod->initiate_check(mod, dep->check, 1, check); 
     1167    if(!mod) { 
     1168      bad_check_initiate(mod, dep->check, 1, check); 
     1169    } 
     1170    else { 
     1171      noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 
     1172            dep->check->target, dep->check->name, 
     1173            check->target, check->name); 
     1174      if((dep->check->flags & NP_DISABLED) == 0) 
     1175        if(mod->initiate_check) 
     1176          mod->initiate_check(mod, dep->check, 1, check); 
     1177    } 
    11431178  } 
    11441179}