You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "andreachild (via GitHub)" <gi...@apache.org> on 2025/02/28 23:02:58 UTC

[PR] Golang driver replace websockets with http [tinkerpop]

andreachild opened a new pull request, #3059:
URL: https://github.com/apache/tinkerpop/pull/3059

   Replaced web sockets with http for Golang driver and removed a lot of code that is no longer applicable for Tinkerpop 4.0. Note that tests are not yet enabled as they will not pass without changes to serialization.
   
   The following was changed as part of conversion from web sockets to http:
   * gorilla ws library replaced with native http library
   * removed docker dependency on gremlin-socket-server
   * connection and connection pooling changed to delegate to native http library
   * protocol and transport interfaces replaced with single concrete http implementations
   
   The following was removed as no longer applicable for Tinkerpop 4.0:
   * sessions
   * request id
   * request processor
   * request op
   * response attributes
   * response meta data
   
   Out of scope for future PRs:
   * response chunk streaming (entire response is processed at once)
   * interceptors (ie. authentication)
   * full http connection configuration
   * serialization/deserialization changes
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#issuecomment-2691720549

   ## [Codecov](https://app.codecov.io/gh/apache/tinkerpop/pull/3059?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 78.01%. Comparing base [(`cfd6889`)](https://app.codecov.io/gh/apache/tinkerpop/commit/cfd68897ea111e3ae7100dbc2f0f7a364fd0ffa5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`e6febaf`)](https://app.codecov.io/gh/apache/tinkerpop/commit/e6febaf9c4c0722701aa1a9f326f2a7e3a1036c6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 140 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #3059      +/-   ##
   ============================================
   + Coverage     77.87%   78.01%   +0.14%     
   - Complexity    13578    13919     +341     
   ============================================
     Files          1015     1019       +4     
     Lines         59308    59933     +625     
     Branches       6835     6950     +115     
   ============================================
   + Hits          46184    46755     +571     
   - Misses        10817    10844      +27     
   - Partials       2307     2334      +27     
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/tinkerpop/pull/3059?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#issuecomment-2726016183

   VOTE +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#issuecomment-2731080430

   VOTE +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on code in PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#discussion_r1996436427


