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

Use eks:cluster-name as clusterId #856

Merged
merged 8 commits into from
Mar 4, 2020
Merged
Changes from 5 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
37 changes: 27 additions & 10 deletions pkg/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,7 @@ func New(ctx context.Context) (Publisher, error) {
if err != nil {
return nil, errors.Wrap(err, "publisher: unable to obtain EC2 service client")
}
clusterID, err := ec2Client.GetClusterTag("CLUSTER_ID")
if err != nil || clusterID == "" {
glog.Errorf("Failed to obtain cluster-id, fetching name. %v", err)
clusterID, err = ec2Client.GetClusterTag("Name")
if err != nil || clusterID == "" {
glog.Errorf("Failed to obtain cluster-id or name, defaulting to 'k8s-cluster'. %v", err)
clusterID = "k8s-cluster"
}
}
glog.Info("Using cluster ID ", clusterID)
clusterID := getClusterId(ec2Client)

// Get CloudWatch client
ec2MetadataClient := ec2metadatawrapper.New(nil)
Expand Down Expand Up @@ -207,6 +198,32 @@ func (p *cloudWatchPublisher) getCloudWatchMetricNamespace() *string {
return aws.String(cloudwatchMetricNamespace)
}

func getClusterId(ec2Client *ec2wrapper.EC2Wrapper) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit... could you name this getClusterID() (capitalized ID) please?

// Default cluster id if unable to detect something more suitable
defaultClusterID := "k8s-cluster"

// List of EC2 tags (in priority order) to use as the CLUSTER_ID metric dimension
clusterIDTags := []string{
"eks:cluster-name",
"CLUSTER_ID",
"Name",
}

var clusterID string
var err error
for _, tag := range clusterIDTags {
clusterID, err = ec2Client.GetClusterTag(tag)
if err != nil && clusterID != "" {
break
}
}
if clusterID == "" {
clusterID = defaultClusterID
}
glog.Info("Using cluster ID ", clusterID)
return clusterID
}
mogren marked this conversation as resolved.
Show resolved Hide resolved

func (p *cloudWatchPublisher) getCloudWatchMetricDatumDimensions() []*cloudwatch.Dimension {
return []*cloudwatch.Dimension{
{
Expand Down