eclipse-zenoh / zenoh

zenoh unifies data in motion, data in-use, data at rest and computations. It carefully blends traditional pub/sub with geo-distributed storages, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.
https://zenoh.io
Other
1.46k stars 157 forks source link

REST API always returns empty array #1302

Open mbspng opened 2 months ago

mbspng commented 2 months ago

Describe the bug

REST API always returns empty array

To reproduce

Build an run this Docker code

# Use an official Ubuntu as a parent image
FROM ubuntu:20.04 AS builder

# Set environment variables to non-interactive to prevent prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/bin:$PATH

# Install system dependencies
RUN apt-get update && \
    apt-get install -y \
    python3-pip \
    wget \
    git \
    libasio-dev \
    libtinyxml2-dev \
    swig \
    libpython3-dev \
    python3-venv \
    sudo \
    build-essential \
    libssl-dev \
    gcc-10 \
    g++-10 \
    make \
    libssl-dev \
    zlib1g-dev \
    libbz2-dev \
    libreadline-dev \
    libsqlite3-dev \
    curl \
    llvm \
    libncurses5-dev \
    libncursesw5-dev \
    xz-utils \
    tk-dev \
    libffi-dev \
    liblzma-dev && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Install pyenv and set Python version
RUN curl https://pyenv.run | bash && \
    pyenv install 3.10.13 && \
    pyenv global 3.10.13

# RUN wget --no-check-certificate https://download.eclipse.org/zenoh/debian-repo/zenoh-keyring.gpg -O - | apt-key add -
RUN echo "deb [trusted=yes] https://download.eclipse.org/zenoh/debian-repo/ /" | tee -a /etc/apt/sources.list > /dev/null
RUN apt-get update && \
    apt-get install -y zenoh

CMD ["zenohd", "--id", "8513e6171ad48733194c2bab57a5dd86"]
docker build -f Dockerfile -t zenoh-test .
docker run -d -p 8000:8000 zenoh-test

Then send curl commands from docs (https://zenoh.io/docs/apis/rest/)

# Put a string value in demo/example/test
curl -X PUT -H "content-type:text/plain" -d 'Hello World!' http://localhost:8000/demo/example/test

Now I expect to see that data when I query it, but I do not:

$ curl -X GET http://localhost:8000/demo/example/test/\*\*
[]%
$ curl -X GET http://localhost:8000/demo/\*\*     
[]%
$ curl -X GET http://localhost:8000/whatever 
[]%    

System info

See docker code.

zenohd v1.0.0-alpha.6 built with rustc 1.75.0 (82e1608df 2023-12-21)

gabrik commented 2 months ago

Hi @mbspng,

Seems that you are not starting any storage, thus the data published with the PUT is being dropped as no subscriber are present.

Please refer to the reference manual: https://zenoh.io/docs/manual/plugin-storage-manager/#backends-and-volumes

mbspng commented 2 months ago

Hi @mbspng,

Seems that you are not starting any storage, thus the data published with the PUT is being dropped as no subscriber are present.

Please refer to the reference manual: https://zenoh.io/docs/manual/plugin-storage-manager/#backends-and-volumes

@gabrik Even when I start it with a storage, the outcome is the same. I followed the example in https://zenoh.io/docs/getting-started/first-app/ even before trying it with Docker. I am running zenohd -c zenoh-myhome.json5 and the storage query script also does not work. The replies() call gives an empty list.

import zenoh

if __name__ == "__main__":
    session = zenoh.open()
    replies = session.get('myhome/kitchen/temp', zenoh.ListCollector())
    for reply in replies():
        try:
            print("Received ('{}': '{}')"
                .format(reply.ok.key_expr, reply.ok.payload.decode("utf-8")))
        except:
            print("Received (ERROR: '{}')"
                .format(reply.err.payload.decode("utf-8")))
session.close()

I added the zenoh-myhome.json5 to my Docker file now and am launching it with CMD ["zenohd", "--id", "8513e6171ad48733194c2bab57a5dd86", "-c", "zenoh-myhome.json"]. The PUT and GET commands from the original post still result in an empty array being returned.

Edit: Ok, got it working, thanks. Documentation could be better, though.

mbspng commented 2 months ago

Actually, I still don't understand why the getting started example does not work. I got the manual PUT and GET working by adjusting the paths to myhome, as per the example config, rather than demo/test. But the retrieval script from the example still is not working.

gabrik commented 2 months ago

Hi @mbspng, thank you for spotting this, the documentation is not yet updated to the 1.0.0-alpha.X. We are going to update it once the final 1.0.0 is released

mbspng commented 2 months ago

@gabrik Ok thanks, installing zenoh=0.11.0-stable made it work. Documentation should state which version it is for, and apt should maybe not install an alpha version by default. When following the docs (https://zenoh.io/docs/getting-started/installation/) for the installatoin of zenohd, one will get a version of zenohd which does not match the docs!

anhaabaete commented 2 months ago

Hi, if you using Zenohd in a 1.0.0 and using 0.11.0 in a lib to you aplication. It Don't work. I had this problem here.