module Bicho::Export

Utility methods for exporting bugs to other systems

Public Class Methods

to_json(bug) click to toggle source

Exports full data of a bug to json, including some extended calculated attributes.

# File lib/bicho/export.rb, line 11
def self.to_json(bug)
  bug_h = bug.to_h
  bug_h['history'] = bug.history.changesets.map(&:to_h)
  bug_h['resolution_time'] = Bicho::Reports.resolution_time(bug)
  JSON.generate(bug_h)
end
to_prometheus_push_gateway(query) click to toggle source

Export a query for usage as a metric in prometheus See github.com/prometheus/pushgateway

The metric name will be 'bugs_total' See prometheus.io/docs/practices/naming/)

And every attributed specified in the query will be used as a label

# File lib/bicho/export.rb, line 26
def self.to_prometheus_push_gateway(query)
  buf = StringIO.new
  dimensions = [:product, :status, :priority, :severity, :resolution, :component]
  grouped = query.to_a.group_by do |i|
    puts i
    dimensions.map { |d| [d, i[d]] }.to_h
  end

  buf.write("# TYPE bugs_total gauge\n")
  grouped.each do |attrs, set|
    labels = attrs
             .map { |e| "#{e[0]}=\"#{e[1]}\"" }
             .join(',')
    buf.write("bugs_total{#{labels}} #{set.size}\n")
  end
  buf.write("\n")
  buf.close
  buf.string
end