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

Kafka connection in cloud2edge #492

Closed
bs3245 opened this issue Aug 31, 2023 · 16 comments
Closed

Kafka connection in cloud2edge #492

bs3245 opened this issue Aug 31, 2023 · 16 comments

Comments

@bs3245
Copy link

bs3245 commented Aug 31, 2023

I have installed cloud2edge package in mickrok8s and I am able to create tenants, devices and credentials.

Can you provide me the steps on how to enable kafka based Hono connection in ditto in cloud2edge?

Also can you suggest how to implement inbound and outbound kafka connection?

@calohmn could you please take this question
This is more of an question than issue, I don't know to how to add question tag

@calohmn
Copy link
Contributor

calohmn commented Sep 7, 2023

@bs3245 When deploying the current cloud2edge chart version (0.4.2), there is already a Kafka connection being created for the org.eclipse.packages.c2e tenant.
As for creating another connection for a new tenant, I've created PR #493 to update the cloud2edge tour webpage accordingly.
(In the PR code there is currently still an issue concerning the Kafka topic mapping - I'm looking into that.)

There is already #468 concerning issues creating a new tenant and connection, and there is #432 about updating the cloud2edge tour with instructions how to add a Kafka connection.

I'm closing this as a duplicate then, you can follow the PR #493 to see when the cloud2edge documentation gets updated.

In general, if you have a question, you can ask it in the Gitter channel.

@calohmn calohmn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2023
@calohmn
Copy link
Contributor

calohmn commented Sep 7, 2023

Duplicate of #468

@calohmn calohmn marked this as a duplicate of #468 Sep 7, 2023
@calohmn
Copy link
Contributor

calohmn commented Sep 8, 2023

@bs3245 Connecting Hono to Ditto can be done via AMQP 1.0 or Kafka. I'm positive we will get the Kafka connection example in the cloud2edge chart fully working soon together with the new Ditto version (see #493).

Concerning the AMQP connection support, I can say with respect to Hono that having started out with AMQP 1.0, we added Kafka support in Hono 2.0. Kafka has been the focus of development since then, mainly because of its wider adoption.

@bs3245
Copy link
Author

bs3245 commented Sep 9, 2023

Hi @calohmn,

I'm trying to install the new c2e version, do I need add any helm repo since ditto has been moved to its own repository?

@calohmn
Copy link
Contributor

calohmn commented Sep 9, 2023

@bs3245 No, that is not needed. You just need the added eclipse-iot repo, as described here.
To make sure you use the newest cloud2edge chart version, run helm repo update eclipse-iot.
To install the newest cloud2edge chart version, you need at least Helm version 3.8.

@bs3245
Copy link
Author

bs3245 commented Sep 9, 2023

@calohmn Yeah, I did update the repo and my helm version is 3.10, but the installation is getting failed

NAME                                           READY   STATUS     RESTARTS   AGE
c2e-ditto-policies-6c66f7cd87-f2722            0/1     Pending    0          15m
c2e-ditto-things-7967f59b4-8ndqq               0/1     Pending    0          15m
c2e-ditto-dittoui-649d4b487d-777nr             1/1     Running    0          15m
c2e-ditto-thingssearch-5c5468bfc6-26kg6        0/1     Running    0          15m
c2e-ditto-swaggerui-646678bdfd-6p5bz           1/1     Running    0          15m
c2e-ditto-connectivity-74d887f74c-d9hnr        0/1     Running    0          15m
c2e-ditto-nginx-855cdbfd46-56bdn               0/1     Init:0/1   0          15m
c2e-zookeeper-0                                1/1     Running    0          15m
c2e-ditto-gateway-557c96cb88-9km87             0/1     Running    0          15m
ditto-mongodb-6595d47d5f-pr6df                 1/1     Running    0          15m
c2e-service-auth-7bc7dcfb6b-x9pxb              1/1     Running    0          15m
c2e-kafka-0                                    1/1     Running    0          15m
c2e-service-device-registry-8547bcccf4-2zjj5   1/1     Running    0          15m
c2e-service-command-router-58cb44d796-dk6zw    1/1     Running    0          15m
c2e-adapter-http-6c994d798c-f56k2              1/1     Running    0          15m
c2e-adapter-mqtt-6d9b67b678-qfwkg              1/1     Running    0          15m
c2e-adapter-amqp-7c94bf5bdd-dsf6j              1/1     Running    0          15m

Name:             c2e-ditto-nginx-855cdbfd46-56bdn
Namespace:        c2e
Priority:         0
Service Account:  default
Node:             lexi-node/172.31.0.44
Start Time:       Sat, 09 Sep 2023 05:29:41 +0000
Labels:           app.kubernetes.io/instance=c2e
                  app.kubernetes.io/name=ditto-nginx
                  pod-template-hash=855cdbfd46
Annotations:      checksum/nginx-auth: 733b07dfc2bc566031ee16f6008d013ef7952d55940a568a702d77aad79228fa
                  checksum/nginx-conf: 8a1b64e7d088a9ebb702a926a42ebb98f91fe22759114f57f64aee6f986f15de
                  checksum/nginx-config: 3729c0b1c2ebd84e6f683b60e63914353161fdc14d164a09c210141a172adb78
                  cni.projectcalico.org/containerID: 03bbf4697027ebf5aef91416ade4b4a2fb60e7f647358a386c2d04052b89b6be
                  cni.projectcalico.org/podIP: 10.1.251.41/32
                  cni.projectcalico.org/podIPs: 10.1.251.41/32
Status:           Pending
IP:               10.1.251.41
IPs:
  IP:           10.1.251.41
Controlled By:  ReplicaSet/c2e-ditto-nginx-855cdbfd46
Init Containers:
  wait-for-gateway:
    Container ID:  containerd://b8eb5030c9f94ba68a12946663dcc2b9dff867172fe3045477e31c8d53e0740e
    Image:         rancher/curlimages-curl:7.73.0
    Image ID:      docker.io/rancher/curlimages-curl@sha256:879cd9c184850948c88bebc4954c773e1241ad6404f1baa3621049aac2864e52
    Port:          <none>
    Host Port:     <none>
    Args:
      /bin/sh
      -c
      set -x; while [[ "$(curl -sL -w "%{http_code}\n" http://c2e-ditto-gateway:8080/health -o /dev/null)" != "200" ]]; do
        echo '.'
        sleep 1;
      done

    State:          Running
      Started:      Sat, 09 Sep 2023 05:29:50 +0000
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-vfq8h (ro)
Containers:
  ditto-nginx:
    Container ID:
    Image:          docker.io/nginx:1.25
    Image ID:
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       PodInitializing
    Ready:          False
    Restart Count:  0
    Limits:
      memory:  64Mi
    Requests:
      cpu:        200m
      memory:     64Mi
    Environment:  <none>
    Mounts:
      /etc/nginx/html/ditto-down.svg from nginx-ditto-down (rw,path="ditto-down.svg")
      /etc/nginx/html/ditto-up.svg from nginx-ditto-up (rw,path="ditto-up.svg")
      /etc/nginx/html/index.html from nginx-index (rw,path="index.html")
      /etc/nginx/nginx-cors.conf from nginx-cors (rw,path="nginx-cors.conf")
      /etc/nginx/nginx.conf from nginx-conf (rw,path="nginx.conf")
      /etc/nginx/nginx.htpasswd from nginx-htpasswd (rw,path="nginx.htpasswd")
      /run/nginx from nginx-run (rw)
      /var/cache/nginx from nginx-cache (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-vfq8h (ro)
Conditions:
  Type              Status
  Initialized       False
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  nginx-conf:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      c2e-nginx-conf
    Optional:  false
  nginx-htpasswd:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  c2e-nginx-config-nginx-htpasswd
    Optional:    false
  nginx-cors:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      c2e-nginx-config-nginx-cors-conf
    Optional:  false
  nginx-index:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      c2e-nginx-config-index-html
    Optional:  false
  nginx-ditto-down:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      c2e-nginx-config-ditto-down-svg
    Optional:  false
  nginx-ditto-up:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      c2e-nginx-config-ditto-up-svg
    Optional:  false
  nginx-cache:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  nginx-run:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  kube-api-access-vfq8h:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

@calohmn
Copy link
Contributor

calohmn commented Sep 9, 2023

@bs3245 If you have used the ditto.nginx.service.type=LoadBalancer helm install parameter, Load Balancer support in your Kubernetes environment is needed. If you are using minikube, run minikube tunnel in a separate terminal.

@bs3245
Copy link
Author

bs3245 commented Sep 9, 2023

No, I'm trying the nodeport install command which as worked fine in the previous version. And also I'm deploying it in microk8s.

@calohmn
Copy link
Contributor

calohmn commented Sep 9, 2023

I just tested on minikube and the c2e-ditto-nginx pod also stayed in "Init" state for quite a while but then got ready.
(The nginx init-container is waiting for the c2e-ditto-gateway to report that it is up.)

@bs3245
Copy link
Author

bs3245 commented Sep 9, 2023

It didn't work for me in MicroK8s, so I tried it in Minikube using the LoadBalancer install command alongside running minikube tunnel, but unfortunately, that also didn't seem to resolve the issue.

desc.txt
Can help me in debugging this?

I've noticed that some of the pods are failing, seemingly due to insufficient CPU resources. I started Minikube with the resource requirements specified in the installation guide. Could you share your Minikube configuration?

@calohmn
Copy link
Contributor

calohmn commented Sep 9, 2023

I noticed a bug in the cloud2edge chart here. The chart is supposed to configure the Ditto chart with lower CPU/memory resources compared to the Ditto defaults. But the way this configuration is done has changed with the new Ditto chart version and the cloud2edge chart hasn't been adapted there.
That means the cloud2edge chart per default currently has much higher resource requirements than intended.

As a workaround, you can supply the corresponding chart parameters by referencing this file:
ditto_resources.yaml.txt
(rename it to ditto_resources.yaml and use -f <path>/ditto_resources.yaml in helm install).

The bug is tracked in #499.

@bs3245
Copy link
Author

bs3245 commented Sep 11, 2023

@calohmn While creating the kafka connection based on the tour guide, I'm getting this

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Mon, 11 Sep 2023 11:14:44 GMT
Content-Type: application/json
Content-Length: 230
Connection: keep-alive
correlation-id: b5282210-b18e-44a7-9e1a-412857166ae2
response-required: false
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *

{"status":400,"error":"connectivity:connection.configuration.invalid","message":"The provided key in your target address may not be empty.","description":"Make sure all required properties are set and valid in the configuration."}

While trying the fetch the ditto connection through connection api there is only one kafka connection. Can you tell me what is the configuration that is required here?

Tried again with the connection api of ditto, it gives the same error.

@calohmn
Copy link
Contributor

calohmn commented Sep 11, 2023

@bs3245 Sorry, there was an issue with the website, meaning there were certain parts of the JSON message in the curl request being omitted.
It is fixed now. You can do a reload of the c2e tour page (check whether the curl request for creating the Kafka connection contains {{ thing:id }} for example).

@bs3245
Copy link
Author

bs3245 commented Sep 11, 2023

@calohmn Thank you for solving this. It worked fine this time and the connection is created.

I just have some doubt if you could clarify them it would be helpful,

  • If I have made both kafka and amqp connection with an tenant, how does a thing in ditto get updated(like which connection does it is use)
  • Since we are making connection specific to an tenant, then if we have multiple tenant do we need to make multiple connections as well?

@bs3245
Copy link
Author

bs3245 commented Sep 12, 2023

@calohmn Can you review this as part of the tour, I tried sending the command of this, 'start watering' from ditto. How can I receive this message at device side?

If Ditto shall wait for a response, responding with the response from the device at the HTTP level, simply increase the timeout to the amount of seconds to wait:

curl -i -X POST -u ditto:ditto -H 'Content-Type: application/json' -w '\n' --data '{
  "water-amount": "3liters"
}' ${DITTO_API_BASE_URL:?}/api/2/things/org.eclipse.packages.c2e:demo-device/inbox/messages/start-watering?timeout=60

Receiving a command at the device
The device may receive a command by specifying a ttd when e.g. sending telemetry via HTTP to Hono:

curl -i -k -u [email protected]:demo-secret -H 'hono-ttd: 50' -H 'application/json' -w '\n' --data '{
  "topic": "org.eclipse.packages.c2e/demo-device/things/twin/commands/modify",
  "headers": {},
  "path": "/features/temperature/properties/value",
  "value": 45
}' ${HTTP_ADAPTER_BASE_URL:?}/telemetry

An example response for the device containing the command sent via the Ditto twin (see previous step for sending the command) is:

Example of a received command at the device
HTTP/1.1 200 OK
hono-command: start-watering
hono-cmd-req-id: 024d84b1ceb-797b-45f5-bc87-78e9b5396645replies
content-type: application/json
content-length: 516

{"topic":"org.eclipse.packages.c2e/demo-device/things/live/messages/start-watering","headers":{"correlation-id":"d84b1ceb-797b-45f5-bc87-78e9b5396645","x-forwarded-for":"10.244.0.1","version":2,"timeout":"0","x-forwarded-user":"ditto","accept":"*/*","x-real-ip":"10.244.0.1","x-ditto-dummy-auth":"nginx:ditto","host":"172.17.0.2:30385","content-type":"application/json","timestamp":"2020-02-28T08:04:43.518+01:00","user-agent":"curl/7.58.0"},"path":"/inbox/messages/start-watering","value":{"water-amount":"3liters"}}

@calohmn
Copy link
Contributor

calohmn commented Sep 13, 2023

@bs3245 Thanks for the notification here. The "Receiving a command at the device" curl command seems wrong.
You could use

curl -i -X POST -k -u [email protected]:demo-secret -H 'hono-ttd: 50' \
  -H 'Content-Type: application/vnd.eclipse-hono-empty-notification' ${HTTP_ADAPTER_BASE_URL:?}/telemetry

I've created #503 to fix this.

(EDIT: updated the curl command here)

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

2 participants