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

Document requests #45

Open
dazinator opened this issue Aug 27, 2021 · 2 comments
Open

Document requests #45

dazinator opened this issue Aug 27, 2021 · 2 comments

Comments

@dazinator
Copy link

I'm experimenting with using docker flow swarm listener as a means to notify my own endpoint with information about new services that join the swarm.

The reason for this, is because I would like to auto provision a secret for new services, that will be used for service to service authentication (it's an oauth client secret for the client credentials oauth flow that I'd be planning to use between the services.

From experimentation I can see that when I create a service in the swarm with docker service create the listener sends a request like this:

Date received: 23:04:56
POST /api/echo?distribute=true&madeup=foo&replicas=1&serviceName=dummy-nginx HTTP/1.1

Accept-Encoding: gzip
Host: dummy-endpoint:80
User-Agent: Go-http-client/1.1
Content-Length: 0

I would be really nice if the format of these requests were documented as a stable api, so that this swarm listener could be more easily used in combination with other services in its own right, not just monitor - without having to set up a proxy or dummy http endpoint to work out what will be sent and when.

@dazinator
Copy link
Author

dazinator commented Aug 27, 2021

This is what I have figured out so far, I have a single node cluster so I am not able to see what is generated for when nodes are added or removed:

Swarm listener

The swarm listener is designed to listen to the following docker swarm events (or poll docker) and send an HTTP notification to some URL when events are detected with more information:-

  • Service created
  • Service destroyed
  • Node created
  • Node destroyed

The following examples show the HTTP Requests that are made, as a result of these events. For reference, this is based on the following docker compose configuration of the swarm listener service:-

swarm-listener:
    # SEE https://swarmlistener.dockerflow.com/config/ 
    image: dockerflow/docker-flow-swarm-listener
    networks:
       - monitor
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DF_NOTIFY_CREATE_SERVICE_URL=http://dummy-endpoint:80/api/echo
      - DF_NOTIFY_REMOVE_SERVICE_URL=http://dummy-endpoint:80/api/echo
      - DF_NOTIFY_CREATE_SERVICE_METHOD=POST
      - DF_NOTIFY_REMOVE_SERVICE_METHOD=POST
      - DF_NOTIFY_CREATE_NODE_URL=http://dummy-endpoint:80/api/echo
      - DF_NOTIFY_REMOVE_NODE_URL=http://dummy-endpoint:80/api/echo


    deploy:
      placement:
        constraints: [node.role == manager]

Service Created

When a service is created on the swarm, for example using:-

docker service create --name dummy-nginx --network monitor --label com.df.notify=true --label com.df.madeup=foo nginx

The swarm listener sends a request with the following content:

Date received: 23:04:56
POST /api/echo?distribute=true&madeup=foo&replicas=1&serviceName=dummy-nginx HTTP/1.1

Accept-Encoding: gzip
Host: dummy-endpoint:80
User-Agent: Go-http-client/1.1
Content-Length: 0

Service Scaled

If a service is scaled, for example using:-

docker service scale dummy-nginx=2  

The swarm listener sends a request like this:-

Date received: 23:13:18
POST /api/echo?distribute=true&madeup=foo&replicas=2&serviceName=dummy-nginx HTTP/1.1

Accept-Encoding: gzip
Host: dummy-endpoint:80
User-Agent: Go-http-client/1.1
Content-Length: 0

Service Removed

If a service is removed, for example using:-

docker service rm dummy-nginx

The swarm listener sends a request like this:-

Date received: 23:24:32
POST /api/echo?distribute=true&madeup=foo&serviceName=dummy-nginx HTTP/1.1

Accept-Encoding: gzip
Host: dummy-endpoint:80
User-Agent: Go-http-client/1.1
Content-Length: 0

@vfarcic
Copy link
Contributor

vfarcic commented Sep 2, 2021

This repo hasn't received any commits for a few years now. Since almost everyone moved to Kubernetes (me included), there is close to no activity with Docker Swarm (in general, as well as in Docker Flow repos). That being said, it would be great if existing Docker Swarm users would like to pick it up and continue the work.

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