/// <summary>Ctor. </summary>
        /// <param name="engineURI">engine URI</param>
        /// <param name="specification">specifies statement groups</param>
        public StatementMetricRepository(String engineURI,
                                         MetricsReportingConfig specification)
        {
            _specification = specification;
            int numGroups = specification.StatementGroups.Count + 1; // +1 for default group (remaining stmts)

            _groupMetrics = new StatementMetricArray[numGroups];

            // default group
            _groupMetrics[0] = new StatementMetricArray(engineURI, "group-default", 100, false);

            // initialize all other groups
            int countGroups = 1;

            foreach (var entry in specification.StatementGroups)
            {
                MetricsReportingConfig.StmtGroupMetrics config = entry.Value;

                int initialNumStmts = config.NumStatements;
                if (initialNumStmts < 10)
                {
                    initialNumStmts = 10;
                }
                _groupMetrics[countGroups] = new StatementMetricArray(engineURI, "group-" + countGroups, initialNumStmts,
                                                                      config.IsReportInactive);
                countGroups++;
            }

            _statementGroups = new Dictionary <String, int?>();
        }
Beispiel #2
0
        public void TestEnabledDisableStatement()
        {
            var fields     = new String[] { "StatementName" };
            var statements = new EPStatement[5];
            var config     = GetConfig(-1, 10000, true);

            var configOne = new MetricsReportingConfig.StmtGroupMetrics();

            configOne.Interval = -1;
            configOne.AddIncludeLike("%@METRIC%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("metrics", configOne);

            _epService = EPServiceProviderManager.GetProvider("MyURI", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            SendTimer(1000);

            statements[0]         = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "MyStatement@METRIC");
            statements[0].Events += _listenerStmtMetric.Update;

            statements[1] = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=1)#keepall where 2=2", "stmtone");
            SendEvent("E1", 1, CpuGoalOneNano);
            statements[2] = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive>0)#lastevent where 1=1", "stmttwo");
            SendEvent("E2", 1, CpuGoalOneNano);

            SendTimer(11000);
            EPAssertionUtil.AssertPropsPerRow(_listenerStmtMetric.GetNewDataListFlattened(), fields, new Object[][] { new Object[] { "stmtone" }, new Object[] { "stmttwo" } });
            _listenerStmtMetric.Reset();

            SendEvent("E1", 1, CpuGoalOneNano);
            SendTimer(21000);
            EPAssertionUtil.AssertPropsPerRow(_listenerStmtMetric.GetNewDataListFlattened(), fields, new Object[][] { new Object[] { "stmtone" }, new Object[] { "stmttwo" } });
            _listenerStmtMetric.Reset();

            _epService.EPAdministrator.Configuration.SetMetricsReportingStmtDisabled("stmtone");

            SendEvent("E1", 1, CpuGoalOneNano);
            SendTimer(31000);
            EPAssertionUtil.AssertPropsPerRow(_listenerStmtMetric.GetNewDataListFlattened(), fields, new Object[][] { new Object[] { "stmttwo" } });
            _listenerStmtMetric.Reset();

            _epService.EPAdministrator.Configuration.SetMetricsReportingStmtEnabled("stmtone");
            _epService.EPAdministrator.Configuration.SetMetricsReportingStmtDisabled("stmttwo");

            SendEvent("E1", 1, CpuGoalOneNano);
            SendTimer(41000);
            EPAssertionUtil.AssertPropsPerRow(_listenerStmtMetric.GetNewDataListFlattened(), fields, new Object[][] { new Object[] { "stmtone" } });
            _listenerStmtMetric.Reset();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Beispiel #3
