@Test public void testUpdateAddOperation() { PerOperationSamplingParameters perOperationSamplingParameters1 = new PerOperationSamplingParameters(OPERATION, new ProbabilisticSamplingStrategy(SAMPLING_RATE)); List<PerOperationSamplingParameters> parametersList = new ArrayList<>(); parametersList.add(perOperationSamplingParameters1); undertest.update(new OperationSamplingParameters(DEFAULT_SAMPLING_PROBABILITY, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND, parametersList)); assertEquals(1, undertest.getOperationNameToSampler().size()); assertEquals(new GuaranteedThroughputSampler(SAMPLING_RATE, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND), undertest.getOperationNameToSampler().get(OPERATION)); }
public synchronized boolean update(final OperationSamplingParameters strategies) { boolean isUpdated = false; lowerBound = strategies.getDefaultLowerBoundTracesPerSecond(); ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability()); if (!defaultSampler.equals(this.defaultSampler)) { this.defaultSampler = defaultSampler; isUpdated = true; } Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>(); for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) { String operation = strategy.getOperation(); double samplingRate = strategy.getProbabilisticSampling().getSamplingRate(); GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation); if (sampler != null) { isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated; newOpsSamplers.put(operation, sampler); } else { if (newOpsSamplers.size() < maxOperations) { sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound); newOpsSamplers.put(operation, sampler); isUpdated = true; } else { log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations); } } } operationNameToSampler = newOpsSamplers; return isUpdated; }
PerOperationSampler implements Sampler { public synchronized boolean update(final OperationSamplingParameters strategies) { boolean isUpdated = false; lowerBound = strategies.getDefaultLowerBoundTracesPerSecond(); ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability()); if (!defaultSampler.equals(this.defaultSampler)) { this.defaultSampler = defaultSampler; isUpdated = true; } Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>(); for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) { String operation = strategy.getOperation(); double samplingRate = strategy.getProbabilisticSampling().getSamplingRate(); GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation); if (sampler != null) { isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated; newOpsSamplers.put(operation, sampler); } else { if (newOpsSamplers.size() < maxOperations) { sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound); newOpsSamplers.put(operation, sampler); isUpdated = true; } else { log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations); } } } operationNameToSampler = newOpsSamplers; return isUpdated; } }
PerOperationSampler implements Sampler { public synchronized boolean update(final OperationSamplingParameters strategies) { boolean isUpdated = false; lowerBound = strategies.getDefaultLowerBoundTracesPerSecond(); ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability()); if (!defaultSampler.equals(this.defaultSampler)) { this.defaultSampler = defaultSampler; isUpdated = true; } Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>(); for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) { String operation = strategy.getOperation(); double samplingRate = strategy.getProbabilisticSampling().getSamplingRate(); GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation); if (sampler != null) { isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated; newOpsSamplers.put(operation, sampler); } else { if (newOpsSamplers.size() < maxOperations) { sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound); newOpsSamplers.put(operation, sampler); isUpdated = true; } else { log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations); } } } operationNameToSampler = newOpsSamplers; return isUpdated; } PerOperationSampler(int maxOperations, OperationSamplingParameters strategies); }
PerOperationSampler implements Sampler { public synchronized boolean update(final OperationSamplingParameters strategies) { boolean isUpdated = false; lowerBound = strategies.getDefaultLowerBoundTracesPerSecond(); ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability()); if (!defaultSampler.equals(this.defaultSampler)) { this.defaultSampler = defaultSampler; isUpdated = true; } Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>(); for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) { String operation = strategy.getOperation(); double samplingRate = strategy.getProbabilisticSampling().getSamplingRate(); GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation); if (sampler != null) { isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated; newOpsSamplers.put(operation, sampler); } else { if (newOpsSamplers.size() < maxOperations) { sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound); newOpsSamplers.put(operation, sampler); isUpdated = true; } else { log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations); } } } operationNameToSampler = newOpsSamplers; return isUpdated; } PerOperationSampler(int maxOperations, OperationSamplingParameters strategies); synchronized boolean update(final OperationSamplingParameters strategies); @Override synchronized SamplingStatus sample(String operation, long id); @Override synchronized void close(); }
PerOperationSampler implements Sampler { public synchronized boolean update(final OperationSamplingParameters strategies) { boolean isUpdated = false; lowerBound = strategies.getDefaultLowerBoundTracesPerSecond(); ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability()); if (!defaultSampler.equals(this.defaultSampler)) { this.defaultSampler = defaultSampler; isUpdated = true; } Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>(); for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) { String operation = strategy.getOperation(); double samplingRate = strategy.getProbabilisticSampling().getSamplingRate(); GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation); if (sampler != null) { isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated; newOpsSamplers.put(operation, sampler); } else { if (newOpsSamplers.size() < maxOperations) { sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound); newOpsSamplers.put(operation, sampler); isUpdated = true; } else { log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations); } } } operationNameToSampler = newOpsSamplers; return isUpdated; } PerOperationSampler(int maxOperations, OperationSamplingParameters strategies); synchronized boolean update(final OperationSamplingParameters strategies); @Override synchronized SamplingStatus sample(String operation, long id); @Override synchronized void close();  }