Search in sources :

Example 11 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class JMXReporterTest method testHistogramReporting.

/**
	 * Tests that histograms are properly reported via the JMXReporter.
	 */
@Test
public void testHistogramReporting() throws Exception {
    MetricRegistry registry = null;
    String histogramName = "histogram";
    try {
        Configuration config = new Configuration();
        config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "jmx_test");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
        registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
        TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
        TestingHistogram histogram = new TestingHistogram();
        metricGroup.histogram(histogramName, histogram);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
        MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
        MBeanAttributeInfo[] attributeInfos = info.getAttributes();
        assertEquals(11, attributeInfos.length);
        assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count"));
        assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean"));
        assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev"));
        assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max"));
        assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min"));
        assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median"));
        assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile"));
    } finally {
        if (registry != null) {
            registry.shutdown();
        }
    }
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MBeanInfo(javax.management.MBeanInfo) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 12 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class MetricRegistryTest method testConfigurableDelimiterForReportersInGroup.

@Test
public void testConfigurableDelimiterForReportersInGroup() {
    Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test1,test2,test3,test4");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_TM, "A.B");
    MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
    List<MetricReporter> reporters = registry.getReporters();
    //test1  reporter
    ((TestReporter8) reporters.get(0)).expectedDelimiter = '_';
    //test2 reporter
    ((TestReporter8) reporters.get(1)).expectedDelimiter = '-';
    //test3 reporter, because 'AA' - not correct delimiter
    ((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER;
    //for test4 reporter use global delimiter
    ((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER;
    TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
    group.counter("C");
    group.close();
    registry.shutdown();
    assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
    assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) Test(org.junit.Test)

Example 13 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class MetricRegistryTest method testConfigurableDelimiter.

@Test
public void testConfigurableDelimiter() {
    Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_SCOPE_DELIMITER, "_");
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_TM, "A.B.C.D.E");
    MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
    TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "host", "id");
    assertEquals("A_B_C_D_E_name", tmGroup.getMetricIdentifier("name"));
    registry.shutdown();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) Test(org.junit.Test)

Example 14 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class MetricQueryServiceTest method testCreateDump.

@Test
public void testCreateDump() throws Exception {
    ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration());
    ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null);
    TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class));
    TestActor testActor = (TestActor) testActorRef.underlyingActor();
    final Counter c = new SimpleCounter();
    final Gauge<String> g = new Gauge<String>() {

        @Override
        public String getValue() {
            return "Hello";
        }
    };
    final Histogram h = new TestingHistogram();
    final Meter m = new Meter() {

        @Override
        public void markEvent() {
        }

        @Override
        public void markEvent(long n) {
        }

        @Override
        public double getRate() {
            return 5;
        }

        @Override
        public long getCount() {
            return 10;
        }
    };
    MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
    final TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
    MetricQueryService.notifyOfAddedMetric(serviceActor, c, "counter", tm);
    MetricQueryService.notifyOfAddedMetric(serviceActor, g, "gauge", tm);
    MetricQueryService.notifyOfAddedMetric(serviceActor, h, "histogram", tm);
    MetricQueryService.notifyOfAddedMetric(serviceActor, m, "meter", tm);
    serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);
    synchronized (testActor.lock) {
        if (testActor.message == null) {
            testActor.lock.wait();
        }
    }
    MetricDumpSerialization.MetricSerializationResult dump = (MetricDumpSerialization.MetricSerializationResult) testActor.message;
    testActor.message = null;
    assertTrue(dump.serializedMetrics.length > 0);
    MetricQueryService.notifyOfRemovedMetric(serviceActor, c);
    MetricQueryService.notifyOfRemovedMetric(serviceActor, g);
    MetricQueryService.notifyOfRemovedMetric(serviceActor, h);
    MetricQueryService.notifyOfRemovedMetric(serviceActor, m);
    serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);
    synchronized (testActor.lock) {
        if (testActor.message == null) {
            testActor.lock.wait();
        }
    }
    MetricDumpSerialization.MetricSerializationResult emptyDump = (MetricDumpSerialization.MetricSerializationResult) testActor.message;
    testActor.message = null;
    assertEquals(0, emptyDump.serializedMetrics.length);
    s.shutdown();
}
Also used : ActorSystem(akka.actor.ActorSystem) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) Histogram(org.apache.flink.metrics.Histogram) Configuration(org.apache.flink.configuration.Configuration) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Meter(org.apache.flink.metrics.Meter) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestActorRef(akka.testkit.TestActorRef) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) Test(org.junit.Test)

