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

Add service deployments gauge #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions collector/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ func (e *ECSClient) GetClusterServices(cluster *types.ECSCluster) ([]*types.ECSS

for _, s := range resp.Services {
es := &types.ECSService{
ID: aws.StringValue(s.ServiceArn),
Name: aws.StringValue(s.ServiceName),
DesiredT: aws.Int64Value(s.DesiredCount),
RunningT: aws.Int64Value(s.RunningCount),
PendingT: aws.Int64Value(s.PendingCount),
ID: aws.StringValue(s.ServiceArn),
Name: aws.StringValue(s.ServiceName),
DesiredT: aws.Int64Value(s.DesiredCount),
RunningT: aws.Int64Value(s.RunningCount),
PendingT: aws.Int64Value(s.PendingCount),
Deployments: len(s.Deployments),
}
ss = append(ss, es)
}
Expand Down
10 changes: 5 additions & 5 deletions collector/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ func TestGetClusterServices(t *testing.T) {
}{
{
[]*types.ECSService{
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10},
&types.ECSService{ID: "s2", Name: "service2", PendingT: 5, RunningT: 5, DesiredT: 10},
&types.ECSService{ID: "s3", Name: "service3", PendingT: 7, RunningT: 3, DesiredT: 10},
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10, Deployments: 2},
&types.ECSService{ID: "s2", Name: "service2", PendingT: 5, RunningT: 5, DesiredT: 10, Deployments: 2},
&types.ECSService{ID: "s3", Name: "service3", PendingT: 7, RunningT: 3, DesiredT: 10, Deployments: 2},
},
false, false, false,
},
{
[]*types.ECSService{
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10},
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10, Deployments: 2},
},
true, false, true,
},
{
[]*types.ECSService{
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10},
&types.ECSService{ID: "s1", Name: "service1", PendingT: 1, RunningT: 9, DesiredT: 10, Deployments: 2},
},
true, true, true,
},
Expand Down
10 changes: 10 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ var (
[]string{"region", "cluster", "service"}, nil,
)

serviceDeployments = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "service_deployments"),
"The number of deployments regarding a service",
[]string{"region", "cluster", "service"}, nil,
)

// Container instances metrics
cInstanceCount = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "container_instances"),
Expand Down Expand Up @@ -145,6 +151,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- serviceDesired
ch <- servicePending
ch <- serviceRunning
ch <- serviceDeployments

if e.noCIMetrics {
return
Expand Down Expand Up @@ -263,6 +270,9 @@ func (e *Exporter) collectClusterServicesMetrics(ctx context.Context, ch chan<-

// Running task count
sendSafeMetric(ctx, ch, prometheus.MustNewConstMetric(serviceRunning, prometheus.GaugeValue, float64(s.RunningT), e.region, cluster.Name, s.Name))

// Deployment count
sendSafeMetric(ctx, ch, prometheus.MustNewConstMetric(serviceDeployments, prometheus.GaugeValue, float64(s.Deployments), e.region, cluster.Name, s.Name))
}
}

Expand Down
24 changes: 18 additions & 6 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func TestCollectClusterServiceMetrics(t *testing.T) {

testC := &types.ECSCluster{ID: "c1", Name: "cluster1"}
testSs := []*types.ECSService{
&types.ECSService{ID: "s1", Name: "service1", DesiredT: 10, PendingT: 5, RunningT: 5},
&types.ECSService{ID: "s2", Name: "service2", DesiredT: 15, PendingT: 5, RunningT: 10},
&types.ECSService{ID: "s3", Name: "service3", DesiredT: 30, PendingT: 27, RunningT: 0},
&types.ECSService{ID: "s4", Name: "service4", DesiredT: 51, PendingT: 50, RunningT: 1},
&types.ECSService{ID: "s5", Name: "service5", DesiredT: 109, PendingT: 99, RunningT: 2},
&types.ECSService{ID: "s6", Name: "service6", DesiredT: 6431, PendingT: 5000, RunningT: 107},
&types.ECSService{ID: "s1", Name: "service1", DesiredT: 10, PendingT: 5, RunningT: 5, Deployments: 2},
&types.ECSService{ID: "s2", Name: "service2", DesiredT: 15, PendingT: 5, RunningT: 10, Deployments: 2},
&types.ECSService{ID: "s3", Name: "service3", DesiredT: 30, PendingT: 27, RunningT: 0, Deployments: 2},
&types.ECSService{ID: "s4", Name: "service4", DesiredT: 51, PendingT: 50, RunningT: 1, Deployments: 2},
&types.ECSService{ID: "s5", Name: "service5", DesiredT: 109, PendingT: 99, RunningT: 2, Deployments: 2},
&types.ECSService{ID: "s6", Name: "service6", DesiredT: 6431, PendingT: 5000, RunningT: 107, Deployments: 2},
}
// Collect mocked metrics
go func() {
Expand Down Expand Up @@ -144,6 +144,18 @@ func TestCollectClusterServiceMetrics(t *testing.T) {
if expected != m.Desc().String() {
t.Errorf("expected '%s', \ngot '%s'", expected, m.Desc().String())
}

// Check 1st received metric per service (deployments)
m = (<-ch).(prometheus.Metric)
m2 = readGauge(m)
want = float64(wantS.Deployments)
if m2.value != want {
t.Errorf("expected %f service_deployments, got %f", want, m2.value)
}
expected = `Desc{fqName: "ecs_service_deployments", help: "The number of deployments regarding a service", constLabels: {}, variableLabels: [region cluster service]}`
if expected != m.Desc().String() {
t.Errorf("expected '%s', \ngot '%s'", expected, m.Desc().String())
}
}
}

Expand Down
1 change: 1 addition & 0 deletions mock/aws/ecs_mock_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func MockECSDescribeServices(t *testing.T, mockMatcher *sdk.MockECSAPI, wantErro
PendingCount: aws.Int64(s.PendingT),
RunningCount: aws.Int64(s.RunningT),
DesiredCount: aws.Int64(s.DesiredT),
Deployments: make([]*ecs.Deployment, s.Deployments),
}
ss = append(ss, ds)
}
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ECSService struct {
ID string // Service ARN
Name string // Name of the service
DesiredT, PendingT, RunningT int64 // Service task information
Deployments int // Number of deployments
}

// ECSCluster reprensens a cluster on ECS
Expand Down