WillemJiang closed pull request #547: [SCB-320] remove custom metrics service
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/547
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/RegistryMetric.java
 
b/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/RegistryMetric.java
index c03ad8f93..b9a919edf 100644
--- 
a/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/RegistryMetric.java
+++ 
b/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/RegistryMetric.java
@@ -29,8 +29,6 @@
 
   private final Map<String, ProducerInvocationMetric> producerMetrics;
 
-  private final Map<String, Double> customMetrics;
-
   public InstanceMetric getInstanceMetric() {
     return instanceMetric;
   }
@@ -43,27 +41,19 @@ public InstanceMetric getInstanceMetric() {
     return producerMetrics;
   }
 
-  public Map<String, Double> getCustomMetrics() {
-    return customMetrics;
-  }
-
   public RegistryMetric(@JsonProperty("instanceMetric") InstanceMetric 
instanceMetric,
       @JsonProperty("consumerMetrics") Map<String, ConsumerInvocationMetric> 
consumerMetrics,
-      @JsonProperty("producerMetrics") Map<String, ProducerInvocationMetric> 
producerMetrics,
-      @JsonProperty("customMetrics") Map<String, Double> customMetrics) {
+      @JsonProperty("producerMetrics") Map<String, ProducerInvocationMetric> 
producerMetrics) {
     this.consumerMetrics = consumerMetrics;
     this.producerMetrics = producerMetrics;
     this.instanceMetric = instanceMetric;
-    this.customMetrics = customMetrics;
   }
 
   public RegistryMetric(SystemMetric systemMetric,
       Map<String, ConsumerInvocationMetric> consumerMetrics,
-      Map<String, ProducerInvocationMetric> producerMetrics,
-      Map<String, Double> customMetrics) {
+      Map<String, ProducerInvocationMetric> producerMetrics) {
     this.consumerMetrics = consumerMetrics;
     this.producerMetrics = producerMetrics;
-    this.customMetrics = customMetrics;
 
     ConsumerInvocationMetric instanceConsumerInvocationMetric = new 
ConsumerInvocationMetric("instance",
         MetricsConst.INSTANCE_CONSUMER_PREFIX,
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/CounterService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/CounterService.java
deleted file mode 100644
index a67993f83..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/CounterService.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-/**
- CounterService is simple service for manage basic counter,Window 
Time-unrelated,always get latest value
- */
-public interface CounterService {
-  void increment(String name);
-
-  void increment(String name, long value);
-
-  void decrement(String name);
-
-  void reset(String name);
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultCounterService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultCounterService.java
deleted file mode 100644
index a41319c6f..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultCounterService.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.springframework.stereotype.Component;
-
-import com.netflix.servo.monitor.BasicCounter;
-import com.netflix.servo.monitor.MonitorConfig;
-
-@Component
-public class DefaultCounterService implements CounterService {
-
-  private final Map<String, BasicCounter> counters;
-
-  public DefaultCounterService() {
-    this.counters = new ConcurrentHashMapEx<>();
-  }
-
-  @Override
-  public void increment(String name) {
-    getCounter(name).increment();
-  }
-
-  @Override
-  public void increment(String name, long value) {
-    getCounter(name).increment(value);
-  }
-
-  @Override
-  public void decrement(String name) {
-    getCounter(name).increment(-1);
-  }
-
-  @Override
-  public void reset(String name) {
-    counters.remove(name);
-    this.increment(name, 0);
-  }
-
-  private BasicCounter getCounter(String name) {
-    return counters.computeIfAbsent(name, n -> new 
BasicCounter(MonitorConfig.builder(n).build()));
-  }
-
-  public Map<String, Double> toMetrics() {
-    Map<String, Double> metrics = new HashMap<>();
-    for (Entry<String, BasicCounter> counter : counters.entrySet()) {
-      metrics.put(counter.getKey(), 
counter.getValue().getValue().doubleValue());
-    }
-    return metrics;
-  }
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultGaugeService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultGaugeService.java
deleted file mode 100644
index 4789ae5ee..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultGaugeService.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.springframework.stereotype.Component;
-
-@Component
-public class DefaultGaugeService implements GaugeService {
-
-  private final Map<String, Double> gauges;
-
-  public DefaultGaugeService() {
-    this.gauges = new ConcurrentHashMapEx<>();
-  }
-
-  @Override
-  public void update(String name, double value) {
-    this.gauges.put(name, value);
-  }
-
-  public Map<String, Double> toMetrics() {
-    return new HashMap<>(gauges);
-  }
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultWindowCounterService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultWindowCounterService.java
deleted file mode 100644
index 6f53ae645..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/DefaultWindowCounterService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.springframework.stereotype.Component;
-
-@Component
-public class DefaultWindowCounterService implements WindowCounterService {
-
-  private final Map<String, WindowCounter> counters;
-
-  public DefaultWindowCounterService() {
-    this.counters = new ConcurrentHashMapEx<>();
-  }
-
-  @Override
-  public void record(String name, long value) {
-    WindowCounter counter = counters.computeIfAbsent(name, WindowCounter::new);
-    counter.update(value);
-  }
-
-  public Map<String, Double> toMetrics(int windowTimeIndex) {
-    Map<String, Double> metrics = new HashMap<>();
-    for (Entry<String, WindowCounter> counter : counters.entrySet()) {
-      metrics.putAll(counter.getValue().toMetric(windowTimeIndex));
-    }
-    return metrics;
-  }
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/GaugeService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/GaugeService.java
deleted file mode 100644
index a69ca4327..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/GaugeService.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-/**
- GaugeService is simple service for manage basic gauge,Window 
Time-unrelated,always get latest value
- */
-public interface GaugeService {
-  void update(String name, double value);
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounter.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounter.java
deleted file mode 100644
index 9684f20c1..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounter.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.netflix.servo.monitor.MaxGauge;
-import com.netflix.servo.monitor.MinGauge;
-import com.netflix.servo.monitor.MonitorConfig;
-import com.netflix.servo.monitor.StepCounter;
-
-public class WindowCounter {
-  private final String name;
-
-  private final StepCounter total;
-
-  private final StepCounter count;
-
-  private final MinGauge min;
-
-  private final MaxGauge max;
-
-  public WindowCounter(String name) {
-    this.name = name;
-    total = new StepCounter(MonitorConfig.builder(name).build());
-    count = new StepCounter(MonitorConfig.builder(name).build());
-    min = new MinGauge(MonitorConfig.builder(name).build());
-    max = new MaxGauge(MonitorConfig.builder(name).build());
-  }
-
-  public void update(long value) {
-    if (value > 0) {
-      total.increment(value);
-      count.increment();
-      max.update(value);
-      min.update(value);
-    }
-  }
-
-  public Map<String, Double> toMetric(int windowTimeIndex) {
-    Map<String, Double> metrics = new HashMap<>();
-    metrics.put(name + ".total", 
this.adjustValue(total.getCount(windowTimeIndex)));
-    metrics.put(name + ".count", 
this.adjustValue(count.getCount(windowTimeIndex)));
-    metrics.put(name + ".max", 
this.adjustValue(max.getValue(windowTimeIndex)));
-    metrics.put(name + ".min", 
this.adjustValue(min.getValue(windowTimeIndex)));
-    double value = count.getCount(windowTimeIndex) == 0 ? 0 :
-        (double) this.total.getCount(windowTimeIndex) / (double) 
this.count.getCount(windowTimeIndex);
-    metrics.put(name + ".average", value);
-    metrics.put(name + ".rate", 
this.adjustValue(total.getValue(windowTimeIndex).doubleValue()));
-    metrics.put(name + ".tps", 
this.adjustValue(count.getValue(windowTimeIndex).doubleValue()));
-    return metrics;
-  }
-
-  //for time-related monitor type, if stop poll value over one window time,
-  //the value may return -1 because servo can't known precise value of 
previous step
-  //so must change to return 0
-  private double adjustValue(double value) {
-    return value < 0 ? 0 : value;
-  }
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounterService.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounterService.java
deleted file mode 100644
index 26ba380c6..000000000
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/custom/WindowCounterService.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.servicecomb.metrics.core.custom;
-
-/**
- WindowCounterService is complex service for manage Window Time-related Step 
Counter,
- It will output total,count,tps,rate,average,max and min
- examples:
- if record four time in one window,and window time = 2000 (2 seconds), like :
- record("Order Amount",100)
- record("Order Amount",200)
- record("Order Amount",300)
- record("Order Amount",400)
-
- Output metrics include:
- Order Amount.total = 1000
- Order Amount.count = 4
- Order Amount.tps = 2           count / time(second)
- Order Amount.rate = 500        total / time(second
- Order Amount.average = 250     total / count
- Order Amount.max = 400
- Order Amount.min = 100
- */
-public interface WindowCounterService {
-  void record(String name, long value);
-}
diff --git 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/monitor/RegistryMonitor.java
 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/monitor/RegistryMonitor.java
index 982e11be2..78be2827e 100644
--- 
a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/monitor/RegistryMonitor.java
+++ 
b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/monitor/RegistryMonitor.java
@@ -24,9 +24,6 @@
 import org.apache.servicecomb.metrics.common.ConsumerInvocationMetric;
 import org.apache.servicecomb.metrics.common.ProducerInvocationMetric;
 import org.apache.servicecomb.metrics.common.RegistryMetric;
-import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
-import org.apache.servicecomb.metrics.core.custom.DefaultGaugeService;
-import org.apache.servicecomb.metrics.core.custom.DefaultWindowCounterService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -39,20 +36,9 @@
 
   private final Map<String, ProducerInvocationMonitor> 
producerInvocationMonitors;
 
-  private final DefaultCounterService counterService;
-
-  private final DefaultGaugeService gaugeService;
-
-  private final DefaultWindowCounterService windowCounterService;
-
   @Autowired
-  public RegistryMonitor(SystemMonitor systemMonitor,
-      DefaultCounterService counterService, DefaultGaugeService gaugeService,
-      DefaultWindowCounterService windowCounterService) {
+  public RegistryMonitor(SystemMonitor systemMonitor) {
     this.systemMonitor = systemMonitor;
-    this.counterService = counterService;
-    this.gaugeService = gaugeService;
-    this.windowCounterService = windowCounterService;
     this.consumerInvocationMonitors = new ConcurrentHashMapEx<>();
     this.producerInvocationMonitors = new ConcurrentHashMapEx<>();
   }
@@ -75,11 +61,6 @@ public RegistryMetric toRegistryMetric(int windowTimeIndex) {
       producerInvocationMetrics.put(monitor.getOperationName(), 
monitor.toMetric(windowTimeIndex));
     }
 
-    Map<String, Double> customMetrics = new 
HashMap<>(counterService.toMetrics());
-    customMetrics.putAll(gaugeService.toMetrics());
-    customMetrics.putAll(windowCounterService.toMetrics(windowTimeIndex));
-
-    return new RegistryMetric(systemMonitor.toMetric(), 
consumerInvocationMetrics, producerInvocationMetrics,
-        customMetrics);
+    return new RegistryMetric(systemMonitor.toMetric(), 
consumerInvocationMetrics, producerInvocationMetrics);
   }
 }
diff --git 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestCustomMetrics.java
 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestCustomMetrics.java
deleted file mode 100644
index b0ac7e19f..000000000
--- 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestCustomMetrics.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.servicecomb.metrics.core;
-
-import org.apache.servicecomb.metrics.common.RegistryMetric;
-import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
-import org.apache.servicecomb.metrics.core.custom.DefaultGaugeService;
-import org.apache.servicecomb.metrics.core.custom.DefaultWindowCounterService;
-import org.apache.servicecomb.metrics.core.monitor.DefaultSystemMonitor;
-import org.apache.servicecomb.metrics.core.monitor.RegistryMonitor;
-import org.apache.servicecomb.metrics.core.monitor.SystemMonitor;
-import org.apache.servicecomb.metrics.core.publish.DefaultDataSource;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestCustomMetrics {
-
-  @Test
-  public void testCustom() throws InterruptedException {
-    SystemMonitor systemMonitor = new DefaultSystemMonitor();
-    DefaultCounterService counterService = new DefaultCounterService();
-    DefaultGaugeService gaugeService = new DefaultGaugeService();
-    DefaultWindowCounterService windowCounterService = new 
DefaultWindowCounterService();
-
-    RegistryMonitor registryMonitor = new RegistryMonitor(systemMonitor, 
counterService, gaugeService,
-        windowCounterService);
-    DefaultDataSource dataSource = new DefaultDataSource(registryMonitor, 
"1000,2000,3000");
-
-    counterService.increment("C1");
-    counterService.increment("C1");
-    counterService.decrement("C1");
-
-    counterService.increment("C2", 99);
-    counterService.reset("C2");
-
-    counterService.increment("C3", 20);
-
-    gaugeService.update("G1", 100);
-    gaugeService.update("G1", 200);
-    gaugeService.update("G2", 150);
-
-    windowCounterService.record("W1", 100);
-    windowCounterService.record("W1", 200);
-    windowCounterService.record("W1", 300);
-    windowCounterService.record("W1", 400);
-
-    //sim lease one window time
-    Thread.sleep(1000);
-
-    RegistryMetric metric = dataSource.getRegistryMetric(1000);
-
-    Assert.assertEquals(1, metric.getCustomMetrics().get("C1").intValue());
-    Assert.assertEquals(0, metric.getCustomMetrics().get("C2").intValue());
-    Assert.assertEquals(20, metric.getCustomMetrics().get("C3").intValue());
-    Assert.assertEquals(200, metric.getCustomMetrics().get("G1").intValue());
-    Assert.assertEquals(150, metric.getCustomMetrics().get("G2").intValue());
-
-    Assert.assertEquals(1000, metric.getCustomMetrics().get("W1.total"), 0);
-    Assert.assertEquals(4, metric.getCustomMetrics().get("W1.count"), 0);
-    Assert.assertEquals(4, metric.getCustomMetrics().get("W1.tps"), 0);
-    Assert.assertEquals(1000, metric.getCustomMetrics().get("W1.rate"), 0);
-    Assert.assertEquals(250, metric.getCustomMetrics().get("W1.average"), 0);
-    Assert.assertEquals(100, metric.getCustomMetrics().get("W1.min"), 0);
-    Assert.assertEquals(400, metric.getCustomMetrics().get("W1.max"), 0);
-  }
-}
diff --git 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
index db400d191..85cf46343 100644
--- 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
+++ 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
@@ -35,9 +35,6 @@
 import org.apache.servicecomb.foundation.common.utils.EventUtils;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.common.RegistryMetric;
-import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
-import org.apache.servicecomb.metrics.core.custom.DefaultGaugeService;
-import org.apache.servicecomb.metrics.core.custom.DefaultWindowCounterService;
 import org.apache.servicecomb.metrics.core.event.DefaultEventListenerManager;
 import 
org.apache.servicecomb.metrics.core.event.dimension.StatusConvertorFactory;
 import org.apache.servicecomb.metrics.core.monitor.DefaultSystemMonitor;
@@ -71,8 +68,7 @@ public void test() throws InterruptedException {
     when(nonHeap.getUsed()).thenReturn(800L);
 
     DefaultSystemMonitor systemMonitor = new 
DefaultSystemMonitor(systemMXBean, threadMXBean, memoryMXBean);
-    RegistryMonitor monitor = new RegistryMonitor(systemMonitor, new 
DefaultCounterService(), new DefaultGaugeService(),
-        new DefaultWindowCounterService());
+    RegistryMonitor monitor = new RegistryMonitor(systemMonitor);
     DefaultDataSource dataSource = new DefaultDataSource(monitor, 
"1000,2000,3000");
 
     List<Long> intervals = dataSource.getAppliedWindowTime();
diff --git 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestPublisher.java
 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestPublisher.java
index 8650fc5e6..bf380581c 100644
--- 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestPublisher.java
+++ 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestPublisher.java
@@ -24,9 +24,6 @@
 import java.util.Map;
 
 import org.apache.servicecomb.metrics.common.RegistryMetric;
-import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
-import org.apache.servicecomb.metrics.core.custom.DefaultGaugeService;
-import org.apache.servicecomb.metrics.core.custom.DefaultWindowCounterService;
 import org.apache.servicecomb.metrics.core.monitor.DefaultSystemMonitor;
 import org.apache.servicecomb.metrics.core.monitor.RegistryMonitor;
 import org.apache.servicecomb.metrics.core.monitor.SystemMonitor;
@@ -40,8 +37,7 @@
   @Test
   public void test() {
     SystemMonitor systemMonitor = new DefaultSystemMonitor();
-    RegistryMonitor registryMonitor = new RegistryMonitor(systemMonitor, new 
DefaultCounterService(),
-        new DefaultGaugeService(), new DefaultWindowCounterService());
+    RegistryMonitor registryMonitor = new RegistryMonitor(systemMonitor);
     DefaultDataSource dataSource = new DefaultDataSource(registryMonitor, 
"1000,2000,3000,3000,2000,1000");
     DefaultMetricsPublisher publisher = new 
DefaultMetricsPublisher(dataSource);
 
diff --git 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
index 844aa0476..897648bb7 100644
--- 
a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
+++ 
b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
@@ -25,9 +25,6 @@
 import org.apache.servicecomb.foundation.common.utils.EventUtils;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.common.RegistryMetric;
-import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
-import org.apache.servicecomb.metrics.core.custom.DefaultGaugeService;
-import org.apache.servicecomb.metrics.core.custom.DefaultWindowCounterService;
 import org.apache.servicecomb.metrics.core.event.DefaultEventListenerManager;
 import 
org.apache.servicecomb.metrics.core.event.dimension.StatusConvertorFactory;
 import org.apache.servicecomb.metrics.core.monitor.DefaultSystemMonitor;
@@ -100,8 +97,7 @@ public void testCodeDimension() throws InterruptedException {
   private RegistryMetric prepare(String outputLevel) throws 
InterruptedException {
     DefaultSystemMonitor systemMonitor = new DefaultSystemMonitor();
 
-    RegistryMonitor monitor = new RegistryMonitor(systemMonitor, new 
DefaultCounterService(), new DefaultGaugeService(),
-        new DefaultWindowCounterService());
+    RegistryMonitor monitor = new RegistryMonitor(systemMonitor);
     DefaultDataSource dataSource = new DefaultDataSource(monitor, 
"1000,2000,3000");
 
     new DefaultEventListenerManager(monitor, new StatusConvertorFactory(), 
outputLevel);
diff --git 
a/metrics/metrics-integration/metrics-prometheus/src/main/java/org/apache/servicecomb/metrics/prometheus/MetricsCollector.java
 
b/metrics/metrics-integration/metrics-prometheus/src/main/java/org/apache/servicecomb/metrics/prometheus/MetricsCollector.java
index 52bab8e11..932863ea1 100644
--- 
a/metrics/metrics-integration/metrics-prometheus/src/main/java/org/apache/servicecomb/metrics/prometheus/MetricsCollector.java
+++ 
b/metrics/metrics-integration/metrics-prometheus/src/main/java/org/apache/servicecomb/metrics/prometheus/MetricsCollector.java
@@ -88,22 +88,9 @@ public MetricsCollector(DataSource dataSource) {
           .add(new MetricFamilySamples("Producer Side", Type.UNTYPED, 
"Producer Side Metrics", producerSamples));
     }
 
-    if (registryMetric.getCustomMetrics().size() != 0) {
-      familySamples.add(getFamilySamples("User Custom", 
registryMetric.getCustomMetrics()));
-    }
-
     return familySamples;
   }
 
-  private <T extends Number> MetricFamilySamples getFamilySamples(String name, 
Map<String, T> metrics) {
-    List<Sample> samples = metrics.entrySet()
-        .stream()
-        .map((entry) -> new Sample(entry.getKey().replace(".", "_"),
-            new ArrayList<>(), new ArrayList<>(), 
entry.getValue().doubleValue()))
-        .collect(Collectors.toList());
-    return new MetricFamilySamples(name, Type.UNTYPED, name + " Metrics", 
samples);
-  }
-
   private List<Sample> convertConsumerMetric(ConsumerInvocationMetric metric) {
     return convertMetricValues(metric.getConsumerLatency().toMap());
   }
diff --git a/samples/custom-business-metrics/pom.xml 
b/samples/custom-business-metrics/pom.xml
deleted file mode 100644
index 90b60da89..000000000
--- a/samples/custom-business-metrics/pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0";
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
-  <parent>
-    <artifactId>samples</artifactId>
-    <groupId>org.apache.servicecomb.samples</groupId>
-    <version>0.6.0-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>custom-business-metrics</artifactId>
-  <name>Java Chassis::Samples::Custom Business Metrics</name>
-
-
-  <dependencies>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>spring-boot-starter-provider</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-validator</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>metrics-core</artifactId>
-    </dependency>
-  </dependencies>
-
-
-</project>
\ No newline at end of file
diff --git 
a/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/CustomMetricsApplication.java
 
b/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/CustomMetricsApplication.java
deleted file mode 100644
index 3826c99a1..000000000
--- 
a/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/CustomMetricsApplication.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.servicecomb.samples.metrics.custom;
-
-import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-@EnableServiceComb
-public class CustomMetricsApplication {
-  public static void main(String[] args) {
-    SpringApplication.run(CustomMetricsApplication.class, args);
-  }
-}
diff --git 
a/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/ShopDemoService.java
 
b/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/ShopDemoService.java
deleted file mode 100644
index 6e5faecd3..000000000
--- 
a/samples/custom-business-metrics/src/main/java/org/apache/servicecomb/samples/metrics/custom/ShopDemoService.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.servicecomb.samples.metrics.custom;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
-import org.apache.servicecomb.metrics.core.custom.CounterService;
-import org.apache.servicecomb.metrics.core.custom.GaugeService;
-import org.apache.servicecomb.metrics.core.custom.WindowCounterService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ShopDemoService {
-
-  private final CounterService counterService;
-
-  private final GaugeService gaugeService;
-
-  private final WindowCounterService windowCounterService;
-
-  //autowire metrics service
-  @Autowired
-  public ShopDemoService(CounterService counterService, GaugeService 
gaugeService,
-      WindowCounterService windowCounterService) {
-    this.counterService = counterService;
-    this.gaugeService = gaugeService;
-    this.windowCounterService = windowCounterService;
-
-    login(null,null);
-  }
-
-  public void login(String name, String password) {
-    counterService.increment("Active User");
-  }
-
-  public void logout(String session) {
-    counterService.decrement("Active User");
-  }
-
-  public void order(double amount) throws InterruptedException {
-    long start = System.currentTimeMillis();
-    //sim  do order process
-    Thread.sleep(100);
-
-    //sim record order process time
-    windowCounterService.record("Order Latency", System.currentTimeMillis() - 
start);
-
-    //plus one
-    windowCounterService.record("Order Count", 1);
-
-    //only support long,please do unit convert ,$99.00 dollar -> $9900 cent, 
$59.99 dollar -> $5999 cent
-    windowCounterService.record("Order Amount", (long) round(amount * 100, 0));
-  }
-
-  public void discount(double value) {
-    //make a discount to Levis Jeans
-
-    //record current Levis Jeans Discount
-    gaugeService.update("Levis Jeans Discount", value);
-  }
-
-  private double round(double value, int places) {
-    if (!Double.isNaN(value)) {
-      BigDecimal decimal = new BigDecimal(value);
-      return decimal.setScale(places, RoundingMode.HALF_UP).doubleValue();
-    }
-    return 0;
-  }
-
-  /*  Output of RegistryMetric.customMetrics :
-   *  Active User
-   *  Order Latency (total,count,tps,rate,average,max,min)
-   *  Order Count (total,count,tps,rate,average,max,min)
-   *  Order Amount (total,count,tps,rate,average,max,min)
-   *  Levis Jeans Discount
-   */
-}
diff --git 
a/samples/custom-business-metrics/src/main/resources/microservice.yaml 
b/samples/custom-business-metrics/src/main/resources/microservice.yaml
deleted file mode 100644
index c1c9226ec..000000000
--- a/samples/custom-business-metrics/src/main/resources/microservice.yaml
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-# all interconnected microservices must belong to an application wth the same 
ID
-APPLICATION_ID: metrics
-service_description:
-# name of the declaring microservice
-  name: metricsCustom
-  version: 0.0.1
-cse:
-  service:
-    registry:
-      address: http://127.0.0.1:30100
-  rest:
-    address: 0.0.0.0:7777
\ No newline at end of file
diff --git 
a/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
 
b/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
index 8571ae770..67f4b4416 100644
--- 
a/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
+++ 
b/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
@@ -156,8 +156,7 @@ public Features getFeatures() {
             new CallMetric("B2", Collections.singletonList(new 
LongMetricValue("B2", 100L, new HashMap<>())),
                 Collections.singletonList(new DoubleMetricValue("B2", 
888.66666, new HashMap<>())))));
 
-    RegistryMetric metric = new RegistryMetric(systemMetric, 
consumerInvocationMetricMap, new HashMap<>(),
-        new HashMap<>());
+    RegistryMetric metric = new RegistryMetric(systemMetric, 
consumerInvocationMetricMap, new HashMap<>());
 
     DataSource dataSource = Mockito.mock(DataSource.class);
     Mockito.when(dataSource.getRegistryMetric()).thenReturn(metric);
diff --git a/samples/pom.xml b/samples/pom.xml
index 2c60a7ced..0590c43cf 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -37,7 +37,6 @@
     <module>metrics-write-file-sample</module>
     <module>metrics-extend-healthcheck</module>
     <module>config-apollo-sample</module>
-    <module>custom-business-metrics</module>
   </modules>
 
   <dependencyManagement>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to