Example 15 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class TaskExecutorITCase method testSlotAllocation.

@Test
public void testSlotAllocation() throws Exception {
    TestingFatalErrorHandler testingFatalErrorHandler = new TestingFatalErrorHandler();
    TestingHighAvailabilityServices testingHAServices = new TestingHighAvailabilityServices();
    final Configuration configuration = new Configuration();
    final ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
    final ResourceID taskManagerResourceId = new ResourceID("foobar");
    final UUID rmLeaderId = UUID.randomUUID();
    final TestingLeaderElectionService rmLeaderElectionService = new TestingLeaderElectionService();
    final TestingLeaderRetrievalService rmLeaderRetrievalService = new TestingLeaderRetrievalService();
    final String rmAddress = "rm";
    final String jmAddress = "jm";
    final UUID jmLeaderId = UUID.randomUUID();
    final JobID jobId = new JobID();
    final ResourceProfile resourceProfile = new ResourceProfile(1.0, 1);
    testingHAServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
    testingHAServices.setResourceManagerLeaderRetriever(rmLeaderRetrievalService);
    testingHAServices.setJobMasterLeaderRetriever(jobId, new TestingLeaderRetrievalService(jmAddress, jmLeaderId));
    TestingSerialRpcService rpcService = new TestingSerialRpcService();
    ResourceManagerConfiguration resourceManagerConfiguration = new ResourceManagerConfiguration(Time.milliseconds(500L), Time.milliseconds(500L), Time.minutes(5L));
    SlotManagerFactory slotManagerFactory = new DefaultSlotManager.Factory();
    JobLeaderIdService jobLeaderIdService = new JobLeaderIdService(testingHAServices, rpcService.getScheduledExecutor(), resourceManagerConfiguration.getJobTimeout());
    MetricRegistry metricRegistry = mock(MetricRegistry.class);
    HeartbeatServices heartbeatServices = mock(HeartbeatServices.class, RETURNS_MOCKS);
    final TaskManagerConfiguration taskManagerConfiguration = TaskManagerConfiguration.fromConfiguration(configuration);
    final TaskManagerLocation taskManagerLocation = new TaskManagerLocation(taskManagerResourceId, InetAddress.getLocalHost(), 1234);
    final MemoryManager memoryManager = mock(MemoryManager.class);
    final IOManager ioManager = mock(IOManager.class);
    final NetworkEnvironment networkEnvironment = mock(NetworkEnvironment.class);
    final TaskManagerMetricGroup taskManagerMetricGroup = mock(TaskManagerMetricGroup.class);
    final BroadcastVariableManager broadcastVariableManager = mock(BroadcastVariableManager.class);
    final FileCache fileCache = mock(FileCache.class);
    final TaskSlotTable taskSlotTable = new TaskSlotTable(Arrays.asList(resourceProfile), new TimerService<AllocationID>(scheduledExecutorService, 100L));
    final JobManagerTable jobManagerTable = new JobManagerTable();
    final JobLeaderService jobLeaderService = new JobLeaderService(taskManagerLocation);
    ResourceManager<ResourceID> resourceManager = new StandaloneResourceManager(rpcService, resourceManagerConfiguration, testingHAServices, slotManagerFactory, metricRegistry, jobLeaderIdService, testingFatalErrorHandler);
    TaskExecutor taskExecutor = new TaskExecutor(taskManagerConfiguration, taskManagerLocation, rpcService, memoryManager, ioManager, networkEnvironment, testingHAServices, heartbeatServices, metricRegistry, taskManagerMetricGroup, broadcastVariableManager, fileCache, taskSlotTable, jobManagerTable, jobLeaderService, testingFatalErrorHandler);
    JobMasterGateway jmGateway = mock(JobMasterGateway.class);
    when(jmGateway.registerTaskManager(any(String.class), any(TaskManagerLocation.class), eq(jmLeaderId), any(Time.class))).thenReturn(FlinkCompletableFuture.<RegistrationResponse>completed(new JMTMRegistrationSuccess(taskManagerResourceId, 1234)));
    when(jmGateway.getHostname()).thenReturn(jmAddress);
    rpcService.registerGateway(rmAddress, resourceManager.getSelf());
    rpcService.registerGateway(jmAddress, jmGateway);
    final AllocationID allocationId = new AllocationID();
    final SlotRequest slotRequest = new SlotRequest(jobId, allocationId, resourceProfile);
    final SlotOffer slotOffer = new SlotOffer(allocationId, 0, resourceProfile);
    try {
        resourceManager.start();
        taskExecutor.start();
        // notify the RM that it is the leader
        rmLeaderElectionService.isLeader(rmLeaderId);
        // notify the TM about the new RM leader
        rmLeaderRetrievalService.notifyListener(rmAddress, rmLeaderId);
        Future<RegistrationResponse> registrationResponseFuture = resourceManager.registerJobManager(rmLeaderId, jmLeaderId, jmAddress, jobId);
        RegistrationResponse registrationResponse = registrationResponseFuture.get();
        assertTrue(registrationResponse instanceof JobMasterRegistrationSuccess);
        resourceManager.requestSlot(jmLeaderId, rmLeaderId, slotRequest);
        verify(jmGateway).offerSlots(eq(taskManagerResourceId), (Iterable<SlotOffer>) argThat(Matchers.contains(slotOffer)), eq(jmLeaderId), any(Time.class));
    } finally {
        if (testingFatalErrorHandler.hasExceptionOccurred()) {
            testingFatalErrorHandler.rethrowError();
        }
    }
}
Also used : ResourceManagerConfiguration(org.apache.flink.runtime.resourcemanager.ResourceManagerConfiguration) Configuration(org.apache.flink.configuration.Configuration) TestingLeaderRetrievalService(org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) JobLeaderIdService(org.apache.flink.runtime.resourcemanager.JobLeaderIdService) SlotManagerFactory(org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerFactory) Time(org.apache.flink.api.common.time.Time) StandaloneResourceManager(org.apache.flink.runtime.resourcemanager.StandaloneResourceManager) JobMasterGateway(org.apache.flink.runtime.jobmaster.JobMasterGateway) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) TestingSerialRpcService(org.apache.flink.runtime.rpc.TestingSerialRpcService) UUID(java.util.UUID) RegistrationResponse(org.apache.flink.runtime.registration.RegistrationResponse) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) JMTMRegistrationSuccess(org.apache.flink.runtime.jobmaster.JMTMRegistrationSuccess) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) JobMasterRegistrationSuccess(org.apache.flink.runtime.jobmaster.JobMasterRegistrationSuccess) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) ResourceManagerConfiguration(org.apache.flink.runtime.resourcemanager.ResourceManagerConfiguration) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) FileCache(org.apache.flink.runtime.filecache.FileCache) SlotManagerFactory(org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerFactory) TaskSlotTable(org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)16 Configuration (org.apache.flink.configuration.Configuration)15 Test (org.junit.Test)15 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)13 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)10 MetricReporter (org.apache.flink.metrics.reporter.MetricReporter)6 JobID (org.apache.flink.api.common.JobID)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 Counter (org.apache.flink.metrics.Counter)3 SimpleCounter (org.apache.flink.metrics.SimpleCounter)3 BroadcastVariableManager (org.apache.flink.runtime.broadcast.BroadcastVariableManager)3 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)3 FileCache (org.apache.flink.runtime.filecache.FileCache)3 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)3 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)3 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)3 TaskMetricGroup (org.apache.flink.runtime.metrics.groups.TaskMetricGroup)3 TaskSlotTable (org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable)3 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)3