Skip to content

Commit

Permalink
fix broker metrics names
Browse files Browse the repository at this point in the history
Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
  • Loading branch information
riccardomodanese authored and Coduz committed Jan 27, 2020
1 parent 864a59c commit 6b67b97
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public abstract class AbstractKapuaConverter {
public static final Logger logger = LoggerFactory.getLogger(AbstractKapuaConverter.class);

// metrics
protected static final String METRIC_COMPONENT_NAME = "converter";
protected static final String METRIC_MODULE_NAME = "converter";
protected static final String METRIC_COMPONENT_NAME = "kapua";
protected static final MetricsService METRICS_SERVICE = MetricServiceFactory.getInstance();

private final Counter metricConverterJmsMessage;
Expand All @@ -59,9 +60,9 @@ public abstract class AbstractKapuaConverter {
* Constructor
*/
protected AbstractKapuaConverter() {
metricConverterJmsMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "jms", "messages", "count");
metricConverterJmsErrorMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "jms", "messages", "error", "count");
metricConverterErrorMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "error", "count");
metricConverterJmsMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "jms", "message", "count");
metricConverterJmsErrorMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "jms", "message", "error", "count");
metricConverterErrorMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "kapua_message", "message", "error", "count");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public class DeviceManagementNotificationMessageProcessor extends AbstractProces
private static final DeviceManagementRegistryManagerService DEVICE_MANAGEMENT_REGISTRY_MANAGER_SERVICE = KapuaLocator.getInstance().getService(DeviceManagementRegistryManagerService.class);
private static final JobDeviceManagementOperationManagerService JOB_DEVICE_MANAGEMENT_OPERATION_MANAGER_SERVICE = KapuaLocator.getInstance().getService(JobDeviceManagementOperationManagerService.class);

private static final String METRIC_COMPONENT_NAME = "deviceManagementRegistry";
private static final String METRIC_MODULE_NAME = "device_management_registry";
private static final String METRIC_COMPONENT_NAME = "notification";
private static final String METRIC_PROCESS_QUEUE = "process_queue";

// queues counters
private final Counter metricQueueCommunicationErrorCount;
Expand All @@ -53,9 +55,9 @@ public DeviceManagementNotificationMessageProcessor() {
super("Device Management Notify Processor");
MetricsService metricService = MetricServiceFactory.getInstance();

metricQueueCommunicationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "deviceManagementNotification", "process", "queue", "communication", "error", "count");
metricQueueConfigurationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "deviceManagementNotification", "process", "queue", "configuration", "error", "count");
metricQueueGenericErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "deviceManagementNotification", "process", "queue", "generic", "error", "count");
metricQueueCommunicationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, METRIC_PROCESS_QUEUE, "communication", "error", "count");
metricQueueConfigurationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, METRIC_PROCESS_QUEUE, "configuration", "error", "count");
metricQueueGenericErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, METRIC_PROCESS_QUEUE, "generic", "error", "count");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public List<AuthorizationEntry> connect(KapuaConnectionContext kcc) throws Kapua

kcc.updatePermissions(hasPermissions);

Context loginFindClientIdTimeContext = loginMetric.getFindClientIdTime().time();
Context loginFindDeviceConnectionTimeContext = loginMetric.getFindDeviceConnectionTime().time();
DeviceConnection deviceConnection = KapuaSecurityUtils.doPrivileged(() -> deviceConnectionService.findByClientId(kcc.getScopeId(), kcc.getClientId()));
loginFindClientIdTimeContext.stop();
loginFindDeviceConnectionTimeContext.stop();

// enforce the user-device bound
enforceDeviceConnectionUserBound(KapuaSecurityUtils.doPrivileged(() -> deviceConnectionService.getConfigValues(kcc.getScopeId())), deviceConnection, kcc.getScopeId(), kcc.getUserId());

Context loginFindDevTimeContext = loginMetric.getFindDevTime().time();
Context loginUpdateDeviceConnectionTimeContext = loginMetric.getUpdateDeviceConnectionTime().time();
{
deviceConnection = upsertDeviceConnection(kcc, deviceConnection);
kcc.updateKapuaConnectionId(deviceConnection);
}
loginFindDevTimeContext.stop();
loginUpdateDeviceConnectionTimeContext.stop();

