Prose\ExpectsGraphite::metricIsAlwaysZero PHP Method

metricIsAlwaysZero() public method

public metricIsAlwaysZero ( $metric, $startTime, $endTime )
    public function metricIsAlwaysZero($metric, $startTime, $endTime)
    {
        // when are we looking for?
        $humanStartTime = date('Y-m-d H:i:s', $startTime);
        $humanEndTime = date('Y-m-d H:i:s', $endTime);
        // what are we doing?
        $log = usingLog()->startAction("ensure metric '{$metric}' is zero between '{$humanStartTime}' and '{$humanEndTime}'");
        // get the data from graphite
        $data = fromGraphite()->getDataFor($metric, $startTime, $endTime);
        // do we *have* any data?
        if (empty($data) || !isset($data[0]->target, $data[0]->datapoints)) {
            // graphite returns an empty data set when there is no data
            //
            // NOTE: this can also happen when the test is asking for
            //       the wrong metric :(
            $log->endAction("no data available for metric '{$metric}'; assuming success");
            return;
        }
        // we have data ... let's make sure we're happy with it
        foreach ($data[0]->datapoints as $datapoint) {
            if ($datapoint[0] > 0) {
                throw new E5xx_ExpectFailed(__METHOD__, 0, $datapoint[0]);
            }
        }
        // all done
        $log->endAction("data was available, metric '{$metric}' was always zero");
        return;
    }