You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/01/18 12:27:45 UTC

[GitHub] [skywalking-satellite] EvanLjp commented on a change in pull request #16: feat: add http logging receiver

EvanLjp commented on a change in pull request #16:
URL: https://github.com/apache/skywalking-satellite/pull/16#discussion_r559531062



##########
File path: plugins/receiver/http/receiver.go
##########
@@ -0,0 +1,97 @@
+// Licensed to 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. Apache Software Foundation (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 http
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+
+	logging "skywalking/network/logging/v3"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/pkg/log"
+	http_server "github.com/apache/skywalking-satellite/plugins/server/http"
+	"github.com/apache/skywalking-satellite/protocol/gen-codes/satellite/protocol"
+)
+
+const (
+	Name      = "http-log-receiver"
+	eventName = "http-log-event"
+	timeout   = 5 * time.Second
+)
+
+type Receiver struct {
+	config.CommonFields
+	Server        *http_server.Server
+	OutputChannel chan *protocol.Event
+}
+
+func (r *Receiver) Name() string {
+	return Name
+}
+
+func (r *Receiver) Description() string {
+	return "This is a receiver for SkyWalking http logging format, " +
+		"which is defined at https://github.com/apache/skywalking-data-collect-protocol/blob/master/logging/Logging.proto."
+}
+
+func (r *Receiver) DefaultConfig() string {
+	return ""
+}
+
+func (r *Receiver) RegisterHandler(server interface{}) {
+	r.Server = server.(*http_server.Server)
+	r.OutputChannel = make(chan *protocol.Event)
+	r.Server.Server.Handle(r.Server.URI, httpHandler(r))

Review comment:
       why not config URI config here rather than in the server.

##########
File path: plugins/receiver/http/receiver.go
##########
@@ -0,0 +1,97 @@
+// Licensed to 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. Apache Software Foundation (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 http
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+
+	logging "skywalking/network/logging/v3"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/pkg/log"
+	http_server "github.com/apache/skywalking-satellite/plugins/server/http"
+	"github.com/apache/skywalking-satellite/protocol/gen-codes/satellite/protocol"
+)
+
+const (
+	Name      = "http-log-receiver"
+	eventName = "http-log-event"
+	timeout   = 5 * time.Second
+)
+
+type Receiver struct {
+	config.CommonFields
+	Server        *http_server.Server
+	OutputChannel chan *protocol.Event
+}
+
+func (r *Receiver) Name() string {
+	return Name
+}
+
+func (r *Receiver) Description() string {
+	return "This is a receiver for SkyWalking http logging format, " +
+		"which is defined at https://github.com/apache/skywalking-data-collect-protocol/blob/master/logging/Logging.proto."
+}
+
+func (r *Receiver) DefaultConfig() string {
+	return ""
+}
+
+func (r *Receiver) RegisterHandler(server interface{}) {
+	r.Server = server.(*http_server.Server)
+	r.OutputChannel = make(chan *protocol.Event)
+	r.Server.Server.Handle(r.Server.URI, httpHandler(r))
+}
+
+func httpHandler(r *Receiver) http.Handler {
+	h := http.HandlerFunc(func(rsp http.ResponseWriter, req *http.Request) {
+		b, err := ioutil.ReadAll(req.Body)
+		if err != nil {
+			log.Logger.Errorf("get http body error: %v", err)
+			http.Error(rsp, err.Error(), http.StatusBadRequest)
+			return
+		}
+		var data logging.LogData
+		err = json.Unmarshal(b, &data)

Review comment:
       how about to support protobuf at the same time with a switch config.

##########
File path: plugins/server/http/server.go
##########
@@ -0,0 +1,75 @@
+// Licensed to 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. Apache Software Foundation (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 http
+
+import (
+	"net/http"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/pkg/log"
+)
+
+const Name = "http-server"
+
+type Server struct {
+	config.CommonFields
+	Address string `mapstructure:"address"`
+	URI     string `mapstructure:"uri"`

Review comment:
       please remove it




----------------------------------------------------------------
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.

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