tagit

command module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

TagIt

Go Report Card License codecov

Update consul registration tags with outputs of a script. It copies the current service registration and appends the output of the script line by line as tags, while keeping the original tags.

Why?

Basically because it's a very useful feature that is missing from consul. Read more about it here. A few scenarios where this can be useful:

  1. Your databases are under mydb.service.consul, and you would like to ensure that all the writes go to the leader
    1. You run a script that checks the leader and updates the tag
  2. You have a service that is not consul aware, but you would like to use consul for service discovery
    1. You run a script that checks the service and updates the tags
  3. You have a load or a webserver, and you would like to have tags for all vhosts that are served by this server
    1. You run a script that checks the vhosts and updates the tags
  4. Pretty much any services that are not consul aware, but you would like to use consul for service discovery
    1. You run a script that checks the service and updates the tags

How to test it?

$ git clone github.com/ncode/tagit
$ go build
$ consul agent -dev &
$ curl --request PUT --data @examples/consul/my-service1.json http://127.0.0.1:8500/v1/agent/service/register
$ ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit
INFO[0000] running command                               command=./examples/tagit/example.sh service=my-service1
INFO[0000] updating service tags                         service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
INFO[0005] running command                               command=./examples/tagit/example.sh service=my-service1
INFO[0010] running command                               command=./examples/tagit/example.sh service=my-service1
INFO[0015] running command                               command=./examples/tagit/example.sh service=my-service1
$ ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit
INFO[0000] current service tags                          service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
INFO[0000] updating service tags                         service=my-service1 tags="[v1]"
sequenceDiagram
    participant tagit
    participant consul
    loop execute script on interval
        tagit->>consul: Do you have a service with id my-service1?
        consul->>tagit: Yes, here it is and that's the current registration
        tagit->>consul: Update current registration adding or removing prefixed tags wiht the output of the script
    end

Todo

  • Adds a systemd unit file generator

Documentation

Overview

Copyright © 2022 Juliano Martinez <juliano@martinez.io>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL