You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "bossenti (via GitHub)" <gi...@apache.org> on 2023/12/06 13:28:32 UTC
[PR] extend monitoring by adding metrics for adapters
bossenti opened a new pull request, #2283:
URL: https://github.com/apache/streampipes/pull/2283
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<!--
Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
1. If this is your first time, please read our contributor guidelines:
- https://streampipes.apache.org/getinvolved.html
- https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
4. Please write your PR title to summarize what this PR proposes/fixes.
5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar.
6. Be sure to keep the PR description updated to reflect all changes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
8. Make sure tests pass via `mvn clean install`.
9. (Optional) If the contribution is large, please file an Apache ICLA
- http://apache.org/licenses/icla.pdf
-->
### Purpose
<!--
Please clarify what changes you are proposing and describe how those changes will address the issue.
Furthermore, describe potential consequences the changes might have.
-->
While we already expose monitoring metrics for pipelines during the pipeline health check, adapter metrics are missing out so far.
This PR introduces the capability to define metrics for adapters (see `AdapterMetrics`) and expose them via Prometheus during the adapter health check.
For now, this supports just one metric (`adapter_events_published_total`) which tracks the total amount of events published for every adapter.
This can be used, for example, to monitor if all adapters are running.
Here is a screenshot of the metric for two adapters in Prometheus:

### Remarks
<!--
Is there anything left we need to pay attention on?
Are there some references that might be important? E.g. links to Confluence, or discussions
on the mailing list or GitHub.
-->
PR introduces (a) breaking change(s): no
PR introduces (a) deprecation(s): no
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] extend monitoring by adding metrics for adapters
Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #2283:
URL: https://github.com/apache/streampipes/pull/2283#discussion_r1418493705
##########
streampipes-connect-management/src/main/java/org/apache/streampipes/connect/management/management/AdapterMasterManagement.java:
##########
@@ -149,6 +150,10 @@ public void stopStreamAdapter(String elementId) throws AdapterException {
WorkerRestClient.stopStreamAdapter(ad.getSelectedEndpointUrl(), ad);
ExtensionsLogProvider.INSTANCE.reset(elementId);
+
+ // remove the adapter from the metrics manager so that
+ // no metrics for this adapter are exposed anymore
+ AdapterMetricsManager.INSTANCE.getAdapterMetrics().remove(ad.getElementId(), ad.getName());
Review Comment:
I'm in favor of doing so
Didn't want to change the class API directly, but happy to take on since you're with it :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] extend monitoring by adding metrics for adapters
Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on PR #2283:
URL: https://github.com/apache/streampipes/pull/2283#issuecomment-1844833163
@tenthe please review this commit https://github.com/apache/streampipes/pull/2283/commits/61bf68f8e8b52c4d431eda99190f99d0e4958686 carefully
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] extend monitoring by adding metrics for adapters
Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti merged PR #2283:
URL: https://github.com/apache/streampipes/pull/2283
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] extend monitoring by adding metrics for adapters
Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe commented on code in PR #2283:
URL: https://github.com/apache/streampipes/pull/2283#discussion_r1417438266
##########
streampipes-commons/src/test/java/org/apache/streampipes/commons/prometheus/adapter/AdapterMetricsTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.prometheus.adapter;
+
+import org.junit.Test;
+
+import java.util.NoSuchElementException;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertThrows;
+
+public class AdapterMetricsTest {
+
+ @Test
+ public void register() {
+
+ var metrics = new AdapterMetrics();
+ var adapterId = "adapterId";
Review Comment:
Can we use `adapterId` & `adapterNam` as class variables and use it for all the three tests?
##########
streampipes-connect-management/src/main/java/org/apache/streampipes/connect/management/management/AdapterMasterManagement.java:
##########
@@ -149,6 +150,10 @@ public void stopStreamAdapter(String elementId) throws AdapterException {
WorkerRestClient.stopStreamAdapter(ad.getSelectedEndpointUrl(), ad);
ExtensionsLogProvider.INSTANCE.reset(elementId);
+
+ // remove the adapter from the metrics manager so that
+ // no metrics for this adapter are exposed anymore
+ AdapterMetricsManager.INSTANCE.getAdapterMetrics().remove(ad.getElementId(), ad.getName());
Review Comment:
What do you think? Should we inject the AdapterMetricsManager.INSTANCE into the constructor of the class. This will improve the testability of this method.
##########
streampipes-connect-management/src/main/java/org/apache/streampipes/connect/management/management/AdapterMasterManagement.java:
##########
@@ -166,6 +171,9 @@ public void startStreamAdapter(String elementId) throws AdapterException {
// Invoke adapter instance
WorkerRestClient.invokeStreamAdapter(baseUrl, elementId);
+ // register the adapter at the metrics manager so that the AdapterHealthCheck can send metrics
+ AdapterMetricsManager.INSTANCE.getAdapterMetrics().register(ad.getElementId(), ad.getName());
Review Comment:
Same as above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] extend monitoring by adding metrics for adapters
Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #2283:
URL: https://github.com/apache/streampipes/pull/2283#discussion_r1418513508
##########
streampipes-connect-management/src/main/java/org/apache/streampipes/connect/management/management/AdapterMasterManagement.java:
##########
@@ -166,6 +171,9 @@ public void startStreamAdapter(String elementId) throws AdapterException {
// Invoke adapter instance
WorkerRestClient.invokeStreamAdapter(baseUrl, elementId);
+ // register the adapter at the metrics manager so that the AdapterHealthCheck can send metrics
+ AdapterMetricsManager.INSTANCE.getAdapterMetrics().register(ad.getElementId(), ad.getName());
Review Comment:
Done
##########
streampipes-connect-management/src/main/java/org/apache/streampipes/connect/management/management/AdapterMasterManagement.java:
##########
@@ -149,6 +150,10 @@ public void stopStreamAdapter(String elementId) throws AdapterException {
WorkerRestClient.stopStreamAdapter(ad.getSelectedEndpointUrl(), ad);
ExtensionsLogProvider.INSTANCE.reset(elementId);
+
+ // remove the adapter from the metrics manager so that
+ // no metrics for this adapter are exposed anymore
+ AdapterMetricsManager.INSTANCE.getAdapterMetrics().remove(ad.getElementId(), ad.getName());
Review Comment:
Done
##########
streampipes-commons/src/test/java/org/apache/streampipes/commons/prometheus/adapter/AdapterMetricsTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.prometheus.adapter;
+
+import org.junit.Test;
+
+import java.util.NoSuchElementException;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertThrows;
+
+public class AdapterMetricsTest {
+
+ @Test
+ public void register() {
+
+ var metrics = new AdapterMetrics();
+ var adapterId = "adapterId";
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org