Search in sources :

Example 6 with EventSourceStatistics

use of com.linkedin.databus.monitoring.mbean.EventSourceStatistics in project databus by linkedin.

the class TestGoldenGateEventProducer method testGGProducerStats.

@Test
public void testGGProducerStats() throws InvalidConfigException, UnsupportedKeyException, DatabusException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
    short[] sourceIds = new short[] { 505, 506 };
    String[] sourceNames = new String[] { "source1", "source2" };
    PhysicalSourceStaticConfig pssc = buildSimplePssc(sourceIds, sourceNames, "gg:///tmp:xxx");
    long scn = 10;
    DbusEventBufferAppendable mb = createBufMult(pssc);
    // start producer
    GoldenGateEventProducer gg = new GoldenGateEventProducer(pssc, null, mb, null, null);
    Object handleXmlCallbackObject = getHandleXmlCallbackInnerInstance(gg);
    Method method = getOnTransactionEndMethod();
    // generates the updates
    List<String> keys = new ArrayList<String>();
    keys.add("keys1");
    // SCN = 10
    List<TransactionState.PerSourceTransactionalUpdate> dbUpdates = generateUpdates(new short[] { sourceIds[0] }, keys, scn);
    // SCN = 11
    List<TransactionState.PerSourceTransactionalUpdate> dbUpdates1 = generateUpdates(new short[] { sourceIds[1] }, keys, scn + 1);
    // SCN = 12
    List<TransactionState.PerSourceTransactionalUpdate> dbUpdates2 = generateUpdates(new short[] { sourceIds[1] }, keys, scn + 2);
    long timestamp = System.currentTimeMillis() * DbusConstants.NUM_NSECS_IN_MSEC;
    // gg.addEventToBuffer(dbUpdates, new TransactionInfo(0, 0, timestamp, scn));
    // gg.addEventToBuffer(dbUpdates1, new TransactionInfo(0, 0, timestamp+1, scn+1));
    method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates, new TransactionInfo(0, 0, timestamp, scn) });
    method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates1, new TransactionInfo(0, 0, timestamp + 1, scn + 1) });
    // THis is an extra-call but the corresponding events will not be added to EVB.
    // This is needed to flush the events in the above call to EVB
    method.invoke(handleXmlCallbackObject, new Object[] { dbUpdates2, new TransactionInfo(0, 0, timestamp + 1, scn + 2) });
    for (EventSourceStatisticsIface si : gg.getSources()) {
        EventSourceStatistics ss = si.getStatisticsBean();
        LOG.info(si.getSourceName() + ": scn=" + ss.getMaxScn() + ",averageSize=" + ss.getAvgEventSerializedSize() + ",numErrors=" + ss.getNumErrors() + ",totalEvents=" + ss.getNumTotalEvents() + ",averageFactTime=" + ss.getAvgEventFactoryTimeMillisPerEvent() + ",timeSinceDb=" + ss.getTimeSinceLastDBAccess());
        if (si.getSourceId() == 505) {
            Assert.assertEquals(6, ss.getAvgEventSerializedSize());
            Assert.assertEquals(0, ss.getNumErrors());
            Assert.assertEquals(1, ss.getNumTotalEvents());
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // we are not
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // really
            // reading
            Assert.assertEquals(10, ss.getMaxScn());
        }
        if (si.getSourceId() == 506) {
            Assert.assertEquals(6, ss.getAvgEventSerializedSize());
            Assert.assertEquals(0, ss.getNumErrors());
            Assert.assertEquals(1, ss.getNumTotalEvents());
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // we are not
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // really
            // reading
            Assert.assertEquals(11, ss.getMaxScn());
        }
        if (si.getSourceId() == GoldenGateEventProducer.GLOBAL_SOURCE_ID) {
            Assert.assertEquals(6, ss.getAvgEventSerializedSize());
            Assert.assertEquals(0, ss.getNumErrors());
            Assert.assertEquals(2, ss.getNumTotalEvents());
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // we are not
            Assert.assertEquals(0, ss.getAvgEventFactoryTimeMillisPerEvent());
            // really
            // reading
            Assert.assertEquals(11, ss.getMaxScn());
        }
    }
    long approximateTimeSinceLastTransactionMs = System.currentTimeMillis() - timestamp / DbusConstants.NUM_NSECS_IN_MSEC;
    long diff = gg.getParserStats().getTimeSinceLastTransactionMs() - approximateTimeSinceLastTransactionMs;
    // somewhat
    Assert.assertTrue("time diff is too big:" + diff, diff >= 0 && diff < 30);
    // NS)
    return;
}
Also used : PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) DbusEventBufferAppendable(com.linkedin.databus.core.DbusEventBufferAppendable) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EventSourceStatistics(com.linkedin.databus.monitoring.mbean.EventSourceStatistics) EventSourceStatisticsIface(com.linkedin.databus2.producers.db.EventSourceStatisticsIface) TransactionInfo(com.linkedin.databus.monitoring.mbean.GGParserStatistics.TransactionInfo) Test(org.testng.annotations.Test)

Example 7 with EventSourceStatistics

use of com.linkedin.databus.monitoring.mbean.EventSourceStatistics in project databus by linkedin.

the class TestGoldenGateEventProducer method testStats.

private static void testStats(GoldenGateEventProducer gg, EventStatsValues... eventStatsValues) {
    Map<Short, EventStatsValues> eventStatsValuesMap = new HashMap<Short, EventStatsValues>();
    for (EventStatsValues e : eventStatsValues) {
        eventStatsValuesMap.put(e.getSrcId(), e);
    }
    for (EventSourceStatisticsIface si : gg.getSources()) {
        EventSourceStatistics ss = si.getStatisticsBean();
        LOG.info(si.getSourceName() + ": scn=" + ss.getMaxScn() + ",averageSize=" + ss.getAvgEventSerializedSize() + ",numErrors=" + ss.getNumErrors() + ",totalEvents=" + ss.getNumTotalEvents() + ",averageFactTime=" + ss.getAvgEventFactoryTimeMillisPerEvent() + ",timeSinceDb=" + ss.getTimeSinceLastDBAccess());
        EventStatsValues e = eventStatsValuesMap.get(si.getSourceId());
        Assert.assertEquals(e.getAvgEventSize(), ss.getAvgEventSerializedSize());
        Assert.assertEquals(e.getNumErrors(), ss.getNumErrors());
        Assert.assertEquals(e.getNumTotalEvents(), ss.getNumTotalEvents());
        Assert.assertEquals(e.getAvgEventFactoryTimeMillisPerEvent(), ss.getAvgEventFactoryTimeMillisPerEvent());
        Assert.assertEquals(e.getMaxScn(), ss.getMaxScn());
    }
}
Also used : EventSourceStatisticsIface(com.linkedin.databus2.producers.db.EventSourceStatisticsIface) HashMap(java.util.HashMap) EventSourceStatistics(com.linkedin.databus.monitoring.mbean.EventSourceStatistics)

Example 8 with EventSourceStatistics

use of com.linkedin.databus.monitoring.mbean.EventSourceStatistics in project databus by linkedin.

the class RelayStatsAdapter method getEventSourceStat.

protected EventSourceStatistics getEventSourceStat(DbusEventsTotalStats stats) {
    if (stats == null)
        return null;
    long numErrors = stats.getNumHeaderErrEvents() + stats.getNumPayloadErrEvents() + stats.getNumInvalidEvents();
    EventSourceStatistics eventStats = new EventSourceStatistics(_name, (int) stats.getNumDataEvents(), stats.getTimeSinceLastAccess(), stats.getMaxScn(), numErrors, stats.getSizeDataEvents());
    return eventStats;
}
Also used : EventSourceStatistics(com.linkedin.databus.monitoring.mbean.EventSourceStatistics)

Aggregations

EventSourceStatistics (com.linkedin.databus.monitoring.mbean.EventSourceStatistics)8 PartitionFunction (com.linkedin.databus2.producers.PartitionFunction)3 EventSourceStatisticsIface (com.linkedin.databus2.producers.db.EventSourceStatisticsIface)2 ArrayList (java.util.ArrayList)2 DbusEventBufferAppendable (com.linkedin.databus.core.DbusEventBufferAppendable)1 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)1 DbusEventKey (com.linkedin.databus.core.DbusEventKey)1 DbusOpcode (com.linkedin.databus.core.DbusOpcode)1 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)1 TransactionInfo (com.linkedin.databus.monitoring.mbean.GGParserStatistics.TransactionInfo)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 DbUpdateState (com.linkedin.databus2.ggParser.XmlStateMachine.DbUpdateState)1 TransactionState (com.linkedin.databus2.ggParser.XmlStateMachine.TransactionState)1 PerSourceTransactionalUpdate (com.linkedin.databus2.ggParser.XmlStateMachine.TransactionState.PerSourceTransactionalUpdate)1 ConstantPartitionFunction (com.linkedin.databus2.producers.ConstantPartitionFunction)1 EventFactory (com.linkedin.databus2.producers.db.EventFactory)1 EventReaderSummary (com.linkedin.databus2.producers.db.EventReaderSummary)1 GGMonitoredSourceInfo (com.linkedin.databus2.producers.db.GGMonitoredSourceInfo)1 OracleAvroGenericEventFactory (com.linkedin.databus2.producers.db.OracleAvroGenericEventFactory)1 OracleTriggerMonitoredSourceInfo (com.linkedin.databus2.producers.db.OracleTriggerMonitoredSourceInfo)1