List<AuthorizationEntry> authorizationEntries = buildAuthorizationMap(kcc);
loginNormalUserTimeContext.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class LoginMetric {
private Timer normalUserTime;
private Timer shiroLoginTime;
private Timer checkAccessTime;
private Timer findClientIdTime;
private Timer findDevTime;
private Timer findDeviceConnectionTime;
private Timer updateDeviceConnectionTime;
private Timer shiroLogoutTime;
private Timer sendLoginUpdateMsgTime;
private Timer removeConnectionTime;
Expand All @@ -62,8 +62,8 @@ private LoginMetric() {
normalUserTime = metricsService.getTimer("security", "login", "user", "time", "s");
shiroLoginTime = metricsService.getTimer("security", "login", "shiro", "login", "time", "s");
checkAccessTime = metricsService.getTimer("security", "login", "check_access", "time", "s");
findClientIdTime = metricsService.getTimer("security", "login", "find_client_id", "time", "s");
findDevTime = metricsService.getTimer("security", "login", "find_device", "time", "s");
findDeviceConnectionTime = metricsService.getTimer("security", "login", "find_device_connection", "time", "s");
updateDeviceConnectionTime = metricsService.getTimer("security", "login", "update_device_connection", "time", "s");
shiroLogoutTime = metricsService.getTimer("security", "login", "shiro", "logout", "time", "s");
sendLoginUpdateMsgTime = metricsService.getTimer("security", "login", "send_login_update", "time", "s");
removeConnectionTime = metricsService.getTimer("security", "login", "remove_connection", "time", "s");
Expand Down Expand Up @@ -129,12 +129,12 @@ public Timer getCheckAccessTime() {
return checkAccessTime;
}

public Timer getFindClientIdTime() {
return findClientIdTime;
public Timer getFindDeviceConnectionTime() {
return findDeviceConnectionTime;
}

public Timer getFindDevTime() {
return findDevTime;
public Timer getUpdateDeviceConnectionTime() {
return updateDeviceConnectionTime;
}

public Timer getShiroLogoutTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public class RaiseServiceEventInterceptor implements MethodInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(RaiseServiceEventInterceptor.class);

private static final String MODULE = "commons";
private static final String COMPONENT = "serviceEvent";
private static final String COMPONENT = "service_event";
private static final String ACTION = "event_data_filler";
private static final String COUNT = "count";


private static final MetricsService METRIC_SERVICE = MetricServiceFactory.getInstance();

private Counter wrongIds;
private Counter wrongId;
private Counter wrongEntity;

public RaiseServiceEventInterceptor() {
wrongIds = METRIC_SERVICE.getCounter(MODULE, COMPONENT, ACTION, "wrong_ids", COUNT);
wrongId = METRIC_SERVICE.getCounter(MODULE, COMPONENT, ACTION, "wrong_id", COUNT);
wrongEntity = METRIC_SERVICE.getCounter(MODULE, COMPONENT, ACTION, "wrong_entity", COUNT);
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private void useEntityToFillEvent(ServiceEvent serviceEvent, List<KapuaEntity> e
private void useKapuaIdsToFillEvent(ServiceEvent serviceEvent, List<KapuaId> ids, Class<?>[] implementedClass) {
if (ids.size()>2) {
LOG.warn("Found more than two KapuaId in the parameters! Assuming to use the first two!");
wrongIds.inc();
wrongId.inc();
}
if (ids.size() >= 2) {
serviceEvent.setEntityScopeId(ids.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public final class MessageStoreFacade {

private final Counter metricMessagesAlreadyInTheDatastoreCount;

private static final String METRIC_COMPONENT_NAME = "datastore";

private final MessageStoreMediator mediator;
private final ConfigurationProvider configProvider;
private DatastoreClient client;
Expand All @@ -106,7 +104,7 @@ public MessageStoreFacade(ConfigurationProvider confProvider, MessageStoreMediat
this.mediator = mediator;
client = DatastoreClientFactory.getInstance();
MetricsService metricService = MetricServiceFactory.getInstance();
metricMessagesAlreadyInTheDatastoreCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "already_in_the_datastore", "count");
metricMessagesAlreadyInTheDatastoreCount = metricService.getCounter(MessageStoreServiceImpl.METRIC_MODULE_NAME, MessageStoreServiceImpl.METRIC_COMPONENT_NAME, "store", "messages", "already_in_the_datastore", "count");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
@KapuaProvider
public class MessageStoreServiceImpl extends AbstractKapuaConfigurableService implements MessageStoreService {

protected static final String METRIC_COMPONENT_NAME = "datastore";
public static final String METRIC_MODULE_NAME = "datastore";
public static final String METRIC_COMPONENT_NAME = "driver";

protected static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
// metrics
Expand Down Expand Up @@ -91,17 +92,17 @@ public MessageStoreServiceImpl() throws ClientUnavailableException {
DatastoreMediator.getInstance().setMessageStoreFacade(messageStoreFacade);
// data message
MetricsService metricService = MetricServiceFactory.getInstance();
metricMessageCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "count");
metricCommunicationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "communication", "error", "count");
metricConfigurationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "configuration", "error", "count");
metricGenericErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "generic", "error", "count");
metricValidationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "validation", "error", "count");
metricMessageCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "count");
metricCommunicationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "communication", "error", "count");
metricConfigurationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "configuration", "error", "count");
metricGenericErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "generic", "error", "count");
metricValidationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "validation", "error", "count");
// error messages queues size
metricQueueCommunicationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "communication", "error", "count");
metricQueueConfigurationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "configuration", "error", "count");
metricQueueGenericErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "generic", "error", "count");
metricQueueCommunicationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "queue", "communication", "error", "count");
metricQueueConfigurationErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "queue", "configuration", "error", "count");
metricQueueGenericErrorCount = metricService.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "queue", "generic", "error", "count");
// store timers
metricDataSaveTime = metricService.getTimer(METRIC_COMPONENT_NAME, "datastore", "store", "messages", "time", "s");
metricDataSaveTime = metricService.getTimer(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "store", "messages", "time", "s");
}

@Override
Expand Down

0 comments on commit 6b67b97

Please sign in to comment.