Skip to content

Commit

Permalink
Add minimal concrete implementations of abstract metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Jacobs committed Aug 3, 2015
1 parent dfb2be6 commit 35798bf
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
package com.netflix.hystrix.strategy.metrics.noop;

import com.netflix.hystrix.HystrixCollapserKey;
import com.netflix.hystrix.HystrixCollapserMetrics;
import com.netflix.hystrix.HystrixCollapserProperties;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;

/**
* Not needed for health check - so it's fine to just drop all collapser metrics on the floor if you're not interested in them
*/
public class HystrixCollapserMetricsNoOp extends HystrixCollapserMetrics {

HystrixCollapserMetricsNoOp(HystrixCollapserKey key, HystrixCollapserProperties properties) {
super(key, properties);
}

@Override
public int getBatchSizePercentile(double percentile) {
return 0;
}

@Override
public int getBatchSizeMean() {
return 0;
}

@Override
protected void addBatchSize(int batchSize) {

}

@Override
public int getShardSizePercentile(double percentile) {
return 0;
}

@Override
public int getShardSizeMean() {
return 0;
}

@Override
protected void addShardSize(int shardSize) {

}

@Override
public long getCumulativeCount(HystrixRollingNumberEvent event) {
return 0;
}

@Override
public long getRollingCount(HystrixRollingNumberEvent event) {
return 0;
}

@Override
public long getRollingMax(HystrixRollingNumberEvent event) {
return 0;
}

@Override
protected void addEvent(HystrixRollingNumberEvent event) {

}

@Override
protected void addEventWithValue(HystrixRollingNumberEvent event, long value) {

}

@Override
protected void updateRollingMax(HystrixRollingNumberEvent event, long value) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
package com.netflix.hystrix.strategy.metrics.noop;

import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandMetrics;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
import com.netflix.hystrix.util.HystrixRollingNumber;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;

/**
* We need to track counts accurately to properly calculate circuit health. We can ignore latency, though
*/
public class HystrixCommandMetricsCountsOnly extends HystrixCommandMetrics {

private final HystrixRollingNumber counter;

public HystrixCommandMetricsCountsOnly(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixThreadPoolKey threadPoolKey, HystrixCommandProperties properties, HystrixEventNotifier eventNotifier) {
super(key, commandGroup, threadPoolKey, properties, eventNotifier);
this.counter = new HystrixRollingNumber(properties.metricsRollingStatisticalWindowInMilliseconds().get(), properties.metricsRollingStatisticalWindowBuckets().get());
}

/**
* COUNT measurements that must be implemented
*/


@Override
public long getCumulativeCount(HystrixRollingNumberEvent event) {
return counter.getCumulativeSum(event);
}

@Override
public long getRollingCount(HystrixRollingNumberEvent event) {
return counter.getRollingSum(event);
}

@Override
public long getRollingMax(HystrixRollingNumberEvent event) {
return counter.getRollingMaxValue(event);
}

@Override
protected void addEvent(HystrixRollingNumberEvent event) {
counter.increment(event);
}

@Override
protected void addEventWithValue(HystrixRollingNumberEvent event, long value) {
counter.add(event, value);
}

@Override
protected void updateRollingMax(HystrixRollingNumberEvent event, long value) {
counter.updateRollingMax(event, value);
}

@Override
protected void clear() {
counter.reset();
}

/**
* LATENCY measurements that may be ignored
*/

@Override
public int getExecutionTimePercentile(double percentile) {
return 0;
}

@Override
public int getExecutionTimeMean() {
return 0;
}

@Override
public int getTotalTimePercentile(double percentile) {
return 0;
}

@Override
public int getTotalTimeMean() {
return 0;
}

@Override
protected void addCommandExecutionTime(long duration) {

}

@Override
protected void addUserThreadExecutionTime(long duration) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
package com.netflix.hystrix.strategy.metrics.noop;

import com.netflix.hystrix.HystrixCollapserKey;
import com.netflix.hystrix.HystrixCollapserMetrics;
import com.netflix.hystrix.HystrixCollapserProperties;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandMetrics;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolMetrics;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsCollection;

import java.util.concurrent.ThreadPoolExecutor;

public class HystrixMetricsCollectionMinimal extends HystrixMetricsCollection {

@Override
public HystrixCommandMetrics getCommandMetricsInstance(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixThreadPoolKey threadPoolKey, HystrixCommandProperties properties, HystrixEventNotifier eventNotifier) {
return new HystrixCommandMetricsCountsOnly(key, commandGroup, threadPoolKey, properties, eventNotifier);
}

@Override
public HystrixThreadPoolMetrics getThreadPoolMetricsInstance(HystrixThreadPoolKey key, ThreadPoolExecutor threadPool, HystrixThreadPoolProperties properties) {
return new HystrixThreadPoolMetricsNoOp(key, threadPool, properties);
}

@Override
public HystrixCollapserMetrics getCollapserMetricsInstance(HystrixCollapserKey key, HystrixCollapserProperties properties) {
return new HystrixCollapserMetricsNoOp(key, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
package com.netflix.hystrix.strategy.metrics.noop;

import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolMetrics;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;

import java.util.concurrent.ThreadPoolExecutor;

/**
* Thread pool metrics not used in health checks, so these may be dropped on the floor if you're not interested in them
*/
public class HystrixThreadPoolMetricsNoOp extends HystrixThreadPoolMetrics {

public HystrixThreadPoolMetricsNoOp(HystrixThreadPoolKey key, ThreadPoolExecutor threadPool, HystrixThreadPoolProperties properties) {
super(key, threadPool, properties);
}

@Override
public long getCumulativeCount(HystrixRollingNumberEvent event) {
return 0;
}

@Override
public long getRollingCount(HystrixRollingNumberEvent event) {
return 0;
}

@Override
public long getRollingMax(HystrixRollingNumberEvent event) {
return 0;
}

@Override
protected void addEvent(HystrixRollingNumberEvent event) {

}

@Override
protected void addEventWithValue(HystrixRollingNumberEvent event, long value) {

}

@Override
protected void updateRollingMax(HystrixRollingNumberEvent event, long value) {

}
}

0 comments on commit 35798bf

Please sign in to comment.