Skip to content
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

bugfix tracing filter and add samples #271

Merged
merged 7 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions pkg/filter/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
import (
"github.com/apache/dubbo-go-pixiu/pkg/common/constant"
"github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
"github.com/apache/dubbo-go-pixiu/pkg/config"
contexthttp "github.com/apache/dubbo-go-pixiu/pkg/context/http"
)

Expand All @@ -51,28 +50,52 @@ func init() {
}

// tracerFilter is a filter for tracer
type Plugin struct {
}
type (
Plugin struct {
}
TraceFilter struct {
cfg *TraceConfig
}

type TraceFilter struct {
}
// Tracing
TraceConfig struct {
Http Http `yaml:"http" json:"http,omitempty"`
URL string `yaml:"url" json:"url,omitempty"`
Type string `yaml:"type" json:"type,omitempty"`
}

// Tracing
Http struct {
ztelur marked this conversation as resolved.
Show resolved Hide resolved
Name string `yaml:"name"`
Config interface{} `yaml:"config"`
}
)

func (ap *Plugin) Kind() string {
return constant.TracingFilter
}

func (ap *Plugin) CreateFilter() (filter.HttpFilter, error) {
New()
return &TraceFilter{}, nil
return &TraceFilter{cfg: &TraceConfig{}}, nil
}

func (m *TraceFilter) Config() interface{} {
return nil
return m.cfg
}

func (m *TraceFilter) Apply() error {
// init
New()
tc := m.cfg
switch tc.Type {
case TracingType_Jaeger:
tp, err := newTracerProvider(tc.URL)
if err != nil {
log.Fatal(err)
}
otel.SetTracerProvider(tp)
default:
panic("unsupported tracing")
}
return nil
}

Expand Down Expand Up @@ -100,25 +123,6 @@ func newTracerProvider(url string) (*tracesdk.TracerProvider, error) {
return tp, nil
}

// New create tracer filter.
func New() TraceFilter {
tc := config.GetBootstrap().Tracing
switch tc.Type {
case "":
return TraceFilter{}
case TracingType_Jaeger:
tp, err := newTracerProvider(tc.URL)
if err != nil {
log.Fatal(err)
}
otel.SetTracerProvider(tp)
default:
panic("unsupported tracing")
}

return TraceFilter{}
}

// Do execute tracerFilter filter logic.
func (f TraceFilter) Handle(hc *contexthttp.HttpContext) {
spanName := "HTTP " + hc.Request.Method
Expand Down
1 change: 1 addition & 0 deletions pkg/pluginregistry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
_ "github.com/apache/dubbo-go-pixiu/pkg/filter/metric"
_ "github.com/apache/dubbo-go-pixiu/pkg/filter/response"
_ "github.com/apache/dubbo-go-pixiu/pkg/filter/timeout"
_ "github.com/apache/dubbo-go-pixiu/pkg/filter/tracing"

// adapter
_ "github.com/apache/dubbo-go-pixiu/pkg/adapter/dubboregistry"
Expand Down
38 changes: 38 additions & 0 deletions samples/dubbogo/simple/jaeger/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# 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.
#

version: '3'

services:
zookeeper:
image: zookeeper
ports:
- 2181:2181
restart: on-failure

jaeger:
image: jaegertracing/all-in-one:1.26
ports:
- 5775:5775/udp
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 14268:14268
- 14250:14250
105 changes: 105 additions & 0 deletions samples/dubbogo/simple/jaeger/pixiu/api_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# 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.
#
name: pixiu
description: pixiu sample
resources:
- path: '/api/v1/test-dubbo/user'
type: restful
description: user
methods:
- httpVerb: POST
enable: true
timeout: 1000ms
inboundRequest:
requestType: http
integrationRequest:
requestType: dubbo
mappingParams:
- name: requestBody._all
mapTo: 0
mapType: "object"
applicationName: "UserProvider"
interface: "com.dubbogo.pixiu.UserService"
method: "CreateUser"
group: "test"
version: 1.0.0
clusterName: "test_dubbo"
- httpVerb: PUT
enable: true
timeout: 1000ms
inboundRequest:
requestType: http
integrationRequest:
requestType: dubbo
mappingParams:
- name: requestBody._all
mapTo: 0
mapType: "object"
applicationName: "UserProvider"
interface: "com.dubbogo.pixiu.UserService"
method: "UpdateUser"
group: "test"
version: 1.0.0
clusterName: "test_dubbo"
- path: '/api/v1/test-dubbo/user2'
type: restful
description: user
methods:
- httpVerb: PUT
enable: true
timeout: 1000ms
inboundRequest:
requestType: http
integrationRequest:
requestType: dubbo
mappingParams:
- name: requestBody.name
mapTo: 0
mapType: "string"
- name: requestBody.user
mapTo: 1
mapType: "object"
applicationName: "UserProvider"
interface: "com.dubbogo.pixiu.UserService"
method: "UpdateUserByName"
group: "test"
version: 1.0.0
clusterName: "test_dubbo"
# this path is for search
- path: '/api/v1/test-dubbo/userByName'
type: restful
description: user
methods:
- httpVerb: GET
enable: true
timeout: 1000ms
inboundRequest:
requestType: http
integrationRequest:
requestType: dubbo
mappingParams:
- name: queryStrings.name
mapTo: 0
mapType: "string"
applicationName: "UserProvider"
interface: "com.dubbogo.pixiu.UserService"
method: "GetUserByName"
group: "test"
version: 1.0.0
clusterName: "test_dubbo"
55 changes: 55 additions & 0 deletions samples/dubbogo/simple/jaeger/pixiu/conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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.
#
---
static_resources:
listeners:
- name: "net/http"
filter_chains:
- filters:
- name: dgp.filter.httpconnectionmanager
config:
route_config:
routes:
- match:
prefix: "/api/v1"
http_filters:
- name: dgp.filters.tracing
config:
url: http://127.0.0.1:14268/api/traces
type: jaeger
- name: dgp.filter.http.apiconfig
config:
path: $PROJECT_DIR/pixiu/api_config.yaml
- name: dgp.filter.http.dubboproxy
config:
dubboProxyConfig:
registries:
"zookeeper":
protocol: "zookeeper"
timeout: "3s"
address: "127.0.0.1:2181"
username: ""
password: ""
timeout_config:
connect_timeout: 5s
request_timeout: 5s
- name: dgp.filter.http.response
config:
server_name: "test_http_dubbo"
generate_request_id: false
32 changes: 32 additions & 0 deletions samples/dubbogo/simple/jaeger/request.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# 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.
#
ADDRESS="localhost:8881"

API1=$(curl -s -X POST ${ADDRESS}"/api/v1/test-dubbo/user" -d '{"id":"0003","code":3,"name":"dubbogo","age":99}' --header 'Content-Type: application/json')
API2=$(curl -s -X PUT ${ADDRESS}"/api/v1/test-dubbo/user" -d '{"id":"0003","code":3,"name":"dubbogo","age":77}' --header "Content-Type: application/json")
API3=$(curl -s -X PUT ${ADDRESS}"/api/v1/test-dubbo/user2" -d '{"name":"dubbogo","user":{"id":"0003","code":3,"name":"dubbogo","age":88}}' --header "Content-Type: application/json")

ARRAY_API=(${API1} ${API2} ${API3})

for element in ${ARRAY_API[@]}
do
echo ${element}
#QUERY=$(curl -s -X GET ${ADDRESS}"/api/v1/test-dubbo/userByName?name=dubbogo")
#echo ${QUERY}
done
Loading