[ 
https://issues.apache.org/jira/browse/SCB-937?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16627265#comment-16627265
 ] 

ASF GitHub Bot commented on SCB-937:
------------------------------------

little-cui closed pull request #449: SCB-937 Customizable tracing sample rate
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/449
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/scctl/pkg/plugin/README.md b/scctl/pkg/plugin/README.md
index da9f2db8..c265e2e4 100644
--- a/scctl/pkg/plugin/README.md
+++ b/scctl/pkg/plugin/README.md
@@ -21,7 +21,7 @@ Get the microservices list from ServiceCenter. `service` 
command can be instead
 #### Options
 
 - `domain`(d) domain name, return `default` domain microservices list by 
default.
-- `output`(o) return the complete microservices information(e.g., framework, 
endpoints).
+- `output`(o) support mode `wide`, return the complete microservices 
information(e.g., framework, endpoints).
 - `all-domains` return all domains microservices information.
 
 #### Examples
@@ -56,7 +56,7 @@ Get the instances list from ServiceCenter. `instance` command 
can be instead of
 #### Options
 
 - `domain`(d) domain name, return `default` domain microservices list by 
default.
-- `output`(o) return the complete microservices information(e.g., framework, 
endpoints).
+- `output`(o) support mode `wide`, return the complete microservices 
information(e.g., framework, endpoints).
 - `all-domains` return all domains microservices information.
 
 #### Examples
diff --git a/server/plugin/infra/tracing/buildin/common.go 
b/server/plugin/infra/tracing/buildin/common.go
index 64f410fd..79574442 100644
--- a/server/plugin/infra/tracing/buildin/common.go
+++ b/server/plugin/infra/tracing/buildin/common.go
@@ -25,9 +25,18 @@ import (
        zipkin "github.com/openzipkin/zipkin-go-opentracing"
        "os"
        "path/filepath"
+       "strconv"
        "strings"
 )
 
+const (
+       collectorType       = "TRACING_COLLECTOR"
+       fileCollectorPath   = "TRACING_FILE_PATH"
+       serverCollectorAddr = "TRACING_SERVER_ADDRESS"
+       samplerRate         = "TRACING_SIMPLER_RATE"
+       defaultSamplerRate  = 1
+)
+
 func initTracer() {
        collector, err := newCollector()
        if err != nil {
@@ -36,7 +45,9 @@ func initTracer() {
        }
        ipPort := metric.InstanceName()
        recorder := zipkin.NewRecorder(collector, false, ipPort, 
strings.ToLower(core.Service.ServiceName))
-       tracer, err := zipkin.NewTracer(recorder, zipkin.TraceID128Bit(true))
+       tracer, err := zipkin.NewTracer(recorder,
+               zipkin.TraceID128Bit(true),
+               zipkin.WithSampler(zipkin.NewCountingSampler(GetSamplerRate())))
        if err != nil {
                log.Errorf(err, "new tracer failed")
                return
@@ -45,7 +56,7 @@ func initTracer() {
 }
 
 func newCollector() (collector zipkin.Collector, err error) {
-       ct := strings.TrimSpace(os.Getenv("TRACING_COLLECTOR"))
+       ct := strings.TrimSpace(os.Getenv(collectorType))
        switch ct {
        case "server":
                sa := GetServerEndpoint()
@@ -71,7 +82,7 @@ func ZipkinTracer() opentracing.Tracer {
 }
 
 func GetFilePath(defName string) string {
-       path := os.Getenv("TRACING_FILE_PATH")
+       path := os.Getenv(fileCollectorPath)
        if len(path) == 0 {
                wd, _ := os.Getwd()
                return filepath.Join(wd, defName)
@@ -80,9 +91,18 @@ func GetFilePath(defName string) string {
 }
 
 func GetServerEndpoint() string {
-       sa := os.Getenv("TRACING_SERVER_ADDRESS")
+       sa := os.Getenv(serverCollectorAddr)
        if len(sa) == 0 {
                sa = "http://127.0.0.1:9411";
        }
        return sa
 }
+
+func GetSamplerRate() float64 {
+       strRate := os.Getenv(samplerRate)
+       rate, err := strconv.ParseFloat(strRate, 64)
+       if rate <= 0 || err != nil {
+               return defaultSamplerRate
+       }
+       return rate
+}
diff --git a/server/plugin/infra/tracing/buildin/common_test.go 
b/server/plugin/infra/tracing/buildin/common_test.go
new file mode 100644
index 00000000..f82d1871
--- /dev/null
+++ b/server/plugin/infra/tracing/buildin/common_test.go
@@ -0,0 +1,79 @@
+// 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 buildin
+
+import (
+       "github.com/openzipkin/zipkin-go-opentracing"
+       "os"
+       "path/filepath"
+       "testing"
+)
+
+func TestGetFilePath(t *testing.T) {
+       wd, _ := os.Getwd()
+       f := GetFilePath("a")
+       if f != filepath.Join(wd, "a") {
+               t.Fatalf("TestGetFilePath failed, %v", f)
+       }
+       os.Setenv(fileCollectorPath, "trace.log")
+       f = GetFilePath("a")
+       if f != "trace.log" {
+               t.Fatalf("TestGetFilePath failed, %v", f)
+       }
+}
+
+func TestGetSamplerRate(t *testing.T) {
+       r := GetSamplerRate()
+       if r != defaultSamplerRate {
+               t.Fatalf("TestGetSamplerRate failed, %v", r)
+       }
+       os.Setenv(samplerRate, "a")
+       r = GetSamplerRate()
+       if r != defaultSamplerRate {
+               t.Fatalf("TestGetSamplerRate failed, %v", r)
+       }
+       os.Setenv(samplerRate, "0.1")
+       r = GetSamplerRate()
+       if r != 0.1 {
+               t.Fatalf("TestGetSamplerRate failed, %v", r)
+       }
+}
+
+func TestNewCollector(t *testing.T) {
+       os.Setenv(collectorType, "")
+       tracer, err := newCollector()
+       if err == nil {
+               t.Fatalf("TestNewCollector failed")
+       }
+       os.Setenv(collectorType, "server")
+       tracer, err = newCollector()
+       if err != nil {
+               t.Fatalf("TestNewCollector failed")
+       }
+       _, ok := tracer.(*zipkintracer.HTTPCollector)
+       if !ok {
+               t.Fatalf("TestNewCollector failed")
+       }
+       os.Setenv(collectorType, "file")
+       tracer, err = newCollector()
+       if err != nil {
+               t.Fatalf("TestNewCollector failed")
+       }
+       _, ok = tracer.(*FileCollector)
+       if !ok {
+               t.Fatalf("TestNewCollector failed")
+       }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Customizable tracing sample rate
> --------------------------------
>
>                 Key: SCB-937
>                 URL: https://issues.apache.org/jira/browse/SCB-937
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>          Components: Service-Center
>            Reporter: little-cui
>            Assignee: little-cui
>            Priority: Major
>             Fix For: service-center-1.1.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to