You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2020/12/08 19:57:46 UTC
[airavata] branch prometheus-integration updated: Monitoring API
Server Requests
This is an automated email from the ASF dual-hosted git repository.
dimuthuupe pushed a commit to branch prometheus-integration
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/prometheus-integration by this push:
new a8d5eb9 Monitoring API Server Requests
a8d5eb9 is described below
commit a8d5eb92c336bc6f935d7b5d7f0bf645b082a4f9
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Tue Dec 8 14:57:32 2020 -0500
Monitoring API Server Requests
---
airavata-services/services-security/pom.xml | 5 +++++
.../service/security/interceptor/SecurityInterceptor.java | 4 ++++
.../inventories/scigap/develop/group_vars/all/vars.yml | 4 ++++
.../inventories/scigap/production/group_vars/all/vars.yml | 4 ++++
dev-tools/ansible/roles/api-orch/tasks/main.yml | 11 +++++++++++
.../roles/api-orch/templates/airavata-server.properties.j2 | 7 +++++++
.../org/apache/airavata/patform/monitoring/CountMonitor.java | 12 ++++++++++++
.../src/main/java/org/apache/airavata/server/ServerMain.java | 10 ++++++++++
8 files changed, 57 insertions(+)
diff --git a/airavata-services/services-security/pom.xml b/airavata-services/services-security/pom.xml
index 0f53e2d..d02c71d 100644
--- a/airavata-services/services-security/pom.xml
+++ b/airavata-services/services-security/pom.xml
@@ -102,6 +102,11 @@
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>platform-monitoring</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/airavata-services/services-security/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java b/airavata-services/services-security/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java
index f026557..db44bf0 100644
--- a/airavata-services/services-security/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java
+++ b/airavata-services/services-security/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java
@@ -26,6 +26,7 @@ import org.apache.airavata.common.utils.Constants;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.model.error.AuthorizationException;
import org.apache.airavata.model.security.AuthzToken;
+import org.apache.airavata.patform.monitoring.CountMonitor;
import org.apache.airavata.security.AiravataSecurityException;
import org.apache.airavata.service.security.AiravataSecurityManager;
import org.apache.airavata.service.security.IdentityContext;
@@ -41,14 +42,17 @@ import java.util.Map;
*/
public class SecurityInterceptor implements MethodInterceptor {
private final static Logger logger = LoggerFactory.getLogger(SecurityInterceptor.class);
+ private final static CountMonitor apiRequestCounter = new CountMonitor("api_server_request_counter", "method");
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
+
//obtain the authz token from the input parameters
AuthzToken authzToken = (AuthzToken) invocation.getArguments()[0];
//authorize the API call
HashMap<String, String> metaDataMap = new HashMap();
metaDataMap.put(Constants.API_METHOD_NAME, invocation.getMethod().getName());
+ apiRequestCounter.inc(invocation.getMethod().getName());
authorize(authzToken, metaDataMap);
//set the user identity info in a thread local to be used in downstream execution.
IdentityContext.set(authzToken);
diff --git a/dev-tools/ansible/inventories/scigap/develop/group_vars/all/vars.yml b/dev-tools/ansible/inventories/scigap/develop/group_vars/all/vars.yml
index a54e7c2..723214b 100644
--- a/dev-tools/ansible/inventories/scigap/develop/group_vars/all/vars.yml
+++ b/dev-tools/ansible/inventories/scigap/develop/group_vars/all/vars.yml
@@ -198,6 +198,10 @@ parser_workflow_manager_monitoring_enabled: true
parser_workflow_manager_monitoring_host: "0.0.0.0"
parser_workflow_manager_monitoring_port: 9095
+api_server_monitoring_enabled: true
+api_server_monitoring_host: "0.0.0.0"
+api_server_monitoring_port: 9097
+
# Subnet definitions
iu_subnets:
- "149.163.0.0/16"
diff --git a/dev-tools/ansible/inventories/scigap/production/group_vars/all/vars.yml b/dev-tools/ansible/inventories/scigap/production/group_vars/all/vars.yml
index 6863e25..b69937d 100644
--- a/dev-tools/ansible/inventories/scigap/production/group_vars/all/vars.yml
+++ b/dev-tools/ansible/inventories/scigap/production/group_vars/all/vars.yml
@@ -201,6 +201,10 @@ parser_workflow_manager_monitoring_enabled: true
parser_workflow_manager_monitoring_host: "0.0.0.0"
parser_workflow_manager_monitoring_port: 9095
+api_server_monitoring_enabled: true
+api_server_monitoring_host: "0.0.0.0"
+api_server_monitoring_port: 9097
+
# Subnet definitions
iu_subnets:
- "149.163.0.0/16"
diff --git a/dev-tools/ansible/roles/api-orch/tasks/main.yml b/dev-tools/ansible/roles/api-orch/tasks/main.yml
index 55a69c4..7ecd593 100644
--- a/dev-tools/ansible/roles/api-orch/tasks/main.yml
+++ b/dev-tools/ansible/roles/api-orch/tasks/main.yml
@@ -132,6 +132,17 @@
port: "{{ profile_service_port }}/tcp"
become_user: root
+- name: Openning API Server Monitoring Port
+ firewalld:
+ zone: public
+ permanent: yes
+ state: enabled
+ immediate: yes
+ rich_rule: rule family=ipv4 source address="{{ item }}" port port="{{ api_server_monitoring_port }}" protocol=tcp accept
+ with_items:
+ - "{{ monitoring_subnets }}"
+ become_user: root
+
- name: Install api-orch systemd script
template: src=apiorch.service.j2
dest="{{ api_orch_systemd_unit_file }}"
diff --git a/dev-tools/ansible/roles/api-orch/templates/airavata-server.properties.j2 b/dev-tools/ansible/roles/api-orch/templates/airavata-server.properties.j2
index 21cb2ff..b8da617 100644
--- a/dev-tools/ansible/roles/api-orch/templates/airavata-server.properties.j2
+++ b/dev-tools/ansible/roles/api-orch/templates/airavata-server.properties.j2
@@ -329,3 +329,10 @@ db_event_manager=org.apache.airavata.db.event.manager.DBEventManagerRunner
###########################################################################
thrift.client.pool.abandoned.removal.enabled={{ thrift_client_pool_abandoned_removal_enabled }}
thrift.client.pool.abandoned.removal.logged={{ thrift_client_pool_abandoned_removal_logged }}
+
+###########################################################################
+# Platform Monitoring Configuration
+###########################################################################
+api.server.monitoring.enabled={{ api_server_monitoring_enabled }}
+api.server.monitoring.host={{ api_server_monitoring_host }}
+api.server.monitoring.port={{ api_server_monitoring_port }}
\ No newline at end of file
diff --git a/modules/platform-monitoring/src/main/java/org/apache/airavata/patform/monitoring/CountMonitor.java b/modules/platform-monitoring/src/main/java/org/apache/airavata/patform/monitoring/CountMonitor.java
index acadb37..eca6520 100644
--- a/modules/platform-monitoring/src/main/java/org/apache/airavata/patform/monitoring/CountMonitor.java
+++ b/modules/platform-monitoring/src/main/java/org/apache/airavata/patform/monitoring/CountMonitor.java
@@ -29,11 +29,23 @@ public class CountMonitor {
counter = Counter.build().name(monitorName).help(monitorName).register();
}
+ public CountMonitor(String monitorName, String... labelNames) {
+ counter = Counter.build().name(monitorName).help(monitorName).labelNames(labelNames).register();
+ }
+
public void inc() {
counter.inc();
}
+ public void inc(String... labelValues) {
+ counter.labels(labelValues).inc();
+ }
+
public void inc(double amount) {
counter.inc(amount);
}
+
+ public void inc(double amount, String... labelValues) {
+ counter.labels(labelValues).inc(amount);
+ }
}
diff --git a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
index d2369fb..7d281ca 100644
--- a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
+++ b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
@@ -27,6 +27,7 @@ import org.apache.airavata.common.utils.*;
import org.apache.airavata.common.utils.ApplicationSettings.ShutdownStrategy;
import org.apache.airavata.common.utils.IServer.ServerStatus;
import org.apache.airavata.common.utils.StringUtil.CommandLineParameters;
+import org.apache.airavata.patform.monitoring.MonitoringServer;
import org.apache.commons.cli.ParseException;
import org.apache.zookeeper.server.ServerCnxnFactory;
import org.slf4j.ILoggerFactory;
@@ -173,6 +174,15 @@ public class ServerMain {
ServerSettings.mergeSettingsCommandLineArgs(args);
ServerSettings.setServerRoles(ApplicationSettings.getSetting(SERVERS_KEY, "all").split(","));
+ if (ServerSettings.getBooleanSetting("api.server.monitoring.enabled")) {
+ MonitoringServer monitoringServer = new MonitoringServer(
+ ServerSettings.getSetting("api.server.monitoring.host"),
+ ServerSettings.getIntSetting("api.server.monitoring.port"));
+ monitoringServer.start();
+
+ Runtime.getRuntime().addShutdownHook(new Thread(monitoringServer::stop));
+ }
+
if (ServerSettings.isEnabledKafkaLogging()) {
final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
if (iLoggerFactory instanceof LoggerContext) {