forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...onitoring/src/main/java/org/kie/kogito/serverless/workflow/monitoring/ArrayStoreMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.kie.kogito.serverless.workflow.monitoring; | ||
|
||
public enum ArrayStoreMode { | ||
STRING, | ||
MULTI_PARAM | ||
} |
64 changes: 52 additions & 12 deletions
64
...a/org/kie/kogito/serverless/workflow/monitoring/SonataFlowMetricProcessEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,90 @@ | ||
/* | ||
* 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.kie.kogito.serverless.workflow.monitoring; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.kie.api.event.process.ProcessStartedEvent; | ||
import org.kie.kogito.KogitoGAV; | ||
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; | ||
import org.kie.kogito.monitoring.core.common.process.MetricsProcessEventListener; | ||
import org.kie.kogito.serverless.workflow.SWFConstants; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
|
||
public class SonataFlowMetricProcessEventListener extends MetricsProcessEventListener { | ||
|
||
public SonataFlowMetricProcessEventListener(KogitoGAV gav, MeterRegistry meterRegistry) { | ||
private ArrayStoreMode arrayStoreMode; | ||
|
||
public SonataFlowMetricProcessEventListener(KogitoGAV gav, MeterRegistry meterRegistry, ArrayStoreMode arrayStoreMode) { | ||
super("sonataflow-process-monitoring-listener", gav, meterRegistry); | ||
this.arrayStoreMode = arrayStoreMode; | ||
} | ||
|
||
@Override | ||
public void beforeProcessStarted(ProcessStartedEvent event) { | ||
final KogitoProcessInstance processInstance = (KogitoProcessInstance) event.getProcessInstance(); | ||
Object node = processInstance.getVariables().get(SWFConstants.DEFAULT_WORKFLOW_VAR); | ||
if (node instanceof ObjectNode) { | ||
registerObject(processInstance.getProcessId(), (ObjectNode) node, null); | ||
registerObject(processInstance.getProcessId(), null, (ObjectNode) node); | ||
} | ||
} | ||
|
||
private void registerInputParam(String processId, String key, JsonNode value) { | ||
if (value instanceof ObjectNode) { | ||
registerObject(processId, key, (ObjectNode) value); | ||
} else if (value instanceof ArrayNode) { | ||
registerArray(processId, key, (ArrayNode) value); | ||
} else { | ||
registerValue(processId, key, value.toString()); | ||
} | ||
} | ||
|
||
private void registerObject(String processId, ObjectNode node, String prefix) { | ||
node.fields().forEachRemaining(e -> registerInputParam(processId, e.getKey(), e.getValue(), prefix)); | ||
private void registerObject(String processId, String key, ObjectNode node) { | ||
node.fields().forEachRemaining(e -> registerInputParam(processId, concat(key, e.getKey(), '.'), e.getValue())); | ||
} | ||
|
||
private void registerInputParam(String processId, String key, JsonNode value, String prefix) { | ||
if (value.isObject()) { | ||
registerObject(processId, (ObjectNode) value, concat(prefix, key)); | ||
private void registerArray(String processId, String key, ArrayNode node) { | ||
if (arrayStoreMode == ArrayStoreMode.MULTI_PARAM) { | ||
Iterator<JsonNode> iter = node.elements(); | ||
for (int i = 0; iter.hasNext(); i++) { | ||
registerInputParam(processId, concat(key, "[" + i + "]"), iter.next()); | ||
} | ||
} else { | ||
registerInputParam(processId, concat(prefix, key), value.toString()); | ||
registerValue(processId, key, node.toString()); | ||
} | ||
} | ||
|
||
private String concat(String prefix, String key) { | ||
return prefix == null ? key : prefix + "." + key; | ||
private void registerValue(String processId, String key, String value) { | ||
buildCounter("sonataflow_input_parameters_counter", "Input parameters", processId, Tag.of("param_name", key), Tag.of("param_value", value)).increment(); | ||
} | ||
|
||
private void registerInputParam(String processId, String key, String value) { | ||
buildCounter("sonataflow_input_parameters_counter", "Input parameters", processId, Tag.of("param_name", key), Tag.of("param_value", value)).increment(); | ||
private String concat(String prefix, String key, char prefixChar) { | ||
return prefix == null ? key : prefix + prefixChar + key; | ||
} | ||
|
||
private String concat(String prefix, String key) { | ||
return prefix == null ? key : prefix + key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters