Java Code Examples for org.pentaho.di.trans.Trans#setGatheringMetrics()

The following examples show how to use org.pentaho.di.trans.Trans#setGatheringMetrics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformationResource.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@GET
@Path( "/prepare/{id : .+}" )
@Produces( { MediaType.APPLICATION_JSON } )
public TransformationStatus prepareTransformation( @PathParam( "id" ) String id ) {
  Trans trans = CarteResource.getTransformation( id );
  try {

    CarteObjectEntry entry = CarteResource.getCarteObjectEntry( id );
    TransConfiguration transConfiguration =
      CarteSingleton.getInstance().getTransformationMap().getConfiguration( entry );
    TransExecutionConfiguration executionConfiguration = transConfiguration.getTransExecutionConfiguration();
    // Set the appropriate logging, variables, arguments, replay date, ...
    // etc.
    trans.setArguments( executionConfiguration.getArgumentStrings() );
    trans.setReplayDate( executionConfiguration.getReplayDate() );
    trans.setSafeModeEnabled( executionConfiguration.isSafeModeEnabled() );
    trans.setGatheringMetrics( executionConfiguration.isGatheringMetrics() );
    trans.injectVariables( executionConfiguration.getVariables() );
    trans.setPreviousResult( executionConfiguration.getPreviousResult() );

    trans.prepareExecution( null );
  } catch ( KettleException e ) {
    e.printStackTrace();
  }
  return getTransformationStatus( id );
}
 
Example 2
Source File: MetricsIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransformation() throws Exception {

  TransMeta transMeta = new TransMeta( "src/it/resources/metrics/simple-test.ktr" );
  transMeta.setGatheringMetrics( true );
  Trans trans = new Trans( transMeta );
  trans.setGatheringMetrics( true );
  trans.execute( null );
  trans.waitUntilFinished();

  LogChannelInterface log = trans.getLogChannel();

  Queue<MetricsSnapshotInterface> snapshotList =
    MetricsRegistry.getInstance().getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  List<MetricsDuration> durationList =
    MetricsUtil.getDuration( log.getLogChannelId(), Metrics.METRIC_TRANSFORMATION_EXECUTION_START );
  assertEquals( 1, durationList.size() );
  MetricsDuration duration = durationList.get( 0 );
  assertTrue( duration.getDuration() >= 20 && duration.getDuration() <= 5000 );
  assertEquals( Long.valueOf( 1L ), duration.getCount() );

  // Get all durations...
  //
  // durationList = MetricsUtil.getDurations(trans.getLogChannelId());

}
 
Example 3
Source File: MetricsIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testDatabaseGetRow() throws Exception {

  MetricsRegistry metricsRegistry = MetricsRegistry.getInstance();

  TransMeta insertTransMeta = new TransMeta( "src/it/resources/metrics/insert-data.ktr" );
  Trans insertTrans = new Trans( insertTransMeta );
  insertTrans.setGatheringMetrics( true );
  insertTrans.execute( null );
  insertTrans.waitUntilFinished();

  LogChannelInterface log = insertTrans.getLogChannel();
  Queue<MetricsSnapshotInterface> snapshotList = metricsRegistry.getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  TransMeta readTransMeta = new TransMeta( "src/it/resources/metrics/read-data.ktr" );
  Trans readTrans = new Trans( readTransMeta );
  readTrans.setGatheringMetrics( true );
  readTrans.execute( null );
  readTrans.waitUntilFinished();

  log = readTrans.getLogChannel();
  snapshotList = metricsRegistry.getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  Long rowCount = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_COUNT );
  assertNotNull( rowCount );
  assertEquals( Long.valueOf( 1001 ), rowCount );

  Long sumTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_SUM_TIME );
  assertNotNull( sumTime );
  assertTrue( sumTime > 0 );

  Long minTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_MIN_TIME );
  assertNotNull( minTime );
  assertTrue( minTime < sumTime );

  Long maxTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_MAX_TIME );
  assertNotNull( maxTime );
  assertTrue( maxTime >= minTime );
}