-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Refactor metadata generator to support adding metadata across resources #14875
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
1 similar comment
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
||
func init() { | ||
autodiscover.Registry.AddProvider("kubernetes", AutodiscoverBuilder) | ||
} | ||
|
||
type Eventer interface { |
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.
exported type Eventer should have comment or be unexported
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
||
func init() { | ||
autodiscover.Registry.AddProvider("kubernetes", AutodiscoverBuilder) | ||
} | ||
|
||
type Eventer interface { |
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.
exported type Eventer should have comment or be unexported
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
||
func init() { | ||
autodiscover.Registry.AddProvider("kubernetes", AutodiscoverBuilder) | ||
} | ||
|
||
type Eventer interface { |
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.
exported type Eventer should have comment or be unexported
config *Config | ||
} | ||
|
||
func NewResourceMetadataGenerator(config *Config) *resource { |
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.
exported func NewResourceMetadataGenerator returns unexported type *metadata.resource, which can be annoying to use
exported function NewResourceMetadataGenerator should have comment or be unexported
} | ||
|
||
return p.Generate(po, opts...) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
resource *resource | ||
} | ||
|
||
func NewPodMetadataGenerator(cfg *Config, acfg *AddResourceMetadataConfig, client k8s.Interface, options kubernetes.WatchOptions) (MetaGen, error) { |
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.
exported function NewPodMetadataGenerator should have comment or be unexported
|
||
type FieldOptions func(common.MapStr) error | ||
|
||
func WithFields(key string, value interface{}) func(common.MapStr) { |
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.
exported function WithFields should have comment or be unexported
Stop() | ||
} | ||
|
||
type FieldOptions func(common.MapStr) error |
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.
exported type FieldOptions should have comment or be unexported
} | ||
} | ||
|
||
func (c *Config) ApplyConfig(cfg *common.Config) error { |
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.
exported method Config.ApplyConfig should have comment or be unexported
Namespace *common.Config `config:"config"` | ||
} | ||
|
||
func DefaultConfig() Config { |
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.
exported function DefaultConfig should have comment or be unexported
@@ -38,6 +38,10 @@ type MetaGenerator interface { | |||
ContainerMetadata(pod *Pod, container string, image string) common.MapStr | |||
} | |||
|
|||
type MetaGen interface { |
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.
exported type MetaGen should have comment or be unexported
} | ||
} | ||
|
||
func NewInformer(client kubernetes.Interface, resource Resource, opts WatchOptions) (cache.SharedInformer, string, error) { |
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.
exported function NewInformer should have comment or be unexported
} | ||
|
||
return s.Generate(po, opts...) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
|
||
type resource = Config | ||
|
||
func NewResourceMetadataGenerator(cfg *common.Config) *resource { |
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.
exported function NewResourceMetadataGenerator should have comment or be unexported
} | ||
|
||
return n.Generate(no, opts...) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
|
||
if indexers != nil { | ||
return cache.NewSharedIndexInformer(listwatch, resource, opts.SyncTimeout, indexers), objType, nil | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block
|
||
} | ||
|
||
// OnAdd does a no-op on a delete event |
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.
comment on exported method NoOpEventHandlerFuncs.OnDelete should be of the form "OnDelete ..."
|
||
} | ||
|
||
// OnAdd does a no-op on an update event |
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.
comment on exported method NoOpEventHandlerFuncs.OnUpdate should be of the form "OnUpdate ..."
return &config | ||
} | ||
|
||
func (r *Resource) Generate(obj kubernetes.Resource, options ...FieldOptions) common.MapStr { |
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.
exported method Resource.Generate should have comment or be unexported
"github.com/elastic/beats/libbeat/common/safemapstr" | ||
) | ||
|
||
type Resource = Config |
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.
exported type Resource should have comment or be unexported
return &config | ||
} | ||
|
||
func (r *Resource) Generate(obj kubernetes.Resource, options ...FieldOptions) common.MapStr { |
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.
exported method Resource.Generate should have comment or be unexported
"github.com/elastic/beats/libbeat/common/safemapstr" | ||
) | ||
|
||
type Resource = Config |
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.
exported type Resource should have comment or be unexported
fa3ef89
to
617fd17
Compare
617fd17
to
5a59671
Compare
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for namespace resources |
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.
comment on exported function NewNamespaceMetadataGenerator should be of the form "NewNamespaceMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for service resources |
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.
comment on exported function NewNodeMetadataGenerator should be of the form "NewNodeMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for namespace resources |
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.
comment on exported function NewNamespaceMetadataGenerator should be of the form "NewNamespaceMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for service resources |
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.
comment on exported function NewNodeMetadataGenerator should be of the form "NewNodeMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for service resources |
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.
comment on exported function NewServiceMetadataGenerator should be of the form "NewServiceMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for service resources |
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.
comment on exported function NewNodeMetadataGenerator should be of the form "NewNodeMetadataGenerator ..."
resource *Resource | ||
} | ||
|
||
// NewPodMetadataGenerator creates a metagen for service resources |
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.
comment on exported function NewServiceMetadataGenerator should be of the form "NewServiceMetadataGenerator ..."
#14738 needs to be merged first |
5a59671
to
46bdf3b
Compare
@exekias since this breaks the schema can you let me know places where that information need to be updated on Beats side? |
5871578
to
c433691
Compare
e51dfff
to
fcb2025
Compare
@odacremolbap i have made the necessary changes. i will create the git issue at the time of merge if that is ok? |
lgtm but there is still this request by @exekias #14875 (comment) would you mindadding docs on the parameter? |
I missed that you already added those docs. |
ok to test |
…es (elastic#14875) * Refactor metagen to allow multiple resources to be enriched (cherry picked from commit dba8f74)
This PR attempts to refactor metadata generator to support enrichment of resources metadata on top of other resources.
Ex: enriching a pod object with information from a node and namespace object.
This PR does the same only for the autodiscover provider of kubernetes. It adds a configuration
add_resource_metadata
to allow specifying what resources should be used for enrichment.Sample configuration:
this would ensure that we additionally add namespace metadata along with the service metadata.
pods can be enriched with node and namespace metadata. the
namespace
andnode
parameters ofadd_resource_metadata
can takeinclude_*
,exlude_*
configs similar to the parent resource.closes #13873