0
        public void TestStatementMetrics()
        {
            Configuration config = GetConfig(-1, -1, true);

            // report on all statements every 10 seconds
            MetricsReportingConfig.StmtGroupMetrics configOne = new MetricsReportingConfig.StmtGroupMetrics();
            configOne.Interval = 10000;
            configOne.AddIncludeLike("%cpuStmt%");
            configOne.AddIncludeLike("%wallStmt%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("nonmetrics", configOne);

            // exclude metrics themselves from reporting
            MetricsReportingConfig.StmtGroupMetrics configTwo = new MetricsReportingConfig.StmtGroupMetrics();
            configTwo.Interval = -1;
            configOne.AddExcludeLike("%metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("metrics", configTwo);

            _epService = EPServiceProviderManager.GetProvider("MyURI", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            SendTimer(1000);

            EPStatement[] statements = new EPStatement[5];
            statements[0]         = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "stmt_metrics");
            statements[0].Events += _listener.Update;

            statements[1]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=1)#keepall where MyMetricFunctions.TakeCpuTime(LongPrimitive)", "cpuStmtOne");
            statements[1].Events += _listenerTwo.Update;
            statements[2]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=2)#keepall where MyMetricFunctions.TakeCpuTime(LongPrimitive)", "cpuStmtTwo");
            statements[2].Events += _listenerTwo.Update;
            statements[3]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=3)#keepall where MyMetricFunctions.TakeWallTime(LongPrimitive)", "wallStmtThree");
            statements[3].Events += _listenerTwo.Update;
            statements[4]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=4)#keepall where MyMetricFunctions.TakeWallTime(LongPrimitive)", "wallStmtFour");
            statements[4].Events += _listenerTwo.Update;

            SendEvent("E1", 1, CpuGoalOneNano);
            SendEvent("E2", 2, CpuGoalTwoNano);
            SendEvent("E3", 3, WallGoalOneMsec);
            SendEvent("E4", 4, WallGoalTwoMsec);

            SendTimer(10999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(11000);
            RunAssertion(11000);

            SendEvent("E1", 1, CpuGoalOneNano);
            SendEvent("E2", 2, CpuGoalTwoNano);
            SendEvent("E3", 3, WallGoalOneMsec);
            SendEvent("E4", 4, WallGoalTwoMsec);

            SendTimer(21000);
            RunAssertion(21000);

            // destroy all application stmts
            for (int i = 1; i < 5; i++)
            {
                statements[i].Dispose();
            }
            SendTimer(31000);
            Assert.IsFalse(_listener.IsInvoked);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Beispiel #4
0
        public void TestStatementGroups()
        {
            Configuration config = GetConfig(-1, 7000, true);

            MetricsReportingConfig.StmtGroupMetrics groupOne = new MetricsReportingConfig.StmtGroupMetrics();
            groupOne.Interval = 8000;
            groupOne.AddIncludeLike("%GroupOne%");
            groupOne.IsReportInactive = true;
            config.EngineDefaults.MetricsReporting.AddStmtGroup("GroupOneStatements", groupOne);

            MetricsReportingConfig.StmtGroupMetrics groupTwo = new MetricsReportingConfig.StmtGroupMetrics();
            groupTwo.Interval         = 6000;
            groupTwo.IsDefaultInclude = true;
            groupTwo.AddExcludeLike("%Default%");
            groupTwo.AddExcludeLike("%Metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("GroupTwoNonDefaultStatements", groupTwo);

            MetricsReportingConfig.StmtGroupMetrics groupThree = new MetricsReportingConfig.StmtGroupMetrics();
            groupThree.Interval = -1;
            groupThree.AddIncludeLike("%Metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("MetricsStatements", groupThree);

            _epService = EPServiceProviderManager.GetProvider("MyURI", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            SendTimer(0);

            _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 1)#keepall", "GroupOne");
            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 2)#keepall", "GroupTwo");

            stmt.Subscriber = new SupportSubscriber();
            _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 3)#keepall", "Default");   // no listener

            stmt         = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "StmtMetrics");
            stmt.Events += _listener.Update;

            SendTimer(6000);
            SendTimer(7000);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(8000);
            String[] fields = "StatementName,OutputIStreamCount,NumInput".Split(',');
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            SendTimer(12000);
            SendTimer(14000);
            SendTimer(15999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(16000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            // should report as groupTwo
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            SendTimer(17999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(18000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupTwo", 1L, 1L });

            // should report as groupTwo
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            SendTimer(20999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(21000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "Default", 0L, 1L });

            // turn off group 1
            _epService.EPAdministrator.Configuration.SetMetricsReportingInterval("GroupOneStatements", -1);
            SendTimer(24000);
            Assert.IsFalse(_listener.IsInvoked);

            // turn on group 1
            _epService.EPAdministrator.Configuration.SetMetricsReportingInterval("GroupOneStatements", 1000);
            SendTimer(25000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }