jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/379806 )

Change subject: Delete ganglia_reporter, use new module
......................................................................


Delete ganglia_reporter, use new module

DEPLOY NOTE: remember to drush dis ganglia_reporter first!

Bug: T171524
Change-Id: Ib527b1171d69ea5dd29d04a624420bd4d42b14cd
---
D sites/all/modules/ganglia_reporter/GangliaReporter.php
D sites/all/modules/ganglia_reporter/ganglia_reporter.info
D sites/all/modules/ganglia_reporter/ganglia_reporter.module
D sites/all/modules/ganglia_reporter/tests/ganglia_reporter.test
M sites/all/modules/queue2civicrm/queue2civicrm.module
M sites/default/enabled_modules
6 files changed, 9 insertions(+), 347 deletions(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/ganglia_reporter/GangliaReporter.php 
b/sites/all/modules/ganglia_reporter/GangliaReporter.php
deleted file mode 100644
index 76409ff..0000000
--- a/sites/all/modules/ganglia_reporter/GangliaReporter.php
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-
-/**
- * A programmatic interface for gmetric
- */
-class GangliaReporter {
-
-  /**
-   * Path to gmetric executable
-   * @var string
-   */
-  protected $gmetric_path = null;
-
-  /**
-   * Constructor
-   *
-   * Initializes by setting gmetric path.
-   * @param $gmetric_path
-   */
-  function __construct( $gmetric_path=null ) {
-    // if the gmetric path hasn't been explicitly set, try to auto-locate it.
-    if ( !$gmetric_path ) {
-      $gmetric_path = self::locateGmetricPath();
-    }
-    $this->setGmetricPath( $gmetric_path );
-  }
-
-  /**
-   * Get gmetric path
-   *
-   * In the event that gmetric path is not set in scope, attempt to auto-locate
-   * and set it.
-   *
-   * @return string
-   */
-  function getGmetricPath() {
-    if ( !$this->gmetric_path ) {
-      $this->setGmetricPath( self::locateGmetricPath() );
-    }
-    return $this->gmetric_path;
-  }
-
-  /**
-   * Set gmetric path
-   *
-   * Throws an exception in the event that the path to the gmetric binary does
-   * not exist.
-   *
-   * @param $path
-   */
-  function setGmetricPath( $path ) {
-    if ( !file_exists( $path )) {
-      throw new Exception( 'Gmetric path "' . $path . '" does not exist.' );
-    }
-    $this->gmetric_path = $path;
-  }
-
-  /**
-   * Executes gmetric call
-   *
-   * Sends arbitrary data to Ganglia using gmetric.
-   *
-   * Params the same as arguments for gmetric.  Run gmetric --help for more
-   * info.
-   *
-   * @param $name
-   * @param $value
-   * @param $type
-   * @param $units
-   * @param $slope
-   * @param $tmax
-   * @param $dmax
-   * @return bool
-   */
-  function sendMetric( $name, $value, $type = 'int8', $units = '', $slope = 
'both', $tmax = 60, $dmax = 0 ) {
-    // pack the params and their values into an array so we can more easily 
build our string of options
-    $opts = array(
-      'name' => $name,
-      'value' => $value,
-      'type' => $type,
-      'units' => $units,
-      'slope' => $slope,
-      'tmax' => $tmax,
-      'dmax' => $dmax,
-    );
-
-    // construct our command to execute, along with our string of options
-    $cmd = escapeshellcmd( $this->getGmetricPath() . ' ' . 
$this->prepareOptions( $opts ));
-    // execute the gmetric command...
-    exec( $cmd, $output, $retval );
-
-    // return true/false depending on success.
-    if( $retval === 0 ) {
-      return true;
-    } else {
-      return false;
-    }
-  }
-
-  /**
-   * Returns a formatted string of options to be passed to executable
-   *
-   * Takes an associative array of $option_name => $option_value.
-   *
-   * @param $opts
-   * @return string
-   */
-  function prepareOptions( array $opts ) {
-    foreach( $opts as $opt => $val ) {
-      $opts[ $opt ] = "--" . $opt . "=" . escapeshellarg( $val );
-    }
-    return implode( " ", $opts );
-  }
-
-  /**
-   * Attempt to auto-determine location of gmetric
-   * @return string Gmetric path (or null)
-   */
-  static function locateGmetricPath() {
-    $path = exec( 'which gmetric' );
-    if ( !strlen( $path )) {
-      return null;
-    }
-    return $path;
-  }
-}
diff --git a/sites/all/modules/ganglia_reporter/ganglia_reporter.info 
b/sites/all/modules/ganglia_reporter/ganglia_reporter.info
deleted file mode 100644
index 429b9c0..0000000
--- a/sites/all/modules/ganglia_reporter/ganglia_reporter.info
+++ /dev/null
@@ -1,6 +0,0 @@
-name = Ganglia Reporter
-description = Reports metrics to Ganglia 
-core = 7.x
-configure = admin/config/ganglia_reporter/configure
-files[] = tests/ganglia_reporter.test
-files[] = GangliaReporter.php
diff --git a/sites/all/modules/ganglia_reporter/ganglia_reporter.module 
b/sites/all/modules/ganglia_reporter/ganglia_reporter.module
deleted file mode 100644
index bee73bf..0000000
--- a/sites/all/modules/ganglia_reporter/ganglia_reporter.module
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php 
-
-/**
- * Invocation of hook_menu
- */
-function ganglia_reporter_menu() {
-  $items = array();
-  
-  // displays settings form
-  $items[ 'admin/config/ganglia_reporter' ] = array(
-    'title' => 'Ganglia Reporter',
-    'access arguments' => array( 'administer ganglia reporter' ),
-    'page callback' => 'system_admin_menu_block_page',
-    'file' => 'system.admin.inc',
-    'file path' => drupal_get_path('module', 'system'),
-  );
-
-  // forces 'Ganglia Reporter' to appear on the config page
-  $items[ 'admin/config/ganglia_reporter/configure' ] = array(
-    'title' => 'Configure',
-    'description' => 'Configure Ganglia Gmetric scripts.',
-    'access arguments' => array( 'administer ganglia reporter' ),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array( 'ganglia_reporter_settings' ),
-  );
-  
-  return $items;
-}
-
-/**
- * Invocation of hook_permission
- */
-function ganglia_reporter_permission() {
-  return array(
-    'administer ganglia reporter' => array(
-      'title' => t('Administer Ganglia reporter'),
-    ),
-  );
-}
-
-/**
- * Generate settings form
- */
-function ganglia_reporter_settings() {
-  $form = array();
-  
-  $form[ 'ganglia_reporter_gmetric_path' ] = array(
-    '#type' => 'textfield',
-    '#title' => t( 'Gmetric Path' ),
-    '#required' => true,
-    '#default_value' => variable_get( 'ganglia_reporter_gmetric_path', 
GangliaReporter::locateGmetricPath() ),
-    '#description' => t( 'The full path to Gmetric executable.' )
-  );
-  
-  return system_settings_form( $form );
-}
-
-/**
- * Get a GangliaReporter object
- * 
- * Sets a static variable to the GangliaReporter object and returns the object
- * @return object GangliaReporter
- */
-function ganglia_reporter_get_obj() {
-  static $gr_obj;
-  
-  if ( !$gr_obj ) {
-    try {
-      $gr_obj = new GangliaReporter( variable_get( 
'ganglia_reporter_gmetric_path', null ));
-    } catch ( Exception $e ) {
-      drupal_set_message( 'Ganglia reporter encountered a problem: ' . $e, 
'error' );
-      $gr_obj = false;
-    }
-  }
-  
-  return $gr_obj;
-}
-
-/**
- * Wrapper for GangliaReporter->send_metric
- * 
- * Params are the same as those for the gmetric binary.  Run gmetric --help 
- * for more details.
- * 
- * @param string $name
- * @param string $value
- * @param string $type
- * @param string $units
- * @param string $slope
- * @param int $tmax
- * @param int $dmax
- * @return bool Success or failure of executing gmetric
- */
-function ganglia_reporter_send_metric( $name, $value, $type = 'int8', $units = 
'', $slope = 'both', $tmax = 60, $dmax = 0 ) {
-  $gr = ganglia_reporter_get_obj();
-  return $gr->sendMetric( $name, $value, $type, $units, $slope, $tmax, $dmax );
-}
-
diff --git a/sites/all/modules/ganglia_reporter/tests/ganglia_reporter.test 
b/sites/all/modules/ganglia_reporter/tests/ganglia_reporter.test
deleted file mode 100644
index 9e6bacd..0000000
--- a/sites/all/modules/ganglia_reporter/tests/ganglia_reporter.test
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php 
-
-class GangliaReporterTest extends DrupalUnitTestCase {
-  /**
-   * GangliaReporter object
-   * @var object
-   */
-  public $gr_obj;
-  
-  public static function getInfo() {
-    return array(
-      'name' => 'Ganglia Reporter Tests',
-      'description' => 'Tests for Ganglia Reporter module',
-      'group' => 'Pipeline',
-    );
-  }
-  
-  function setUp() {
-    $this->gr_obj = new GangliaReporter();
-    parent::setUp();
-  }
-  
-  function tearDown() {
-    parent::tearDown();
-  }
-  
-  /**
-   * Tests GangliaReporter->getGmetricPath()
-   */
-  function testGetGmetricPath() {
-    $set_path = 'foo';
-    $this->gr_obj->setGmetricPath( $set_path );
-    $get_path = $this->gr_obj->getGmetricPath();
-    $this->assertEqual( $set_path, $get_path, 'Gmetric paths do not match.  
Expected ' . $set_path . ', got ' . $get_path . '.' );
-  }
-  
-  /**
-   * Tests GangliaReporter::locateGmetricPath()
-   */
-  function testLocateGmetricPath() {
-    $path = exec( 'which gmetric' );
-    $located_path = GangliaReporter::locateGmetricPath();
-    $this->assertEqual( $path, $located_path, "Incorrect gmetric path located. 
 Expected " . $path .", got " . $located_path );
-  }
-  
-  /**
-   * Tests GangliaReporter->setGmetricPath's exception case (when path doesn't 
exist)
-   */
-  function testSetGmetricPathException() {
-    $exception = false;
-    try {
-      $this->gr_obj->setGmetricPath( false );
-    } catch ( Exception $e ){
-      $exception = true;
-    }
-    $this->assertTrue( $exception, "Expected exception to be thrown in 
setGmetricPath." );
-  }
-  
-  /**
-   * Tests GangliaReporter->sendMetric()
-   */
-  function testSendMetric() {
-    $retval = $this->gr_obj->sendMetric( 'test', mt_rand(0,100) );
-    $this->assertTrue( $retval, 'Gmetric not succesfully executed.' );
-  }
-  
-  /**
-   * Tests wrapper function ganglia_reporter_send_metric()
-   */
-  function testGangliaReporterSendMetric() {
-    $retval = ganglia_reporter_send_metric( 'test2', mt_rand(0,100) );
-    $this->assertTrue( $retval, 'Gmetric not succesfully executed' );
-  }
-
-  /**
-   * Tests GangliaReporter->prepareOptions()
-   */
-  function testPrepareOptions() {
-    $opts = array(
-      'foo' => 'bar',
-      'baz' => 'blort',
-    );
-    $expected = "--foo='bar' --baz='blort'"; //make sure the values are 
escaped by escapeshellarg()
-    $prepared_options = $this->gr_obj->prepareOptions( $opts );
-    $this->assertEqual( $prepared_options, $expected, "Prepared options 
($prepared_options) different from expected ($expected)." );
-  }
-}
\ No newline at end of file
diff --git a/sites/all/modules/queue2civicrm/queue2civicrm.module 
b/sites/all/modules/queue2civicrm/queue2civicrm.module
index f0da868..b1d2f39 100644
--- a/sites/all/modules/queue2civicrm/queue2civicrm.module
+++ b/sites/all/modules/queue2civicrm/queue2civicrm.module
@@ -102,22 +102,6 @@
     '#required' => TRUE,
     '#default_value' => variable_get('queue2civicrm_batch_time', 90),
   );
-
-  $form [ 'queue2civicrm_gmetric_tmax' ] = array(
-    '#type' => 'textfield',
-    '#title' => t('Default tmax for gmetric reporting (in seconds)'),
-    '#required' => false,
-    '#default_value' => variable_get( 'queue2civicrm_gmetric_tmax', 60 ),
-    '#description' => t('TMAX indicates the freshness of a metric. If TN 
exceeds TMAX, then Ganglia is expecting a new value. However, TMAX is only 
advisory: Ganglia takes no action when TN exceeds TMAX.')
-  );
-  
-  $form [ 'queue2civicrm_gmetric_dmax' ] = array(
-       '#type' => 'textfield',
-    '#title' => t('Default dmax for gmetric reporting (in seconds)'),
-    '#required' => false,
-    '#default_value' => variable_get( 'queue2civicrm_gmetric_dmax', 360 ),
-    '#description' => t('DMAX indicates for how long an old metric should be 
retained. If TN exceeds DMAX then Ganglia will consider that that metric is no 
longer being monitored. Therefore, it will discard information about that 
metric.')
-  );
   
   return system_settings_form($form);
 }
@@ -155,24 +139,20 @@
    * this may some day supersede the process counts handled above...
    * 
    * Note that this might be a little whack.  At least, it feels a little 
sloppy.
-   * The tmax/dmax fields should probably be configurable
-   * through the UI rather than hardcoded here. Furthermore, we might consider 
specifying the names
-   * of gateways to keep track of, rather than auto-generate the gateways to 
keep track of during 
-   * queue consumption.  With the latter (current) method, we'll only report 
to gmetric when there
-   * are > 0 msgs consumed from the queue - meaning if there are no msgs for a 
particular gateway, 
-   * that fact will not get reported to gmetric.  But I've hardcoded the dmax 
param here to be the
-   * same as the frequency of queue consumption, so if there are no messages 
in the queue for
-   * a particular gateway, the gateway will report as having consumed 0 
messages in ganglia anyway.
+   * We might consider specifying the names of gateways to keep track of, 
rather than auto-generate
+   * the gateways to keep track of during queue consumption. With the latter 
(current) method,
+   * we'll only report to prometheus when there are > 0 msgs consumed from the 
queue - meaning if
+   * there are no msgs for a particular gateway, that fact will not get 
reported to prometheus.
    *
-   * TODO: the ganglia stuff should be a hook
+   * TODO: metrics stuff should be a hook
    */
-  $gmetric_tmax = variable_get( 'queue2civicrm_gmetric_tmax', 60 );
-  $gmetric_dmax = variable_get( 'queue2civicrm_gmetric_dmax', 360 );
   $counter = Queue2civicrmTrxnCounter::instance();
+  $metrics = array();
   foreach ( $counter->get_trxn_counts() as $gateway => $count ) {
-    module_invoke( 'ganglia_reporter', 'send_metric', $gateway . ' donations', 
$count, 'int8', 'donations', 'both', $gmetric_tmax, $gmetric_dmax );
+    $metrics["${gateway}_donations"] = $count;
   }
-  module_invoke( 'ganglia_reporter', 'send_metric', 'Total donations', 
$counter->get_count_total(), 'int8', 'donations', 'both', $gmetric_tmax, 
$gmetric_dmax );
+  $metrics['total_donations'] = $counter->get_count_total();
+  metrics_reporting_report_metrics( 'queue2civicrm', $metrics );
   
   if ($processed > 0) {
     watchdog('queue2civicrm', 'Successfully processed ' . $processed . ' 
contribution(s).');
diff --git a/sites/default/enabled_modules b/sites/default/enabled_modules
index 51a71fa..ed5b14f 100644
--- a/sites/default/enabled_modules
+++ b/sites/default/enabled_modules
@@ -8,7 +8,6 @@
 ctools
 environment_indicator
 exchange_rates
-ganglia_reporter
 globalcollect_audit
 ingenico_audit
 large_donation

-- 
To view, visit https://gerrit.wikimedia.org/r/379806
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib527b1171d69ea5dd29d04a624420bd4d42b14cd
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Eileen <emcnaugh...@wikimedia.org>
Gerrit-Reviewer: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org>
Gerrit-Reviewer: Mepps <me...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to