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

Fix filter tags #60

Merged
merged 6 commits into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.consul
*.etcd
site/
docs/scss/Gemfile.lock
Expand Down
15 changes: 9 additions & 6 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (a *AgentCommand) join(addrs []string, replay bool) (n int, err error) {
}

func (a *AgentCommand) RunQuery(job *Job) {
filterNodes, err := a.processFilteredNodes(job)
filterNodes, filterTags, err := a.processFilteredNodes(job)
if err != nil {
log.WithFields(logrus.Fields{
"job": job.Name,
Expand All @@ -683,7 +683,7 @@ func (a *AgentCommand) RunQuery(job *Job) {

params := &serf.QueryParam{
FilterNodes: filterNodes,
FilterTags: job.Tags,
FilterTags: filterTags,
RequestAck: true,
}

Expand All @@ -697,6 +697,7 @@ func (a *AgentCommand) RunQuery(job *Job) {
log.WithFields(logrus.Fields{
"query": QueryRunJob,
"job_name": ex.JobName,
"json": string(exJson),
}).Debug("agent: Sending query")

qr, err := a.serf.Query(QueryRunJob, exJson, params)
Expand Down Expand Up @@ -739,19 +740,21 @@ func (a *AgentCommand) RunQuery(job *Job) {

}

func (a *AgentCommand) processFilteredNodes(job *Job) ([]string, error) {
func (a *AgentCommand) processFilteredNodes(job *Job) ([]string, map[string]string, error) {
var nodes []string
tags := job.Tags

for jtk, jtv := range job.Tags {
var tc []string
if tc = strings.Split(jtv, ":"); len(tc) == 2 {
tv := tc[0]

// Set original tag to clean tag
job.Tags[jtk] = tv
tags[jtk] = tv

count, err := strconv.Atoi(tc[1])
if err != nil {
return nil, err
return nil, nil, err
}

for _, member := range a.serf.Members() {
Expand All @@ -766,7 +769,7 @@ func (a *AgentCommand) processFilteredNodes(job *Job) ([]string, error) {
}
}

return nodes, nil
return nodes, tags, nil
}

func (a *AgentCommand) setExecution(payload []byte) *Execution {
Expand Down
6 changes: 5 additions & 1 deletion dkron/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,16 @@ func Test_processFilteredNodes(t *testing.T) {
}

time.Sleep(2 * time.Second)
nodes, err := a.processFilteredNodes(job)
nodes, tags, err := a.processFilteredNodes(job)

if nodes[0] != "test1" || nodes[1] != "test2" {
t.Fatal("Not expected returned nodes")
}

if tags["role"] != "test" {
t.Fatalf("Tags error, expected: test, got %s", tags["role"])
}

// Send a shutdown request
shutdownCh <- struct{}{}
shutdownCh2 <- struct{}{}
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Dkron relies on the key-value store for data storage, you can run an instance of

It can use etcd, Consul or Zookeeper as data stores. To install any of this systems got to their web site:

- etcd: https://coreos.com/etcd/docs/latest/
- Consul: https://consul.io/intro/getting-started/install.html
- ZooKeeper: https://zookeeper.apache.org/doc/r3.3.3/zookeeperStarted.html
- [etcd](https://coreos.com/etcd/docs/latest/)
- [Consul](https://consul.io/intro/getting-started/install.html)
- [ZooKeeper](https://zookeeper.apache.org/doc/r3.3.3/zookeeperStarted.html)

## Installation

Expand Down