Bug 1120416 - Remove Bugzilla & ElasticSearch comment submission
authorEd Morley <emorley@mozilla.com>
Mon, 12 Jan 2015 14:10:30 +0000
changeset 1501 b17c1d831251
parent 1500 ca691ff528c7
child 1502 ee042d68178e
push id869
push useremorley@mozilla.com
push dateMon, 12 Jan 2015 18:12:14 +0000
bugs1120416
Bug 1120416 - Remove Bugzilla & ElasticSearch comment submission Treeherder no longer relies upon submitBugzillaComment.php and starcomment.php for submitting failure classifications to Bugzilla and ElasticSearch. TBPL is nearing end of life and as such, using TBPL to submit failure classifications is something we now wish to prevent, to: * ensure there are no other tools submitting to TBPL * to prevent inconsistency/duplication between TBPL and Treeherder submissions * to allow us to more easily make credential changes to TBPLbot's BMO account * to give TBPL users an additional nudge to make the transition to Treeherder After this change, commenting on a failure will still add the comment to TBPL's DB, just not submit it to Bugzilla/ElasticSearch. A message will be displayed warning to use Treeherder if the tracking of stats is desired.
js/AddCommentUI.js
js/Config.js
js/UserInterface.js
php/starcomment.php
php/submitBugzillaComment.php
--- a/js/AddCommentUI.js
+++ b/js/AddCommentUI.js
@@ -3,18 +3,16 @@
 
 "use strict";
 
 var AddCommentUI = {
 
   addToBugs: {},
   numSendingComments: 0,
   numSendingCommentChangedCallback: function empty() {},
-  numSendingBugs: 0,
-  numSendingBugChangedCallback: function empty() {},
 
   init: function AddCommentUI_init(submitURL) {
     var self = this;
     $("a.addNote").live("click", function addNoteLinkClick() {
       self.openCommentBox();
       return false;
     });
     $("#autoStar").live("click", function autoStarClick() {
@@ -79,48 +77,27 @@ var AddCommentUI = {
   },
 
   submit: function AddCommentUI_submit() {
     var self = this;
     var data = Controller.getData();
     var email = $("#logNoteEmail").val();
     var comment = $("#logNoteText").val();
     var selectedJobs = Object.keys(UserInterface._selectedBuilds);
-    var bugsSubmitData = {};
     selectedJobs.forEach(function(id) {
       var result = data.getMachineResult(id);
       // result is undefined for pending or in-progress jobs
       if (!result)
         return;
       self._postOneTBPLNote(email, comment, result, function oneLessCommentPending() {
         self.pendingCommentsChanged(-1, result);
       });
       self.pendingCommentsChanged(1);
-      if (!result.suggestions)
-        return;
-      for (var j = 0; j < result.suggestions.length; ++j) {
-        var suggestion = result.suggestions[j];
-        if (!(suggestion.id in self.addToBugs))
-          continue;
-        bugsSubmitData[suggestion.id] = {
-          header: suggestion.signature,
-          log: suggestion.log,
-          email: email.replace("@", "%"),
-          revision: result.revs[Config.treeInfo[result.tree].primaryRepo],
-          slave: result.slave,
-          logLink: result.prodBriefLogURL
-        };
-      }
     });
-    for (var id in bugsSubmitData) {
-      this._postOneBugzillaComment(id, bugsSubmitData[id], function oneLessBugPending() {
-        self.pendingBugsChanged(-1);
-      });
-      this.pendingBugsChanged(1);
-    }
+    UserInterface.showMessage("Failure annotations are no longer submitted to Bugzilla/OrangeFactor. Please use Treeherder if you need stats to be tracked.", 'info');
     this.clearAutoStarBugs();
     this.reset();
   },
 
   openCommentBox: function AddCommentUI_openCommentBox() {
     $("#addNotePopup").show();
     if (UserInterface._activeResult)
       UserInterface.setBuildSelected(UserInterface._activeResult, true);
@@ -174,25 +151,16 @@ var AddCommentUI = {
     this.numSendingComments += changedBy;
     this.numSendingCommentChangedCallback(result);
   },
 
   registerNumSendingCommentChangedCallback: function AddCommentUI_registerNumSendingCommentChangedCallback(callback) {
     this.numSendingCommentChangedCallback = callback;
   },
 
-  pendingBugsChanged: function AddCommentUI_pendingBugsChanged(changedBy) {
-    this.numSendingBugs += changedBy;
-    this.numSendingBugChangedCallback();
-  },
-
-  registerNumSendingBugChangedCallback: function AddCommentUI_registerNumSendingBugChangedCallback(callback) {
-    this.numSendingBugChangedCallback = callback;
-  },
-
   markSuggestedBug: function AddCommentUI_markSuggestedBug(bugid) {
     var resultSuggestion = $(".stars .summary [data-bugid=" + bugid + "] .starSuggestion");
     if (bugid in this.addToBugs) {
       resultSuggestion.addClass('active');
     } else {
       resultSuggestion.removeClass('active');
     }
   },
@@ -272,39 +240,16 @@ var AddCommentUI = {
     box.val(box.val().replace(new RegExp(".*" + rev + ".*\n?", ""), ""));
   },
 
   _popupIsOpen: function AddCommentUI__popupIsOpen() {
     return $("#addNotePopup").is(":visible");
   },
 
   _postOneTBPLNote: function AddCommentUI__postOneTBPLNote(email, comment, machineResult, callback) {
-    var d = machineResult.startTime;
-    $.ajax({
-      url: Config.wooBugURL,
-      type: "POST",
-      data: {
-        buildname: machineResult.machine.name,
-        machinename: machineResult.slave,
-        os: machineResult.machine.os,
-        date: d.getUTCFullYear() + "-" +
-              (d.getUTCMonth() < 9 ? "0" : "") + (d.getUTCMonth() + 1) + "-" +
-              (d.getUTCDate() < 10 ? "0" : "") + d.getUTCDate(),
-        type: machineResult.machine.type,
-        buildtype: machineResult.machine.flavor,
-        starttime: machineResult.startTime.getTime() / 1000,
-        logfile: machineResult.runID,
-        tree: Config.treeInfo[machineResult.tree].primaryRepo,
-        rev: machineResult.revs[Config.treeInfo[machineResult.tree].primaryRepo],
-        who: email,
-        comment: comment,
-        timestamp: Math.ceil((new Date()).getTime()/1000),
-      },
-    });
-
     $.ajax({
       url: Config.serverBaseURL + "php/submitJobComment.php",
       type: "POST",
       data: {
         id: machineResult.runID,
         who: email,
         note: comment,
         machinename: machineResult.slave,
@@ -315,43 +260,9 @@ var AddCommentUI = {
 
     machineResult.notes.push({
       who: email,
       note: comment,
       timestamp: new Date().getTime() / 1000,
     });
   },
 
-  _postOneBugzillaComment: function AddCommentUI__postOneBugzillaComment(id, data, callback) {
-    $.ajax({
-      url: Config.serverBaseURL + "php/submitBugzillaComment.php",
-      type: "POST",
-      data: {
-        id: id,
-        comment:
-          data.email + "\n" +
-          data.logLink + "\n" +
-          data.header + "\n" +
-          "revision: " + data.revision + "\n" +
-          "slave: " + data.slave + "\n\n" +
-          data.log,
-      },
-      success: function (data) {
-        // Typical Bugzilla responses:
-        // for success: {"ref":"https://api-dev.bugzilla.mozilla.org/latest/bug/123456/comment","id":"12345678"}
-        // for failure: {"error":1,"code":"300","message":"The username or password you entered is not valid."}
-        try {
-          var response = JSON.parse(data);
-          if (response.error)
-            UserInterface.showMessage("Bugzilla error submitting bug comment: " + response.message, 'error');
-        } catch (e) {
-          // In case we hit one of the die()s in submitBugzillaComment.php
-          UserInterface.showMessage("submitBugzillaComment.php error: " + data, 'error');
-        }
-      },
-      error: function (request, textStatus, error) {
-        UserInterface.showMessage("Ajax failure submitting bug comment: " + textStatus, 'error');
-      },
-      complete: callback,
-    });
-  },
-
 };
--- a/js/Config.js
+++ b/js/Config.js
@@ -21,17 +21,16 @@ var Config = {
   prodBaseURL: "https://tbpl.mozilla.org/", // used for log links in tbplbot bugzilla comments
   mercurialURL: "https://hg.mozilla.org/",
   buildjsonURL: "https://secure.pub.build.mozilla.org/builddata/buildjson/",
   buildapiURL: "https://secure.pub.build.mozilla.org/buildapi/",
   selfServeURL: "https://secure.pub.build.mozilla.org/buildapi/self-serve/",
   slaveHealthURL: "https://secure.pub.build.mozilla.org/builddata/reports/slave_health/slave.html?name=",
   buildGraphsURL: "http://builddata.pub.build.mozilla.org/reports/pending/",
   treeStatusURL: "https://treestatus.mozilla.org/",
-  wooBugURL: "https://tbpl.mozilla.org/php/starcomment.php", // war-on-orange database
   mcMergeURL: "mcmerge/",
   // treeInfo gives details about the trees and repositories. There are various
   // items that can be specified:
   //
   // - primaryRepo:    [required] The primary hg repository for the tree.
   // - otherRepo:      [optional] An additional hg repository that the tree
   //                              works with.
   //
--- a/js/UserInterface.js
+++ b/js/UserInterface.js
@@ -145,19 +145,16 @@ var UserInterface = {
         //  - the list of failed jobs in the top right corner
         //  - the number of unstarred failures in the title
         //  - the panel showing the star if the starred result is selected
         // We need to refresh all these places.
         self.handleUpdatedPushes([changedResult.push]);
         self._setActiveResult(self._activeResult, false);
       }
     });
-    AddCommentUI.registerNumSendingBugChangedCallback(function bugSendUpdater() {
-      self.updateStatus();
-    });
     HiddenBuildsAdminUI.init();
 
     this._updateTimezoneDisplay();
 
     $("#pushes").append(
       $('<li id="goBackLi"><a id="goBack" href="#" title="add another ' + Config.goBackPushes + ' pushes"></a></li>')
         .children().first().bind('click', function goBack() {
           self._controller.extendPushRange(-Config.goBackPushes);
deleted file mode 100644
--- a/php/starcomment.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-$elastic_search_server = "http://elasticsearch-zlb.webapp.scl3.mozilla.com:9200/";
-
-// ElasticSearch's 'index' and 'doctype' are roughly similar to the SQL
-// concepts of 'database' and 'table'. We store unique instances of
-// bug-per-failure in bugs/bug_info, for use by OrangeFactor.
-$elastic_search_bug_index = "bugs";
-$elastic_search_bug_doctype = "bug_info";
-
-$log_filename = "esinput.log";
-$log_fp = null;
-
-error_reporting(E_ERROR | E_PARSE);
-
-function log_msg($msg) {
-  global $log_fp;
-
-  if ($log_fp)
-    fwrite($log_fp, $msg);
-}
-
-// make a simple HTTP request and return the response
-function do_http_request($url, $data, $method = 'POST') {
-  try {
-    $params = array('http' => array(
-                    'method' => $method,
-                    'content' => json_encode($data),
-                    'header' => "Content-type: text/plain\r\n" .
-                                "Connection: close\r\n"
-                   ));
-
-    $ctx = stream_context_create($params);
-    $fp = fopen($url, 'rb', false, $ctx);
-
-    $response = stream_get_contents($fp);
-    if ($response === false)
-      log_msg("Problem reading data from $url\n");
-
-    if ($fp)
-      fclose($fp);
-
-    return $response;
-  } catch(Exception $e) {
-    log_msg("Network error: " . $e->getMessage() . "\n");
-  }
-}
-
-// send a bug to ES if it doesn't already exist there
-function send_bug($url, $dat, $bug)
-{
-  unset($dat['comment']);
-  $dat['bug'] = $bug;
-
-  // create a request body to test if this bug is already in ES
-  $request = array('query' => array(
-                    'bool' => array(
-                      'must' => array(
-                        array('field' => array('bug' => $bug)),
-                        array('field' => array('machinename' => $dat['machinename'])),
-                        array('field' => array('starttime' => $dat['starttime']))
-                        )
-                      )
-                    )
-                  );
-  log_msg("request: " . json_encode($request) . "\n");
-
-  // send the request to the _search url with HTTP GET
-  $result = do_http_request($url . "_search", $request, 'GET');
-  log_msg("response: " . $result . "\n");
-
-  // find how many instances of this bug already exist in ES
-  $hits = json_decode($result)->hits->total;
-  log_msg("hits: " . json_encode($hits) . "\n");
-
-  // if no instances exist, add to ES
-  if ($hits == 0) {
-    log_msg("writing bug to ES: " . json_encode($dat) . "\n");
-    $result = do_http_request($url, $dat);
-    log_msg("result: " . $result . "\n");
-  }
-}
-
-if ($log_filename)
-  $log_fp = fopen($log_filename, 'a');
-
-$es_bug_url = $elastic_search_server . $elastic_search_bug_index .
-              "/" . $elastic_search_bug_doctype . "/";
-
-try {
-  // the comment arrives as the data in the $_POST array
-  $dat = $_POST;
-  // search the comment string and see if any bug numbers are referenced
-  $hits = preg_match_all('/Bug\s*(?P<bug>\d+)/i', $dat['comment'], $matches);
-  // for each bug referenced, push the bug data to the 'bugs' doctype separately
-  if ($hits) {
-    foreach ($matches['bug'] as $bug) {
-      log_msg("bug found: " . $bug . "\n");
-      send_bug($es_bug_url, $dat, $bug);
-    }
-  } else {
-    log_msg("no bug found\n");
-  }
-} catch (Exception $e) {
-  echo 'Caught exception: ',  $e->getMessage(), "\n";
-  log_msg('Caught exception: ' . $e->getMessage() . "\n");
-}
-
-if ($log_fp)
-  fclose($log_fp);
deleted file mode 100644
--- a/php/submitBugzillaComment.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/* -*- Mode: PHP; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=2 et tw=80 : */
-
-require_once 'config.php';
-require_once 'inc/JSON.php';
-
-if (!defined('TBPLBOT_EMAIL') || !defined('TBPLBOT_PASSWORD'))
-  die('Invalid configuration!');
-
-if (!isset($_POST['id']) || !isset($_POST['comment']))
-  die('Invalid params!');
-
-if (!function_exists('curl_init'))
-  die('Needs CURL!');
-
-$bugid = (int) $_POST['id'];
-if ($bugid <=0)
-  die('Invalid Bug ID specified');
-
-header("Content-Type: text/plain");
-header("Access-Control-Allow-Origin: *");
-
-$url = "https://bugzilla.mozilla.org/rest/bug/$bugid/comment?login=" . urlencode(TBPLBOT_EMAIL) . "&password=" . urlencode(TBPLBOT_PASSWORD);
-$json = new Services_JSON();
-$data = array(
-  "comment" => sanitize($_POST["comment"])
-);
-$data = $json->encode($data);
-
-$ch = curl_init();
-curl_setopt($ch, CURLOPT_URL, $url);
-curl_setopt($ch, CURLOPT_POST, 1);
-curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Content-Type: application/json"));
-$result = curl_exec($ch);
-
-if ($result === false) {
-  $error = array(
-    "error" => curl_errno($ch)
-  );
-  echo $json->encode($error);
-} else {
-  echo $result;
-}
-
-curl_close($ch);
-
-function sanitize($str) {
-  // Remove UTF-8 non-breaking space character sequences (0xc2a0), and
-  // replace them with normal spaces.
-  return str_replace(chr(0xc2) . chr(0xa0), ' ', $str);
-}