-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIVE-26670: Track every single HTTP request between beeline and hs2
- Loading branch information
1 parent
16ce755
commit 7579d5f
Showing
10 changed files
with
213 additions
and
9 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
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
40 changes: 40 additions & 0 deletions
40
jdbc/src/java/org/apache/hive/jdbc/HttpDefaultResponseInterceptor.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,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.hive.jdbc; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.hive.conf.Constants; | ||
import org.apache.http.HttpException; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
public class HttpDefaultResponseInterceptor extends HttpResponseInterceptorBase { | ||
|
||
@Override | ||
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { | ||
String trackHeader = (String) context.getAttribute(Constants.HTTP_HEADER_REQUEST_TRACK); | ||
if (trackHeader == null) { | ||
return; | ||
} | ||
long elapsed = System.currentTimeMillis() - (long) context.getAttribute(trackHeader + "_TIME"); | ||
LOG.info("Response to {} in {} ms", trackHeader, elapsed); | ||
context.removeAttribute(Constants.HTTP_HEADER_REQUEST_TRACK); | ||
context.removeAttribute(trackHeader + "_TIME"); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
jdbc/src/java/org/apache/hive/jdbc/HttpResponseInterceptorBase.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,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.hive.jdbc; | ||
|
||
import org.apache.http.HttpResponseInterceptor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class HttpResponseInterceptorBase implements HttpResponseInterceptor { | ||
protected final Logger LOG = LoggerFactory.getLogger(getClass()); | ||
} |
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
51 changes: 51 additions & 0 deletions
51
jdbc/src/test/org/apache/hive/jdbc/TestHttpRequestInterceptor.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,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.hive.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import org.apache.hadoop.hive.conf.Constants; | ||
import org.apache.http.HttpException; | ||
import org.apache.http.impl.client.BasicCookieStore; | ||
import org.apache.http.message.BasicHttpRequest; | ||
import org.apache.http.protocol.BasicHttpContext; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestHttpRequestInterceptor { | ||
|
||
@Test | ||
public void testRequestTrackHeader() throws HttpException, IOException { | ||
HttpRequestInterceptorBase requestInterceptor = getInterceptor(); | ||
requestInterceptor.setRequestTrackingEnabled(true); | ||
requestInterceptor.sessionId(() -> "sessionId"); | ||
requestInterceptor.process(new BasicHttpRequest("POST", "uri"), new BasicHttpContext()); | ||
|
||
Assert.assertTrue(requestInterceptor.additionalHeaders.containsKey(Constants.HTTP_HEADER_REQUEST_TRACK)); | ||
Assert.assertEquals("HIVE_sessionId_00000000000000000001", | ||
requestInterceptor.additionalHeaders.get(Constants.HTTP_HEADER_REQUEST_TRACK)); | ||
} | ||
|
||
private HttpRequestInterceptorBase getInterceptor() { | ||
HttpRequestInterceptorBase requestInterceptor = new HttpBasicAuthInterceptor("user", "pass", new BasicCookieStore(), | ||
"cookieName", false, new HashMap<>(), new HashMap<>()); | ||
return requestInterceptor; | ||
} | ||
} |
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