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

implement enhance-k8s-metadata plugin with label reading #33

Merged
merged 5 commits into from
May 31, 2019

Conversation

bin3377
Copy link

@bin3377 bin3377 commented May 28, 2019

  • reading labels of pod
  • caching
  • unit test

@lei-sumo @samjsong
FYI - @maimaisie @yuting-liu @rvmiller89

@bin3377 bin3377 requested review from lei-sumo and samjsong May 28, 2019 20:28
Copy link
Contributor

@lei-sumo lei-sumo left a comment

Choose a reason for hiding this comment

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

I have some question around authentication and code readability. Otherwise, looks reasonable to me.

def filter(tag, time, record)
decorate_record(record)
Copy link
Contributor

Choose a reason for hiding this comment

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

time not used here? Or it is inside record?

Copy link
Author

Choose a reason for hiding this comment

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

it's inside the record. time here is only for showing relative message in fluentd log

log.debug "Record doesn't have [#{@in_namespace_path}] field"
elsif pod_name.nil?
log.debug "Record doesn't have [#{@in_pod_path}] field"
else
Copy link
Contributor

Choose a reason for hiding this comment

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

So we will only get label for pod, but not for other objects?

Copy link
Author

Choose a reason for hiding this comment

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

yes

# parameters for read/write record
config_param :in_namespace_path, :string, default: '$.namespace'
config_param :in_pod_path, :string, default: '$.pod'
config_param :out_root, :string, default: 'kubernetes'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part even configurable?

Copy link
Author

Choose a reason for hiding this comment

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

we probably need it's configurable for reuse it on metrics/log. I don't think it's changeable if we want application work

@kubernetes_url = "https://#{env_host}:#{env_port}/api" unless env_host.nil? || env_port.nil?
end
log.info "Kubernetes URL: '#{@kubernetes_url}'"

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain a bit how authentication works? Where does customer get certificates or bearer token?

Copy link
Author

Choose a reason for hiding this comment

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

These files/tokens/env are injected by k8s when containers are launched so the processes inside of containers can talk to k8s-apiserver, k8s-dns, services, etc.
In a typical cluster, customer don't need to setup any of them, they are automatically generated.

To look into it, a simplest way is running into the containers:
kubectl exec -it <pod-name> /bin/sh

def init_cache
@all_caches = {
CACHE_TYPE_POD_LABELS => LruRedux::TTL::ThreadSafeCache.new(@cache_size, @cache_ttl),
CACHE_TYPE_OWNER_REFS => LruRedux::TTL::ThreadSafeCache.new(@cache_size, @cache_ttl)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does owner refs do? Don't see any usage here?

Copy link
Author

Choose a reason for hiding this comment

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

Planning to use it later for deployment lookup. I can remove it for now

cache = @all_caches[CACHE_TYPE_POD_LABELS]
labels = cache[key]
if labels.nil?
labels = fetch_pod_labels(namespace_name, pod_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

A general question: it's a bit hard to follow this kind of function call in another module. Is it by convention people ignore the class reference? Would be much easier to follow if we know where doesn't that function come from. Also what if required modules overload a method, which one would be used?

Copy link
Author

Choose a reason for hiding this comment

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

You can consider the module is another approach to do something like writing util functions in trait in Scala but more flexible. (e.g. duck typing) It's more natural way to reuse code in Ruby rather than using inheritance.

For connivence, if you install Ruby plugin in VS code (and some dependency gems following the instruction), it can support Cmd+Click to jump between functions from different modules

Copy link
Contributor

Choose a reason for hiding this comment

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

Gtk. Thanks!

Copy link
Contributor

@samjsong samjsong left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but I don't really have much background with authentication and I would appreciate if you could explain a bit how it works 😄

@bin3377 bin3377 merged commit b0eaba3 into master May 31, 2019
@bin3377 bin3377 deleted the byi-plugin-impl branch May 31, 2019 20:07
module SumoLogic
module Kubernetes
# module for connecting to Kubernetes cluster
module Connector
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to re-use it in the events plugin?

Copy link
Author

Choose a reason for hiding this comment

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

It's possible, but need to split the code into a mixin so different plugins can refer to.
Or you can just copy the code into your plugin first with same module names and later we can merge and change the dependencies

psaia pushed a commit to psaia/sumologic-kubernetes-collection that referenced this pull request May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants