Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Update gradle, formatting changes, add comment
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Hier <[email protected]>
  • Loading branch information
Isaac Hier committed Jul 10, 2018
1 parent 0dd9d9d commit 3e28488
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
3 changes: 2 additions & 1 deletion jaeger-core/src/main/java/com/uber/jaeger/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ private Span setTagAsObject(String key, Object value) {
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
int priority = ((Number) value).intValue();

// Ignore debug spans trying to re-enable debug.
// Ignore debug spans trying to re-enable debug. Otherwise, the throttler
// may deduct credits for a span that is already has a debug flag.
if (context.isDebug() && priority > 0) {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

public class HttpThrottlerProxy implements ThrottlerProxy {
private static final String DEFAULT_HOST_PORT = "localhost:5778";
private static final Type RESPONSE_TYPE = new TypeToken<CreditResponse>() {
}.getType();
private static final Type RESPONSE_TYPE = new TypeToken<CreditResponse>() {}.getType();
private final Gson gson = new Gson();
private final String hostPort;

Expand All @@ -46,11 +45,8 @@ CreditResponse parseJson(String json) throws ThrottlerException {
}

@Override
public CreditResponse getCredits(
int clientId,
String serviceName,
List<String> operations
) throws ThrottlerException {
public CreditResponse getCredits(int clientId, String serviceName, List<String> operations)
throws ThrottlerException {
String jsonString;
try {
StringBuffer operationsQueryBuffer = new StringBuffer();
Expand All @@ -59,9 +55,13 @@ public CreditResponse getCredits(
}
jsonString =
makeGetRequest(
"http://" + hostPort + "/credits?"
+ "uuid=" + URLEncoder.encode(Integer.toString(clientId), "UTF-8")
+ "&service=" + URLEncoder.encode(serviceName, "UTF-8")
"http://"
+ hostPort
+ "/credits?"
+ "uuid="
+ URLEncoder.encode(Integer.toString(clientId), "UTF-8")
+ "&service="
+ URLEncoder.encode(serviceName, "UTF-8")
+ operationsQueryBuffer.toString());
} catch (IOException e) {
throw new ThrottlerException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Uber Technologies, Inc
* Copyright (c) 2016-2018, Uber Technologies, 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright (c) 2018, Uber Technologies, 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.uber.jaeger.throttler;

import com.uber.jaeger.mocks.MockAgentResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
import com.uber.jaeger.metrics.Metrics;
import com.uber.jaeger.throttler.http.CreditResponse;
import com.uber.jaeger.throttler.http.OperationBalance;
import org.glassfish.hk2.api.Operation;

import java.util.Collections;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class RemoteThrottlerTest {
Expand Down Expand Up @@ -52,15 +49,23 @@ public void testFetchCredits() throws Exception {
final int REFRESH_INTERVAL_MS = 10;
throttler = new RemoteThrottler(proxy, metrics, REFRESH_INTERVAL_MS, true);
throttler.isAllowed(OPERATION_NAME);
final List<OperationBalance> operationBalances = Collections.singletonList(new OperationBalance(OPERATION_NAME, 1));
final List<OperationBalance> operationBalances =
Collections.singletonList(new OperationBalance(OPERATION_NAME, 1));
final CreditResponse response = new CreditResponse(operationBalances);
when(proxy.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList())).thenReturn(response).thenReturn(new CreditResponse(Collections.EMPTY_LIST));
verify(proxy, timeout(REFRESH_INTERVAL_MS * 3).times(0)).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList());
when(proxy.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList()))
.thenReturn(response)
.thenReturn(new CreditResponse(Collections.EMPTY_LIST));
verify(proxy, timeout(REFRESH_INTERVAL_MS * 3).times(0))
.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList());

throttler.setProcess(new TracedProcess(SERVICE_NAME, 123, Collections.EMPTY_MAP));
final List<String> operations = Collections.singletonList(OPERATION_NAME);
verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations));
assertTrue(metricsFactory.getCounter("jaeger:throttler_updates", Collections.singletonMap("result", "ok")) > 0);
verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce())
.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations));
assertTrue(
metricsFactory.getCounter(
"jaeger:throttler_updates", Collections.singletonMap("result", "ok"))
> 0);
assertTrue(throttler.isAllowed(OPERATION_NAME));
assertFalse(throttler.isAllowed(OPERATION_NAME));
assertFalse(throttler.isAllowed(OPERATION_NAME));
Expand All @@ -73,7 +78,11 @@ public void testNullResponse() throws Exception {
throttler.setProcess(new TracedProcess(SERVICE_NAME, 123, Collections.EMPTY_MAP));
throttler.isAllowed(OPERATION_NAME);
final List<String> operations = Collections.singletonList(OPERATION_NAME);
verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations));
assertTrue(metricsFactory.getCounter("jaeger:throttler_updates", Collections.singletonMap("result", "err")) > 0);
verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce())
.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations));
assertTrue(
metricsFactory.getCounter(
"jaeger:throttler_updates", Collections.singletonMap("result", "err"))
> 0);
}
}

0 comments on commit 3e28488

Please sign in to comment.