简体   繁体   English

我正在尝试将 gRPC 协议的指标传递给 kubernetes istio。 我正在使用 java spring 启动

[英]I am trying to pass the metric of a gRPC protocol to kubernetes istio. I am using java spring boot

I have an external request to the aggregator, from which there is a request to the gRPC server.我对聚合器有一个外部请求,从该请求对 gRPC 服务器有一个请求。 I only get metrics from ingress-gateway to aggregator.我只获得从入口网关到聚合器的指标。 and from the aggregator to the grpc service.并从聚合器到 grpc 服务。 It turns out that I do not build a complete query dependency tree, but only two parts of it.事实证明,我并没有构建完整的查询依赖树,而只是构建了它的两个部分。 How can I get the complete dependency tree?如何获得完整的依赖树?

在此处输入图像描述

second metrics第二个指标

在此处输入图像描述

my dependencies我的依赖


     <dependency>
            <groupId>net.devh</groupId>
            <artifactId>grpc-spring-boot-starter</artifactId>
            <version>2.12.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.4.5</version>
        </dependency>

my code我的代码

@Service
public class GrpcService {

    @GrpcClient("square")
    private SquareRpcGrpc.SquareRpcBlockingStub blockingStub;

    @GrpcClient("square")
    private SquareRpcGrpc.SquareRpcStub asyncStub;

    public Object getSquareResponseUnary(int number){
        return IntStream.rangeClosed(1, number)
                .mapToObj(i -> Input.newBuilder().setNumber(i).build())
                .map(this.blockingStub::findSquareUnary)
                .collect(Collectors.toMap(
                        Output::getNumber,
                        Output::getResult
                ));
    }

    public Object getSquareResponseStream(int number){
        CompletableFuture<Map<Integer, Integer>> completableFuture = new CompletableFuture<>();
        OutputStreamingResponse outputStreamingResponse = new OutputStreamingResponse(
                new HashMap<>(),
                completableFuture
        );
        StreamObserver<Input> squareBiStream = this.asyncStub.findSquareBiStream(outputStreamingResponse);
        IntStream.rangeClosed(1, number)
                .mapToObj(i -> Input.newBuilder().setNumber(i).build())
                .forEach(squareBiStream::onNext);
        squareBiStream.onCompleted();
        return completableFuture;
    }
}

proto file原型文件

syntax = "proto3";

package vinsmath;

option java_package = "com.vinsguru.model";
option java_multiple_files = true;

message Input {
  int32 number = 1;
}

message Output {
  int32 number = 1;
  int32 result = 2;
}

service SquareRpc {
  rpc findSquareUnary(Input) returns (Output) {};
  rpc findSquareBiStream(stream Input) returns (stream Output) {};

}

deployment and svc grpc部署和 svc grpc

apiVersion: v1
kind: Service
metadata:
  name: grpc-service
  labels:
    app: grpc
spec:
  type: ClusterIP
  selector:
    app: grpc
  ports:
  - name: grpc
    protocol: TCP
    port: 50101
    targetPort: 50101
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grpc
spec:
  selector:
    matchLabels:
      app: grpc 
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: grpc
        version: v1
    spec:
      containers:
        - name: grpc
          image: 13523661/grpc-square-service:6.9
          imagePullPolicy: Always
          ports:
          - containerPort: 50101
          env:
            - name: JAEGER_ENDPOINT
              value: http://jaeger-collector.istio-system.svc:14268/api/traces
            - name: JAEGER_PROPAGATION
              value: b3
---

Deployment aggregator部署聚合器


apiVersion: v1
kind: Service
metadata:
  name: agr
  labels:
    app: agr
    service: agr
spec:
  ports:
  - port: 8080
    name: http
  selector: 
    app: agr
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: agr-v1
  labels:
    app: agr
    version: v1
spec:
  selector:
    matchLabels:
      app: agr
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: agr
        version: v1
    spec:
      containers:
        - name: agr
          image: 13523661/aggregator-service:6.9
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 8080
          env:
            - name: GRPC_CLIENT_SQUARE_ADDRESS
              valueFrom:
                secretKeyRef:
                  name: secret-3
                  key: grpc.client.square.address
            - name: REST_SQUARE_SERVICE_ENDPOINT
              valueFrom:
                secretKeyRef:
                  name: secret-3
                  key: rest.square.service.endpoint
            - name: JAEGER_ENDPOINT
              value: http://jaeger-collector.istio-system.svc:14250/api/traces
            - name: JAEGER_PROPAGATION
              value: b3

Maybe you have an example of how to get the full tracing span也许您有一个如何获得完整跟踪跨度的示例

it works for me这个对我有用

@Configuration public class TracingConfig { @Configuration public class TracingConfig {

@GrpcGlobalClientInterceptor
TracingClientInterceptor tracingInterceptor(Tracer tracer) {
    return TracingClientInterceptor
            .newBuilder()
            .withTracer(tracer)
            .build();
}

} }

link https://github.com/opentracing-contrib/java-grpc链接https://github.com/opentracing-contrib/java-grpc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java + Spring Boot:我正在尝试将 CacheControl 标头添加到 ResponseEntity - Java + Spring Boot: I am trying to add CacheControl header to ResponseEntity 我正在使用 spring 启动并尝试连接 Apache Phoenix - i am using spring boot and trying to connect Apache Phoenix 当我尝试使用 Spring Boot 将产品添加到购物车时出现错误 - I am getting an error while i am trying to add a product to the cart using Spring boot 我正在尝试将 ArrayList 传递给 Java 中的方法 - I am trying to pass an ArrayList to a method in Java 为什么我尝试在 Spring Boot 应用程序中使用准备好的语句执行 JdbcTemplate 查询时出现此错误? - Why am I obtaining this error trying to perform JdbcTemplate query using prepared statement in a Spring Boot application? 我是Java的新手,并且尝试连接到derby数据库。 我正在使用netbeans 7.4 - I am a newbie with java and I am trying to connect to a derby database. I am using netbeans 7.4 如何使用 CompletableFuture 将此代码转换为 Java 8 中的异步代码? 我正在使用 Spring 引导 - How to convert this code to async in Java 8 using CompletableFuture ? I am using Spring Boot 我可以将数据从Spring引导控制器传递到html页面,但是如何使用Java Script访问数据? - I am able to pass the data from Spring boot controller to html page, but how do I access the data in Java Script? 我正在升级到 spring 启动 2.5.12,并在下面收到此错误 - I am upgrading to spring boot 2.5.12, and am getting this error below 如何在电子邮件中附加图像? 我正在使用 AWS SES 服务使用 JAVA 发送电子邮件 - Spring Boot - How do i attach image in email? I am using AWS SES Service to send email using JAVA - Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM