use of com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain in project ApplicationInsights-Java by microsoft.
the class ProfilerServiceTest method endToEndAlertTriggerCycle.
void endToEndAlertTriggerCycle(boolean triggerNow, TelemetryItem metricTelemetry, Consumer<TelemetryEventData> assertTelemetry) throws Exception {
AtomicBoolean profileInvoked = new AtomicBoolean(false);
AtomicReference<TelemetryEventData> serviceProfilerIndex = new AtomicReference<>();
String appId = UUID.randomUUID().toString();
ServiceProfilerClientV2 clientV2 = stubClient(triggerNow);
Supplier<String> appIdSupplier = () -> appId;
ServiceProfilerUploader serviceProfilerUploader = getServiceProfilerJfrUpload(clientV2, appIdSupplier);
JfrProfiler jfrProfiler = getJfrDaemon(profileInvoked);
Object monitor = new Object();
TelemetryClient client = spy(TelemetryClient.builder().setCustomDimensions(new HashMap<>()).build());
doAnswer(invocation -> {
TelemetryItem telemetry = invocation.getArgument(0);
MonitorDomain data = telemetry.getData().getBaseData();
if (data instanceof TelemetryEventData) {
if ("ServiceProfilerIndex".equals(((TelemetryEventData) data).getName())) {
serviceProfilerIndex.set((TelemetryEventData) data);
}
synchronized (monitor) {
monitor.notifyAll();
}
}
return null;
}).when(client).trackAsync(any(TelemetryItem.class));
ScheduledExecutorService serviceProfilerExecutorService = Executors.newScheduledThreadPool(2, ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerService"));
ScheduledExecutorService alertServiceExecutorService = Executors.newSingleThreadScheduledExecutor(ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerAlertingService"));
AtomicReference<ProfilerService> service = new AtomicReference<>();
AlertingSubsystem alertService = AlertingServiceFactory.create(alert -> awaitReferenceSet(service).getProfiler().accept(alert), TelemetryObservers.INSTANCE, client, alertServiceExecutorService, new GcEventMonitor.GcEventMonitorConfiguration(GcReportingLevel.ALL));
service.set(new JfrProfilerService(() -> appId, new ServiceProfilerServiceConfig(1, 2, 3, new URL("http://localhost"), null, null, LocalFileSystemUtils.getTempDir()), jfrProfiler, ProfilerServiceInitializer.updateAlertingConfig(alertService), ProfilerServiceInitializer.sendServiceProfilerIndex(client), clientV2, serviceProfilerUploader, serviceProfilerExecutorService).initialize().get());
// Wait up to 10 seconds
for (int i = 0; i < 100; i++) {
TelemetryObservers.INSTANCE.getObservers().forEach(telemetryObserver -> telemetryObserver.accept(metricTelemetry));
synchronized (monitor) {
if (serviceProfilerIndex.get() != null) {
break;
}
monitor.wait(100);
}
}
assertThat(profileInvoked.get()).isTrue();
assertThat(serviceProfilerIndex.get()).isNotNull();
assertThat(serviceProfilerIndex.get().getProperties().get("ArtifactKind")).isEqualTo("Profile");
assertThat(serviceProfilerIndex.get().getProperties().get("EtlFileSessionId")).isEqualTo(timeStamp);
assertThat(serviceProfilerIndex.get().getProperties().get("DataCube")).isEqualTo(appId);
assertThat(serviceProfilerIndex.get().getProperties().get("Extension")).isEqualTo(jfrExtension);
assertThat(serviceProfilerIndex.get().getProperties().get("MachineName")).isEqualTo(machineName);
assertThat(serviceProfilerIndex.get().getProperties().get("ProcessId")).isEqualTo(processId);
assertThat(serviceProfilerIndex.get().getProperties().get("StampId")).isEqualTo(stampId);
assertTelemetry.accept(serviceProfilerIndex.get());
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain in project ApplicationInsights-Java by microsoft.
the class TelemetryClient method trackAsync.
public void trackAsync(TelemetryItem telemetry) {
if (Strings.isNullOrEmpty(instrumentationKey)) {
return;
}
MonitorDomain data = telemetry.getData().getBaseData();
if (data instanceof MetricsData) {
MetricsData metricsData = (MetricsData) data;
if (metricsData.getMetrics().isEmpty()) {
throw new AssertionError("MetricsData has no metric point");
}
MetricDataPoint point = metricsData.getMetrics().get(0);
String metricName = point.getName();
if (!nonFilterableMetricNames.contains(metricName)) {
for (MetricFilter metricFilter : metricFilters) {
if (!metricFilter.matches(metricName)) {
// user configuration filtered out this metric name
return;
}
}
}
if (!Double.isFinite(point.getValue())) {
// breeze doesn't like these values
return;
}
}
if (telemetry.getTime() == null) {
// this is easy to forget when adding new telemetry
throw new AssertionError("telemetry item is missing time");
}
QuickPulseDataCollector.INSTANCE.add(telemetry);
TelemetryObservers.INSTANCE.getObservers().forEach(consumer -> consumer.accept(telemetry));
// only that it was successfully delivered to the next layer
if (data instanceof MetricsData) {
getMetricsChannelBatcher().trackAsync(telemetry);
} else {
getGeneralChannelBatcher().trackAsync(telemetry);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain in project ApplicationInsights-Java by microsoft.
the class AlertingServiceFactory method addObserver.
private static void addObserver(AlertingSubsystem alertingSubsystem, TelemetryObservers telemetryObservers) {
telemetryObservers.addObserver(telemetry -> {
MonitorDomain data = telemetry.getData().getBaseData();
if (!(data instanceof MetricsData)) {
return;
}
MetricDataPoint point = ((MetricsData) data).getMetrics().get(0);
AlertMetricType alertMetricType = null;
if (point.getName().equals(TOTAL_CPU_PC_METRIC_NAME)) {
alertMetricType = AlertMetricType.CPU;
}
if (alertMetricType != null) {
alertingSubsystem.track(alertMetricType, point.getValue());
}
});
}
Aggregations