##########
gremlin-go/driver/httpTransporter.go:
##########
@@ -0,0 +1,171 @@
+/*
+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 gremlingo
+
+import (
+	"bytes"
+	"compress/zlib"
+	"encoding/json"
+	"errors"
+	"io"
+	"net/http"
+	"sync"
+)
+
+// TODO decide channel size when chunked response handling is implemented - for now just set to 1
+const responseChannelSizeDefault = 1
+const contentTypeHeader = "content-type"
+
+// httpTransporter responsible for sending and receiving bytes to/from the server
+type httpTransporter struct {
+	url             string
+	isClosed        bool
+	connSettings    *connectionSettings
+	responseChannel chan []byte // receives response bytes from the server
+	httpClient      *http.Client
+	wg              *sync.WaitGroup
+	logHandler      *logHandler
+}
+
+func newHttpTransporter(url string, connSettings *connectionSettings, httpClient *http.Client, logHandler *logHandler) *httpTransporter {
+	wg := &sync.WaitGroup{}
+
+	return &httpTransporter{
+		url:             url,
+		connSettings:    connSettings,
+		responseChannel: make(chan []byte, responseChannelSizeDefault),
+		httpClient:      httpClient,
+		wg:              wg,
+		logHandler:      logHandler,
+	}
+}
+
+// write sends bytes to the server as a POST request and sends received response bytes to the responseChannel
+func (transporter *httpTransporter) write(data []byte) error {
+	resp, err := transporter.sendRequest(data)
+	if err != nil {
+		return err
+	}
+
+	respBytes, err := transporter.readResponse(resp)
+	if err != nil {
+		return err
+	}
+
+	// possible to receive graph-binary or json error response bodies
+	if resp.StatusCode != 200 && resp.Header.Get(contentTypeHeader) != graphBinaryMimeType {
+		return transporter.createResponseError(respBytes, resp)
+	}
+
+	transporter.responseChannel <- respBytes
+	return nil
+}
+
+// read reads bytes from the responseChannel
+func (transporter *httpTransporter) read() ([]byte, error) {
+	msg, ok := <-transporter.responseChannel
+	if !ok {
+		return []byte{}, errors.New("failed to read from response channel")
+	}
+	return msg, nil
+}
+
+// close closes the transporter and its corresponding responseChannel
+func (transporter *httpTransporter) close() {
+	if !transporter.isClosed {
+		if transporter.responseChannel != nil {
+			close(transporter.responseChannel)
+		}
+		transporter.isClosed = true
+	}
+}
+
+func (transporter *httpTransporter) createResponseError(respBytes []byte, resp *http.Response) error {
+	contentType := resp.Header.Get(contentTypeHeader)
+	if contentType == "application/json" {

Review Comment:
   Very small nit: are there no constants for commonly used HTTP values?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#issuecomment-2715095711

   VOTE +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy merged PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on code in PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#discussion_r1980414990


##########
gremlin-go/driver/httpProtocol.go:
##########
@@ -0,0 +1,148 @@
+/*
+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 gremlingo
+
+import (
+	"net/http"
+)
+
+// responsible for serializing and sending requests and then receiving and deserializing responses
+type httpProtocol struct {
+	serializer   serializer
+	logHandler   *logHandler
+	url          string
+	connSettings *connectionSettings
+	httpClient   *http.Client
+}
+
+func newHttpProtocol(handler *logHandler, url string, connSettings *connectionSettings) *httpProtocol {
+	transport := &http.Transport{
+		TLSClientConfig:    connSettings.tlsConfig,
+		MaxConnsPerHost:    0, // TODO
+		IdleConnTimeout:    0, // TODO
+		DisableCompression: !connSettings.enableCompression,
+	}
+
+	httpClient := http.Client{
+		Transport: transport,
+		Timeout:   connSettings.connectionTimeout,
+	}
+
+	httpProt := &httpProtocol{
+		serializer:   newGraphBinarySerializer(handler),
+		logHandler:   handler,
+		url:          url,
+		connSettings: connSettings,
+		httpClient:   &httpClient,
+	}
+	return httpProt
+}
+
+// sends a query request and returns a ResultSet that can be used to obtain query results
+func (protocol *httpProtocol) send(request *request) (ResultSet, error) {
+	rs := newChannelResultSet()
+	bytes, err := protocol.serializer.serializeMessage(request)
+	if err != nil {
+		rs.setError(err)
+		rs.Close()
+		return rs, err
+	}
+
+	// one transport per request
+	transport := NewHttpTransporter(protocol.url, protocol.connSettings, protocol.httpClient, protocol.logHandler)
+
+	// async send request
+	transport.wg.Add(1)
+	go func() {
+		defer transport.wg.Done()
+		err := transport.Write(bytes)
+		if err != nil {
+			rs.setError(err)
+			rs.Close()
+		}
+	}()
+
+	// async receive response
+	transport.wg.Add(1)
+	go func() {
+		defer transport.wg.Done()
+		msg, err := transport.Read()
+		if err != nil {
+			rs.setError(err)
+			rs.Close()
+		} else {
+			err = protocol.receive(rs, msg)
+		}
+		transport.Close()
+	}()
+
+	return rs, err
+}
+
+// receives a binary response message, deserializes, and adds results to the ResultSet
+func (protocol *httpProtocol) receive(rs ResultSet, msg []byte) error {
+	resp, err := protocol.serializer.deserializeMessage(msg)

Review Comment:
   Not all messages return as GraphBinary. It's possible for some errors to still be "application/json". The driver needs to decide what to do by reading the `content-type` header.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Golang driver replace websockets with http [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on code in PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#discussion_r1980409492


##########
gremlin-go/driver/httpTransporter.go:
##########
@@ -0,0 +1,124 @@
+/*
+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 gremlingo
+
+import (
+	"bytes"
+	"compress/zlib"
+	"errors"
+	"io"
+	"net/http"
+	"sync"
+)
+
+// TODO decide channel size when chunked response handling is implemented - for now just set to 1
+const responseChannelSizeDefault = 1
+
+// HttpTransporter responsible for sending and receiving bytes to/from the server
+type HttpTransporter struct {
+	url             string
+	isClosed        bool
+	connSettings    *connectionSettings
+	responseChannel chan []byte // receives response bytes from the server
+	httpClient      *http.Client
+	wg              *sync.WaitGroup
+	logHandler      *logHandler
+}
+
+func NewHttpTransporter(url string, connSettings *connectionSettings, httpClient *http.Client, logHandler *logHandler) *HttpTransporter {
+	wg := &sync.WaitGroup{}
+
+	return &HttpTransporter{
+		url:             url,
+		connSettings:    connSettings,
+		responseChannel: make(chan []byte, responseChannelSizeDefault),
+		httpClient:      httpClient,
+		wg:              wg,
+		logHandler:      logHandler,
+	}
+}
+
+// Write sends bytes to the server as a POST request and sends received response bytes to the responseChannel
+func (transporter *HttpTransporter) Write(data []byte) error {
+	transporter.logHandler.logf(Debug, creatingRequest)
+	req, err := http.NewRequest("POST", transporter.url, bytes.NewBuffer(data))
+	if err != nil {
+		transporter.logHandler.logf(Error, failedToSendRequest, err.Error())
+		return err
+	}
+	req.Header.Set("content-type", graphBinaryMimeType)
+	req.Header.Set("accept", graphBinaryMimeType)
+	if transporter.connSettings.enableUserAgentOnConnect {
+		req.Header.Set(userAgentHeader, userAgent)
+	}
+	if transporter.connSettings.enableCompression {

Review Comment:
   `enableCompression` existed in 3.7 to manage per message deflate in WebSockets, but was removed in master. Maybe this is a setting that also applies to master but I feel like in the vast majority of cases this should just be left on.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org