private[HistogramQueryHandler] def deliverData()

in server/src/main/scala/com/twitter/server/handler/HistogramQueryHandler.scala [66:141]


  private[HistogramQueryHandler] def deliverData(
    counts: Map[String, Seq[BucketAndCount]],
    transform: Seq[BucketAndCount] => Any
  ): String =
    // ".toMap" is important here for scala 2.13 as otherwise it will be a MapView which
    // doesn't serialize correctly with Jackson
    AdminJsonConverter.writeToString(counts.mapValues(transform).toMap)

  // Generates html for visualizing histograms
  private[HistogramQueryHandler] val render: String = {
    val css =
      """<link type="text/css" href="/admin/files/css/histogram-query.css" rel="stylesheet"/>"""

    val chart =
      """<div class="chart">
             <div id="curve_chart" style="width: 900px; height: 500px"></div>
           </div>"""

    /** Generates an html table to display key statistics of a histogram */
    val statsTable = {
      def entry(id: String, display: String): String = {
        s"""<tr>
                <td style="text-align:left">${escapeHtml(display)}</td>
                <td style="text-align:left" id="$id"></td>
              </tr>"""
      }
      s"""
          <div id="stats">
            <table>
              <thead>
                <th style="text-align:left" colspan="2">Details</th>
              </thead>
              <tbody>
                ${entry("detail_count", "Count")}
                ${entry("detail_sum", "Sum")}
                ${entry("detail_average", "Average")}
                ${entry("detail_min", "Min")}
                ${entry("detail_max", "Max")}
                ${entry("detail_p50", "p50")}
                ${entry("detail_p90", "p90")}
                ${entry("detail_p95", "p95")}
                ${entry("detail_p99", "p99")}
                ${entry("detail_p999", "p999")}
                ${entry("detail_p9999", "p9999")}
              </tbody>
            </table>
          </div>"""
    }

    val buttonPanel =
      """<div id="option-panel">
          <form action="post">
            <span class="option-description">Type:
              <a id="PDF" class="button-switch button-light-green left-rounded" title="Probability density function">PDF</a><a id="CDF" class="button-switch button-green right-rounded" title="Cumulative distribution function">CDF</a>
            </span>

            <span class="option-description">Scale:
              <a id="reg" class="button-switch button-red left-rounded" title="Linear scale">Reg</a><a id="log" class="button-switch button-light-red right-rounded" title="Log scale">Log</a>
            </span>

            <span class="option-description">Refresh:
              <a id="refreshOn" class="button-switch button-gray left-rounded" title="Refresh the plot every minute">On</a><a id="refreshOff" class="button-switch button-black right-rounded">Off</a>
            </span>

            <span class="option-description-last"><a id="download-link" class="button-download button-blue" title="Download bucket counts in json">Download</a></span>
          </form>
        </div>"""

    val scripts =
      """
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript" src="/admin/files/js/histogram-utils.js"></script>
        <script type="text/javascript" src="/admin/files/js/histogram-dom.js"></script>
        <script type="text/javascript" src="/admin/files/js/histogram-main.js"></script>"""
    css + chart + statsTable + buttonPanel + scripts
  }