anchor.diff:  terminate(_Reason, _Req, State) ->
       {ok, State}.
   
  +%% Private functions
  +%% =================
  +
   %% Get last value.
   %%
   %% To reduce impact on IO operation we do 2 phase fetch.
  
positive.code: get_last_value(Bucket, Path) ->
      Metric = dproto:metric_from_list(Path),
      Now = erlang:system_time(seconds),
      InitialLookupT = Now - ?INITIAL_LOOKUP_PERIOD - ?INITIAL_LOOKUP_DELAY,
      case get_last_value(Bucket, Metric, InitialLookupT, ?INITIAL_LOOKUP_PERIOD) of
          null ->
              ExtraLookupT = InitialLookupT - ?EXTRA_LOOKUP_PERIOD,
              get_last_value(Bucket, Metric, ExtraLookupT, ?EXTRA_LOOKUP_PERIOD);
          V -> V
      end.
  
  get_last_value(Bucket, Metric, Time, Period) ->
      Count = Period, %% TODO: we should take into account bucket resolution and maybe iterate in chunks
      {ok, _Resolution, Data} = dalmatiner_connection:get(Bucket, Metric, Time, Count),
      {Value, Offset} = find_last_point(Data),
      case Value of
          none -> null;
  
negative.code: 
  -ignore_xref([init/3, handle/2, terminate/3]).
  
  -define(LOOKUP_PERIOD, 3600).
  
  %% Public Api
  %% ==========
  
  init(_Transport, Req, []) ->
      {ok, Req, undefined}.
  