-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ac23990
commit 69a7ed0
Showing
8 changed files
with
291 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
gcs/src/test/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright 2024 Google LLC. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.fs.gcs; | ||
|
||
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.EXCEPTION_COUNT; | ||
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_CLIENT_RATE_LIMIT_COUNT; | ||
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_CLIENT_SIDE_ERROR_COUNT; | ||
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_REQUEST_COUNT; | ||
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_SERVER_SIDE_ERROR_COUNT; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.cloud.hadoop.util.GcsRequestExecutionEvent; | ||
import com.google.cloud.hadoop.util.GoogleCloudStorageEventBus; | ||
import com.google.common.flogger.GoogleLogger; | ||
import io.grpc.Status; | ||
import java.util.Iterator; | ||
import org.apache.hadoop.fs.StorageStatistics.LongStatistic; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class GoogleCloudStorageStatisticsTest { | ||
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); | ||
private GhfsGlobalStorageStatistics subscriber = new GhfsGlobalStorageStatistics(); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
GoogleCloudStorageEventBus.register(subscriber); | ||
} | ||
|
||
@After | ||
public void cleanup() throws Exception { | ||
|
||
GoogleCloudStorageEventBus.unregister(subscriber); | ||
} | ||
|
||
private void verifyStatistics(GhfsGlobalStorageStatistics expectedStats) { | ||
Iterator<LongStatistic> statsIterator = expectedStats.getLongStatistics(); | ||
boolean metricsVerified = true; | ||
while (statsIterator.hasNext()) { | ||
LongStatistic stats = statsIterator.next(); | ||
Long value = subscriber.getLong(stats.getName()); | ||
if (stats.getValue() != value) { | ||
logger.atWarning().log( | ||
"Metric values not matching. for: %s, expected: %d, got: %d", | ||
stats.getName(), stats.getValue(), value); | ||
metricsVerified = false; | ||
break; | ||
} | ||
} | ||
assertThat(metricsVerified).isTrue(); | ||
} | ||
|
||
@Test | ||
public void gcs_requestCounter() throws Exception { | ||
GoogleCloudStorageEventBus.onGcsRequest(new GcsRequestExecutionEvent()); | ||
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); | ||
verifyCounterStats.incrementCounter(GCS_REQUEST_COUNT, 1); | ||
verifyStatistics(verifyCounterStats); | ||
} | ||
|
||
@Test | ||
public void gcs_rateLimitCounter() { | ||
// verify for http event i.e. via Apiary | ||
GoogleCloudStorageEventBus.postOnHttpResponseStatus(429); | ||
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); | ||
verifyCounterStats.incrementCounter(GCS_CLIENT_RATE_LIMIT_COUNT, 1); | ||
verifyCounterStats.incrementCounter(GCS_CLIENT_SIDE_ERROR_COUNT, 1); | ||
verifyStatistics(verifyCounterStats); | ||
|
||
subscriber.reset(); | ||
|
||
// verify for gRPC event i.e. via java-storage | ||
GoogleCloudStorageEventBus.onGrpcStatus(Status.RESOURCE_EXHAUSTED); | ||
verifyStatistics(verifyCounterStats); | ||
} | ||
|
||
@Test | ||
public void gcs_clientSideErrorCounter() { | ||
GoogleCloudStorageEventBus.postOnHttpResponseStatus(404); | ||
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); | ||
verifyCounterStats.incrementCounter(GCS_CLIENT_SIDE_ERROR_COUNT, 1); | ||
verifyStatistics(verifyCounterStats); | ||
|
||
subscriber.reset(); | ||
|
||
// verify for gRPC event i.e. via java-storage | ||
GoogleCloudStorageEventBus.onGrpcStatus(Status.CANCELLED); | ||
verifyStatistics(verifyCounterStats); | ||
} | ||
|
||
@Test | ||
public void gcs_serverSideErrorCounter() { | ||
GoogleCloudStorageEventBus.postOnHttpResponseStatus(503); | ||
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); | ||
verifyCounterStats.incrementCounter(GCS_SERVER_SIDE_ERROR_COUNT, 1); | ||
verifyStatistics(verifyCounterStats); | ||
|
||
subscriber.reset(); | ||
|
||
// verify for gRPC event i.e. via java-storage | ||
GoogleCloudStorageEventBus.onGrpcStatus(Status.INTERNAL); | ||
verifyStatistics(verifyCounterStats); | ||
} | ||
|
||
@Test | ||
public void gcs_ExceptionCounter() { | ||
GoogleCloudStorageEventBus.postOnException(); | ||
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); | ||
verifyCounterStats.incrementCounter(EXCEPTION_COUNT, 1); | ||
verifyStatistics(verifyCounterStats); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageClientGrpcStatisticsInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2024 Google Inc. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.gcsio; | ||
|
||
import com.google.cloud.hadoop.util.GcsRequestExecutionEvent; | ||
import com.google.cloud.hadoop.util.GoogleCloudStorageEventBus; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; | ||
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
import io.grpc.Status; | ||
|
||
/** This is a gRPC interceptor to capture the statistics related to calls made to gcs backend. */ | ||
@VisibleForTesting | ||
public class GoogleCloudStorageClientGrpcStatisticsInterceptor implements ClientInterceptor { | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { | ||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
try { | ||
GoogleCloudStorageEventBus.onGcsRequest(new GcsRequestExecutionEvent()); | ||
} finally { | ||
super.start( | ||
new SimpleForwardingClientCallListener<RespT>(responseListener) { | ||
@Override | ||
public void onClose(Status status, Metadata trailers) { | ||
try { | ||
GoogleCloudStorageEventBus.onGrpcStatus(status); | ||
} finally { | ||
super.onClose(status, trailers); | ||
} | ||
} | ||
}, | ||
headers); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
util/src/main/java/com/google/cloud/hadoop/util/GcsRequestExecutionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 Google LLC. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.util; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
/** This an Event which is published in EvenBus queue whenever a gcs request is created/executed. */ | ||
@VisibleForTesting | ||
public class GcsRequestExecutionEvent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.