import lombok.Setter;
import lombok.Synchronized;
import lombok.ToString;
-import org.onap.policy.drools.metrics.TransMetric;
+import org.onap.policy.drools.metrics.Metric;
import org.slf4j.Logger;
/**
*/
@Synchronized
- public void stat(@NonNull TransMetric trans) {
+ public void stat(@NonNull Metric trans) {
policyExecutedCount++;
if (trans.isSuccess()) {
policyExecutedSuccessCount++;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.ToString;
-import org.onap.policy.drools.metrics.TransMetric;
+import org.onap.policy.drools.metrics.Metric;
/**
* Policy Stats Manager that manages PDP-D statistics.
/**
* stat a new transaction.
*/
- public synchronized void stat(@NonNull String subGroupName, @NonNull TransMetric transaction) {
+ public synchronized void stat(@NonNull String subGroupName, @NonNull Metric transaction) {
groupStat.stat(transaction);
subgroupStats.computeIfAbsent(subGroupName, key -> new PolicyStats()).stat(transaction);
}
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.metrics.Metric;
-import org.onap.policy.drools.metrics.TransMetric;
import org.onap.policy.drools.policies.DomainMaker;
import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
* @param policyName policy name
* @param transaction transaction
*/
- void transaction(String controllerName, String policyName, TransMetric transaction);
+ void transaction(String controllerName, String policyName, Metric transaction);
}
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.features.PolicyEngineFeatureApiConstants;
import org.onap.policy.drools.metrics.Metric;
-import org.onap.policy.drools.metrics.TransMetric;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.policies.DomainMaker;
}
@Override
- public void transaction(@NonNull String controllerName,
- @NonNull String policyName, @NonNull TransMetric transaction) {
+ public void transaction(@NonNull String controllerName, // NOSONAR placeholder
+ @NonNull String controlLoopName, @NonNull Metric transaction) {
- // will stat on a per policy name that for an admin would
- // be more significant than a controller name.
+ // keeping stats on a per control loop name,
+ // applications must report the controller name too
+ // for completeness and to avoid being modified when/if
+ // the controller name is used for tracking purposes
- getStats().stat(controllerName + "[" + policyName + "]", transaction);
+ getStats().stat(controlLoopName, transaction);
}
@Override
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import org.onap.policy.drools.metrics.TransMetric;
+import org.onap.policy.drools.metrics.Metric;
public class PolicyStatsManagerTest {
PolicyStatsManager stats = new PolicyStatsManager();
assertEquals(0, stats.getGroupStat().getPolicyExecutedCount());
- TransMetric trans = new TransMetric();
+ Metric trans = new Metric();
stats.stat("foo", trans);
stats.stat("blah", trans);
stats.stat("blah", trans);
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import org.onap.policy.drools.metrics.TransMetric;
+import org.onap.policy.drools.metrics.Metric;
public class PolicyStatsTest {
@Test
public void testStat() {
- TransMetric trans1 = createTrans();
+ Metric trans1 = createTrans();
trans1.setSuccess(true);
PolicyStats stats = new PolicyStats();
assertEquals(1, stats.getPolicyExecutedSuccessCount());
assertThat(stats.getBirthTime()).isGreaterThanOrEqualTo(trans1.getStartTime().toEpochMilli());
- TransMetric trans2 = createTrans();
+ Metric trans2 = createTrans();
trans2.setSuccess(false);
trans2.setEndTime(trans2.getStartTime().plusMillis(5));
trans2.setElapsedTime(null);
assertEquals(1, stats.getPolicyExecutedSuccessCount());
assertThat(stats.getBirthTime()).isLessThanOrEqualTo(trans2.getStartTime().toEpochMilli());
- TransMetric trans3 = createTrans();
+ Metric trans3 = createTrans();
trans3.setSuccess(false);
trans3.setEndTime(trans3.getStartTime().plusMillis(9));
trans3.setElapsedTime(null);
assertThat(stats.getBirthTime()).isLessThanOrEqualTo(trans2.getStartTime().toEpochMilli());
}
- private TransMetric createTrans() {
- TransMetric trans = new TransMetric();
+ private Metric createTrans() {
+ Metric trans = new Metric();
trans.setStartTime(null);
trans.setEndTime(trans.getStartTime().plusMillis(1));
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.metrics.Metric;
-import org.onap.policy.drools.metrics.TransMetric;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
assertEquals(0, mgr.getStats().getGroupStat().getPolicyExecutedCount());
assertEquals(0, mgr.getStats().getSubgroupStats().size());
- mgr.transaction("foo", "bar", new TransMetric());
+ mgr.transaction("foo", "bar", new Metric());
assertEquals(1, mgr.getStats().getGroupStat().getPolicyExecutedCount());
assertEquals(1, mgr.getStats().getSubgroupStats().size());
- assertEquals(1, mgr.getStats().getSubgroupStats().get("foo[bar]").getPolicyExecutedFailCount());
+ assertEquals(1, mgr.getStats().getSubgroupStats().get("bar").getPolicyExecutedFailCount());
}
@Test
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.metrics;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-import lombok.ToString;
-
-/**
- * Transaction Metric that models a complete policy transaction.
- */
-
-@Data
-@NoArgsConstructor
-@ToString(callSuper = true)
-@EqualsAndHashCode(callSuper = true)
-public class TransMetric extends Metric {
-}
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.metrics;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import com.openpojo.reflection.PojoClass;
-import com.openpojo.reflection.impl.PojoClassFactory;
-import com.openpojo.validation.Validator;
-import com.openpojo.validation.ValidatorBuilder;
-import com.openpojo.validation.rule.impl.GetterMustExistRule;
-import com.openpojo.validation.rule.impl.SetterMustExistRule;
-import com.openpojo.validation.test.impl.GetterTester;
-import com.openpojo.validation.test.impl.SetterTester;
-import org.junit.Test;
-
-public class TransMetricTest {
-
- @Test
- public void testPojo() {
- PojoClass metric = PojoClassFactory.getPojoClass(TransMetric.class);
- Validator val = ValidatorBuilder
- .create()
- .with(new SetterMustExistRule())
- .with(new GetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
- val.validate(metric);
- }
-
- @Test
- public void testEqualsToString() {
- TransMetric trans1 = new TransMetric();
- TransMetric trans2 = new TransMetric();
-
- assertEquals(trans1, trans2);
-
- trans1.setRequestId(null);
- assertNotEquals(trans1, trans2);
-
- trans1.setRequestId("a");
- trans2.setRequestId("a");
- assertEquals(trans1, trans2);
-
- assertThat(trans1.toString()).startsWith("TransMetric");
- }
-
-}
\ No newline at end of file