This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Correctly remove the dynamic replicaset from the pod_name #100
Merged
frankreno
merged 2 commits into
SumoLogic:master
from
Hearst-Hatchery:correctly-remove-dynamic-bits
Dec 6, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,31 @@ def is_number?(string) | |
true if Float(string) rescue false | ||
end | ||
|
||
def strip_dynamic_bits(k8s_metadata) | ||
# Strip out dynamic bits from pod name. | ||
# NOTE: Kubernetes deployments append a template hash. | ||
# At the moment this can be in 3 different forms: | ||
# 1) pre-1.8: numeric in pod_template_hash and pod_parts[-2] | ||
# 2) 1.8-1.11: numeric in pod_template_hash, hash in pod_parts[-2] | ||
# 3) post-1.11: hash in pod_template_hash and pod_parts[-2] | ||
|
||
pod_parts = k8s_metadata[:pod].split("-") | ||
pod_template_hash = k8s_metadata[:"label:pod-template-hash"] | ||
if (pod_template_hash == pod_parts[-2] || | ||
to_hash(pod_template_hash) == pod_parts[-2]) | ||
k8s_metadata[:pod_name] = pod_parts[0..-3].join("-") | ||
else | ||
k8s_metadata[:pod_name] = pod_parts[0..-2].join("-") | ||
end | ||
end | ||
|
||
def to_hash(pod_template_hash) | ||
# Convert the pod_template_hash to an alphanumeric string using the same | ||
# logic Kubernetes uses at https://github.com/kubernetes/apimachinery/blob/master/pkg/util/rand/rand.go#L119 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use a permanent link here in case this module moves: |
||
alphanums = "bcdfghjklmnpqrstvwxz2456789" | ||
pod_template_hash.each_byte.map { |i| alphanums[i.to_i % alphanums.length] }.join("") | ||
end | ||
|
||
def filter(tag, time, record) | ||
# Set the sumo metadata fields | ||
sumo_metadata = record["_sumo_metadata"] || {} | ||
|
@@ -119,14 +144,7 @@ def filter(tag, time, record) | |
end | ||
end | ||
|
||
# Strip out dynamic bits from pod name. | ||
# NOTE: Kubernetes deployments append a template hash. | ||
pod_parts = k8s_metadata[:pod].split("-") | ||
if is_number?(pod_parts[-2]) | ||
k8s_metadata[:pod_name] = pod_parts[0..-3].join("-") | ||
else | ||
k8s_metadata[:pod_name] = pod_parts[0..-2].join("-") | ||
end | ||
strip_dynamic_bits(k8s_metadata) | ||
|
||
if annotations["sumologic.com/exclude"] == "true" | ||
return nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend
def sanitize_pod_name