~vila/uci-engine/nova-failure

« back to all changes in this revision

Viewing changes to bin/called-by-tarmac.py

  • Committer: Ubuntu CI Bot
  • Author(s): Celso Providelo
  • Date: 2014-11-20 23:37:40 UTC
  • mfrom: (898.1.2 tarmac-metrics-no-counters)
  • Revision ID: ubuntu_ci_bot-20141120233740-6ylgjom2quci254t
Replace all Statsd counters by timers, since timer.count is the only counter that actually works with the current Graphite version. [r=Paul Larson, PS Jenkins bot]

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
    def reset_timing(self):
113
113
        self.last_time = time.time()
114
114
 
115
 
    def increment(self, stat):
116
 
        self.client.incr(stat)
117
 
 
118
115
    def timing(self, stat):
119
116
        current_time = time.time()
120
117
        duration = (current_time - self.last_time) * 1000
134
131
    statsd_uri = os.environ.get('CI_STATSD_URI', 'localhost:8125')
135
132
    namespace = os.environ.get('CI_STATSD_NAMESPACE', 'tarmac')
136
133
 
 
134
    # XXX cprov 20141120: Note that we are using timers also for counting
 
135
    # events ('counters.*' namespace), that's because counter (and gauges)
 
136
    # currently do not work as (we) expect in the available versions of
 
137
    # graphite+carbon+txstatsd packages in ubuntu. The essential problem is
 
138
    # that counting samples are propagated to future intervals instead of
 
139
    # getting aggregated (summed). Timers count work as we expect.
137
140
    metrics = SaneMetrics(*statsd_uri.split(':'), namespace=namespace)
138
141
 
139
142
    def die(signum, frame):
142
145
        We rely on atexit() handlers to remove various temporary directories
143
146
        so we need to call sys.exit().
144
147
        """
145
 
        metrics.increment('failures.killed')
 
148
        metrics.timing('counters.failures.killed')
146
149
        logging.info('Received signal {}, exiting'.format(signum))
147
150
        signal.signal(signum, signal.SIG_DFL)
148
151
 
161
164
    # variable so it can be restored.
162
165
    if os.environ.get('TARMAC_METRIC_STARTED') is None:
163
166
        metrics.reset_timing()
164
 
        metrics.increment('attempts')
 
167
        metrics.timing('counters.attempts')
165
168
        os.environ['TARMAC_METRIC_STARTED'] = str(metrics.last_time)
166
169
    else:
167
170
        metrics.last_time = float(os.environ.get('TARMAC_METRIC_STARTED'))
172
175
        atexit.register(venv.delete)
173
176
        metrics.timing('setup')
174
177
        if not fake_out_branch():
175
 
            metrics.increment('failures.fake_out_branch')
 
178
            metrics.timing('counters.failures.fake_out_branch')
176
179
            return 1
177
180
 
178
181
    if not check_lxc_mounted():
179
182
        logging.error('/var/lib/lxc not mounted.')
180
 
        metrics.increment('failures.lxc_not_mounted')
 
183
        metrics.timing('counters.failures.lxc_not_mounted')
181
184
        return 1
182
185
 
183
186
    # TODO ev 2014-07-04 Delete all the swift containers created during
192
195
        # exactly if and/or how they happen, thus the bare exception and
193
196
        # a simple counter. We will have a better idea after we start
194
197
        # collecting and investigating stats.
195
 
        metrics.increment('failures.venv')
 
198
        metrics.timing('counters.failures.venv')
196
199
        raise
197
200
 
198
201
    from testing import run_tests
210
213
        # The environment wasn't cleaned up from the last run, but that's to be
211
214
        # expected. It's left around for debugging between runs.
212
215
        if not destroy_environment():
213
 
            metrics.increment('failures.destroy')
 
216
            metrics.timing('counters.failures.destroy')
214
217
            return 1
215
218
        metrics.timing('destroy')
216
219
 
218
221
    t = time.time()
219
222
    # Bootstrap, then deploy.
220
223
    if not bootstrap() or deploy.main() != 0:
221
 
        metrics.increment('failures.deploy')
 
224
        metrics.timing('counters.failures.deploy')
222
225
        return 1
223
226
    metrics.timing('deploy')
224
227
 
225
228
    logging.info('Done in %.2fs' % (time.time() - t))
226
229
    result = run_tests.main(sys.argv[1:], sys.stdout, sys.stderr)
227
230
    if not result:
228
 
        metrics.increment('success')
 
231
        metrics.timing('counters.success')
229
232
        metrics.timing('testing')
230
233
    else:
231
 
        metrics.increment('failures.testing')
 
234
        metrics.timing('counters.failures.testing')
232
235
 
233
236
    return result
234
237