Skip to content

Commit

Permalink
feat(inputs.docker): Support swarm jobs (#16292)
Browse files Browse the repository at this point in the history
  • Loading branch information
zomfg authored Dec 16, 2024
1 parent 516b8cf commit c0b3dd4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ func (d *Docker) gatherSwarmInfo(acc telegraf.Accumulator) error {
tags["service_mode"] = "global"
fields["tasks_running"] = running[service.ID]
fields["tasks_desired"] = tasksNoShutdown[service.ID]
} else if service.Spec.Mode.ReplicatedJob != nil {
tags["service_mode"] = "replicated_job"
fields["tasks_running"] = running[service.ID]
if service.Spec.Mode.ReplicatedJob.MaxConcurrent != nil {
fields["max_concurrent"] = *service.Spec.Mode.ReplicatedJob.MaxConcurrent
}
if service.Spec.Mode.ReplicatedJob.TotalCompletions != nil {
fields["total_completions"] = *service.Spec.Mode.ReplicatedJob.TotalCompletions
}
} else if service.Spec.Mode.GlobalJob != nil {
tags["service_mode"] = "global_job"
fields["tasks_running"] = running[service.ID]
} else {
d.Log.Error("Unknown replica mode")
}
Expand Down
26 changes: 26 additions & 0 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,32 @@ func TestDockerGatherSwarmInfo(t *testing.T) {
"service_mode": "global",
},
)

acc.AssertContainsTaggedFields(t,
"docker_swarm",
map[string]interface{}{
"tasks_running": int(0),
"max_concurrent": uint64(2),
"total_completions": uint64(2),
},
map[string]string{
"service_id": "rfmqydhe8cluzl9hayyrhw5ga",
"service_name": "test3",
"service_mode": "replicated_job",
},
)

acc.AssertContainsTaggedFields(t,
"docker_swarm",
map[string]interface{}{
"tasks_running": int(0),
},
map[string]string{
"service_id": "mp50lo68vqgkory4e26ts8f9d",
"service_name": "test4",
"service_mode": "global_job",
},
)
}

func TestContainerStateFilter(t *testing.T) {
Expand Down
25 changes: 25 additions & 0 deletions plugins/inputs/docker/docker_testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,31 @@ var serviceList = []swarm.Service{
},
},
},
{
ID: "rfmqydhe8cluzl9hayyrhw5ga",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test3",
},
Mode: swarm.ServiceMode{
ReplicatedJob: &swarm.ReplicatedJob{
MaxConcurrent: &two,
TotalCompletions: &two,
},
},
},
},
{
ID: "mp50lo68vqgkory4e26ts8f9d",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test4",
},
Mode: swarm.ServiceMode{
GlobalJob: &swarm.GlobalJob{},
},
},
},
}

var taskList = []swarm.Task{
Expand Down

0 comments on commit c0b3dd4

Please sign in to comment.