-
Notifications
You must be signed in to change notification settings - Fork 121
Fix ErrorProne warnings and OAuth test timing issues #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ | |
| @Path("/webapp") | ||
| public class GatewayWebAppResource | ||
| { | ||
| private static final LocalDateTime START_TIME = LocalDateTime.now(ZoneId.systemDefault()); | ||
| private final LocalDateTime startTime = LocalDateTime.now(ZoneId.systemDefault()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the errorprone warning on this constant? |
||
| private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); | ||
| private final GatewayBackendManager gatewayBackendManager; | ||
| private final QueryHistoryManager queryHistoryManager; | ||
|
|
@@ -167,7 +167,7 @@ public Response getDistribution(QueryDistributionRequest query) | |
| state -> state.trinoStatus() == TrinoStatus.HEALTHY, | ||
| Collectors.collectingAndThen(Collectors.counting(), Long::intValue))); | ||
| Integer latestHour = query.latestHour(); | ||
| Long ts = System.currentTimeMillis() - (latestHour * 60 * 60 * 1000); | ||
| Long ts = System.currentTimeMillis() - (latestHour * 60 * 60 * 1000L); | ||
| List<DistributionResponse.LineChart> lineChart = queryHistoryManager.findDistribution(ts); | ||
| lineChart.forEach(qh -> qh.setName(urlToNameMap.get(qh.getBackendUrl()))); | ||
| Map<String, List<DistributionResponse.LineChart>> lineChartMap = lineChart.stream().collect(Collectors.groupingBy(DistributionResponse.LineChart::getName)); | ||
|
|
@@ -192,7 +192,7 @@ public Response getDistribution(QueryDistributionRequest query) | |
| distributionResponse.setTotalQueryCount(totalQueryCount); | ||
| distributionResponse.setAverageQueryCountSecond(totalQueryCount / (latestHour * 60d * 60d)); | ||
| distributionResponse.setAverageQueryCountMinute(totalQueryCount / (latestHour * 60d)); | ||
| ZonedDateTime zonedLocalTime = START_TIME.atZone(ZoneId.systemDefault()); | ||
| ZonedDateTime zonedLocalTime = startTime.atZone(ZoneId.systemDefault()); | ||
| ZonedDateTime utcTime = zonedLocalTime.withZoneSameInstant(ZoneOffset.UTC); | ||
| distributionResponse.setStartTime(utcTime.format(formatter)); | ||
| return Response.ok(Result.ok(distributionResponse)).build(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
| import com.google.common.base.Splitter; | ||
| import com.google.common.cache.CacheBuilder; | ||
| import com.google.common.cache.CacheLoader; | ||
| import com.google.common.cache.LoadingCache; | ||
|
|
@@ -54,13 +55,10 @@ public class TrinoRequestUser | |
| public static final String TRINO_USER_HEADER_NAME = "X-Trino-User"; | ||
| public static final String TRINO_UI_TOKEN_NAME = "Trino-UI-Token"; | ||
| public static final String TRINO_SECURE_UI_TOKEN_NAME = "__Secure-Trino-ID-Token"; | ||
|
|
||
| private Optional<String> user = Optional.empty(); | ||
| private Optional<UserInfo> userInfo = Optional.empty(); | ||
|
|
||
| private static final Logger log = Logger.get(TrinoRequestUser.class); | ||
|
|
||
| private final Optional<LoadingCache<String, UserInfo>> userInfoCache; | ||
| private Optional<String> user = Optional.empty(); | ||
| private Optional<UserInfo> userInfo = Optional.empty(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the errorprone warning on this change? |
||
|
|
||
| private TrinoRequestUser(ContainerRequestContext request, String userField, Optional<LoadingCache<String, UserInfo>> userInfoCache) | ||
| { | ||
|
|
@@ -155,11 +153,11 @@ private Optional<String> extractUserFromAuthorizationHeader(String header, Strin | |
|
|
||
| if (header.contains("Basic")) { | ||
| try { | ||
| return Optional.of(new String(Base64.getDecoder().decode(header.split(" ")[1]), StandardCharsets.UTF_8).split(":")[0]); | ||
| return Optional.of(Splitter.on(':').splitToStream(new String(Base64.getDecoder().decode(Splitter.on(' ').splitToStream(header).skip(1).findFirst().get()), StandardCharsets.UTF_8)).findFirst().get()); | ||
| } | ||
| catch (IllegalArgumentException e) { | ||
| log.error(e, "Authorization: Basic header contains invalid base64"); | ||
| log.debug("Invalid header value: " + header.split(" ")[1]); | ||
| log.debug("Invalid header value: " + Splitter.on(' ').splitToStream(header).skip(1).findFirst().get()); | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ void testReadResourceGroup() | |
| assertThat(resourceGroups.get(0).getName()).isEqualTo("admin"); | ||
| assertThat(resourceGroups.get(0).getHardConcurrencyLimit()).isEqualTo(20); | ||
| assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(200); | ||
| assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(Boolean.TRUE); | ||
| assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| assertThat(resourceGroups.get(0).getSoftMemoryLimit()).isEqualTo("80%"); | ||
| } | ||
|
|
||
|
|
@@ -128,21 +128,21 @@ void testUpdateResourceGroup() | |
| assertThat(resourceGroups.get(0).getName()).isEqualTo("admin"); | ||
| assertThat(resourceGroups.get(0).getHardConcurrencyLimit()).isEqualTo(50); | ||
| assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(50); | ||
| assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(Boolean.FALSE); | ||
| assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| assertThat(resourceGroups.get(0).getSoftMemoryLimit()).isEqualTo("20%"); | ||
|
|
||
| assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(2L); | ||
| assertThat(resourceGroups.get(1).getName()).isEqualTo("user"); | ||
| assertThat(resourceGroups.get(1).getHardConcurrencyLimit()).isEqualTo(10); | ||
| assertThat(resourceGroups.get(1).getMaxQueued()).isEqualTo(100); | ||
| assertThat(resourceGroups.get(1).getJmxExport()).isEqualTo(Boolean.TRUE); | ||
| assertThat(resourceGroups.get(1).getJmxExport()).isEqualTo(true); | ||
| assertThat(resourceGroups.get(1).getSoftMemoryLimit()).isEqualTo("50%"); | ||
|
|
||
| assertThat(resourceGroups.get(2).getResourceGroupId()).isEqualTo(3L); | ||
| assertThat(resourceGroups.get(2).getName()).isEqualTo("localization-eng"); | ||
| assertThat(resourceGroups.get(2).getHardConcurrencyLimit()).isEqualTo(50); | ||
| assertThat(resourceGroups.get(2).getMaxQueued()).isEqualTo(70); | ||
| assertThat(resourceGroups.get(2).getJmxExport()).isEqualTo(Boolean.TRUE); | ||
| assertThat(resourceGroups.get(2).getJmxExport()).isEqualTo(true); | ||
| assertThat(resourceGroups.get(2).getSoftMemoryLimit()).isEqualTo("20%"); | ||
| assertThat(resourceGroups.get(2).getSoftConcurrencyLimit()).isEqualTo(Integer.valueOf(20)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md#avoid-var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we can do
Future<?> _ = ...instead of suppressing the unused warning. This is a modern Java way of saying "I don't care about this value".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And anyway, I think
var _should be an exception to the "novar" rule.