Skip to content

是否有在 istio中的 wasmplugin资源中使用dispatch_grpc_call成功的例子? #254

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

Closed
pi-pi-miao opened this issue Aug 15, 2024 · 2 comments

Comments

@pi-pi-miao
Copy link

我在 istio中创建 wasmplugin 调用dispatch_grpc_call方法请求 k8s中的 grpc的 server 服务,没有报错,但是在如下代码中
struct HttpHeaders {
context_id: u32,
}

impl Context for HttpHeaders {
fn on_grpc_call_response(&mut self, _token_id: u32, status_code: u32, response_size: usize) {
if let Some(body) = self.get_grpc_call_response_body(0, response_size) {
let mut hp = pb::pb::HelloResponse::new();
match hp.merge_from_bytes(body.as_slice()) {
Ok(
) => {
let msg = hp.get_message();
error!("{}", msg);
self.set_http_request_header("hello", Some(&msg.to_string()));
}
Err(e) => {
error!("{}", e)
}
}
}
self.resume_http_request();
}
}
一直返回get data la hhhh [on_grpc_call_response] response_size is 0 code is 14,id :53 thread=29
调用的方法:
impl HttpContext for HttpHeaders {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
println!("请求来啦========== ==========");

    let mut req = pb::hello::HelloRequest::new();
    req.set_name("grpc_name".to_string());
    let message = req.write_to_bytes().unwrap();
    match self.dispatch_grpc_call(
        "outbound|9991||grpc-demo-clusterip-service.grpc-server-1.svc.cluster.local",
        "hello.HelloService",
        "Hello",
        Vec::<(&str, &[u8])>::new(),
        Some(message.as_slice()),
        // Duration::from_millis(20),
        Duration::from_secs(10),
    ) {
        Ok(v) => error!("grpc send success,{}",v),
        Err(e) => error!("grpc send error:{:?}", e),
    }
    Action::Pause
}

fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action {
    Action::Continue
}

fn on_log(&mut self) {
    trace!("#{} completed.", self.context_id);
}

}
调用是 ok 的会打印grpc send success

是因为在 istio的 wasmplugin中不支持 grpc的调用吗?

@pi-pi-miao
Copy link
Author

找到问题了,上面的使用方式是正确的,只是请求被对端的 sid ecar拦截了
对端 sidecar 会报错- - HTTP/2" 0 DPE http2.invalid.header.field - "-" 0 0 0 - "-" "-" "-" "-" "-" - - 10.1.9.230:9991 10.1.9.229:48112 outbound_.9991_._.grpc-demo-service.grpc-server.svc.cluster.local -
去掉对端 sidecar 就可以了

@pi-pi-miao
Copy link
Author

上面的例子可以作为在 istio 中的 wasmplugin 中通过 grpc 链接其他服务的实现例子,供后来者参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant