Tsukikage7 commented on code in PR #1128:
URL: https://github.com/apache/dubbo-go-samples/pull/1128#discussion_r3728093277
##########
integrate_test.sh:
##########
@@ -447,11 +577,16 @@ main() {
fi
start_go_server
+ start_sample_dependencies
start_aux_go_servers
run_go_client
run_java_client_if_present
+ if [ -n "$SAMPLE_COMPOSE_FILE" ]; then
+ stop_sample_dependencies
Review Comment:
已修复:teardown 前增加语义断言,带超时查询 Prometheus targets
与关键指标(`dubbo_provider_requests_succeed_total`)、从 Jaeger 校验同一条 trace 下的
consumer/provider spans、并验证 Grafana 预置数据源;任一环节失败均以非零码退出。此外
observability/integration 模式下客户端校验失败现在也会直接导致集成流程失败,避免 CI 假绿。
##########
observability/integration/go-client/cmd/main.go:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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 main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "os"
+ "strconv"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ dubbolog "dubbo.apache.org/dubbo-go/v3/logger"
+ "dubbo.apache.org/dubbo-go/v3/metrics"
+ "dubbo.apache.org/dubbo-go/v3/otel/trace"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+
+ "github.com/dubbogo/gost/log/logger"
+
+ "go.opentelemetry.io/otel"
+ "go.opentelemetry.io/otel/codes"
+ sdktrace "go.opentelemetry.io/otel/sdk/trace"
+)
+
+import (
+
"github.com/apache/dubbo-go-samples/observability/integration/internal/tracefields"
+ observability
"github.com/apache/dubbo-go-samples/observability/integration/proto"
+)
+
+var (
+ requests = flag.Int("requests", 5, "number of requests to send; 0
runs until interrupted")
+ interval = flag.Duration("interval", time.Second, "delay between
requests")
+ timeout = flag.Duration("timeout", 0, "per-request timeout; 0
disables the timeout")
+ cancelAfter = flag.Duration("cancel-after", 0, "cancel each request
after this duration; 0 disables cancellation")
+)
+
+func traceOptions() []trace.Option {
+ return []trace.Option{
+ trace.WithEnabled(),
+ trace.WithOtlpHttpExporter(),
+ trace.WithW3cPropagator(),
+ trace.WithAlwaysMode(),
+ trace.WithEndpoint(getEnv("DUBBO_OBSERVABILITY_OTLP_ENDPOINT",
"127.0.0.1:4318")),
+ trace.WithInsecure(),
+ }
+}
+
+func metricsOptions() []metrics.Option {
+ port, err := strconv.Atoi(getEnv("DUBBO_OBSERVABILITY_METRICS_PORT",
"9098"))
+ if err != nil {
+ port = 9098
+ }
+ return []metrics.Option{
+ metrics.WithEnabled(),
+ metrics.WithPrometheus(),
+ metrics.WithPrometheusExporterEnabled(),
+ metrics.WithRegistryEnabled(),
+ metrics.WithMetadataEnabled(),
+ metrics.WithPort(port),
+ metrics.WithPath("/prometheus"),
+ }
+}
+
+func registryOptions() []registry.Option {
+ return []registry.Option{
+ registry.WithNacos(),
+
registry.WithAddress(getEnv("DUBBO_OBSERVABILITY_REGISTRY_ADDRESS",
"127.0.0.1:8848")),
+ }
+}
+
+func getEnv(key, fallback string) string {
+ if value := os.Getenv(key); value != "" {
+ return value
+ }
+ return fallback
+}
+
+func main() {
+ flag.Parse()
+
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo-observability-client"),
+ dubbo.WithRegistry(registryOptions()...),
+ dubbo.WithTracing(traceOptions()...),
+ dubbo.WithMetrics(metricsOptions()...),
+ dubbo.WithLogger(
+ dubbolog.WithZap(),
+ dubbolog.WithLevel("debug"),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ cli, err := ins.NewClient()
+ if err != nil {
+ panic(err)
+ }
+
+ svc, err := observability.NewGreetService(cli)
+ if err != nil {
+ panic(err)
+ }
+
+ tracer := otel.Tracer("dubbo-observability-client")
+ unexpectedErrors := 0
+
+ for i := 1; *requests == 0 || i <= *requests; i++ {
+ requestCtx := context.Background()
+ cancel := context.CancelFunc(func() {})
+ if *timeout > 0 {
+ requestCtx, cancel = context.WithTimeout(requestCtx,
*timeout)
+ }
+ var cancelTimer *time.Timer
+ if *cancelAfter > 0 {
+ parentCancel := cancel
+ var cancelRequest context.CancelFunc
+ requestCtx, cancelRequest =
context.WithCancel(requestCtx)
+ cancel = func() {
+ cancelRequest()
+ parentCancel()
+ }
+ cancelTimer = time.AfterFunc(*cancelAfter,
cancelRequest)
+ }
+ ctx, span := tracer.Start(requestCtx, "observability.request")
+ name := fmt.Sprintf("request-%d", i)
+ if i%5 == 0 {
+ name = "error"
+ }
+ logger.Infof("sending greet request: name=%s%s", name,
tracefields.Fields(ctx))
+
+ resp, callErr := svc.Greet(ctx,
&observability.GreetRequest{Name: name})
+ if callErr != nil {
+ span.RecordError(callErr)
+ span.SetStatus(codes.Error, callErr.Error())
+ logger.Errorf("greet request failed: %v%s", callErr,
tracefields.Fields(ctx))
+ if name != "error" && *timeout == 0 && *cancelAfter ==
0 {
Review Comment:
已修复:普通请求校验 `resp` 非空且 greeting 精确为 `hello <name>`;forced-error 请求由服务端返回
typed `CodeAborted` 错误,客户端要求 `callErr` 非空且错误码为
`CodeAborted`,所有不匹配累计为失败并退出。校验逻辑抽到 `internal/verify` 包,新增变异测试覆盖 greeting 错误、nil
响应、意外错误、缺失 error 分支(forced-error 请求误成功)及错误码不符等场景。
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]