-
Notifications
You must be signed in to change notification settings - Fork 42
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 and enrich cloudbeat events #69
Changes from 13 commits
b68dceb
4812158
e105383
77a443a
73adf59
6cf20f5
322e71f
a7b24d1
5e80a03
f4b13e5
b35a8fd
4b2373a
43baff4
d1dbb9c
ebdb3f1
366d31c
2905f65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,16 @@ func (f EKSFetcher) Fetch(ctx context.Context) ([]fetching.Resource, error) { | |
func (f EKSFetcher) Stop() { | ||
} | ||
|
||
// GetID TODO: Add resource id logic to all AWS resources | ||
func (r EKSResource) GetID() (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (r EKSResource) GetData() interface{} { | ||
return r | ||
} | ||
|
||
func (r EKSResource) GetMetadata() fetching.ResourceMetadata { | ||
//TODO implement me | ||
return fetching.ResourceMetadata{ | ||
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. in the issue you open include a list of fetchers to fix |
||
ID: "", | ||
Type: "", | ||
SubType: "", | ||
Name: "", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,20 @@ import ( | |
"github.com/elastic/cloudbeat/resources/fetching" | ||
) | ||
|
||
const ( | ||
FSResourceType = "file" | ||
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. |
||
FileSubType = "file" | ||
DirSubType = "directory" | ||
) | ||
|
||
type FileSystemResource struct { | ||
FileName string `json:"filename"` | ||
FileMode string `json:"mode"` | ||
Gid string `json:"gid"` | ||
Uid string `json:"uid"` | ||
Path string `json:"path"` | ||
Inode string `json:"inode"` | ||
SubType string `json:"sub_type"` | ||
} | ||
|
||
// FileSystemFetcher implement the Fetcher interface | ||
|
@@ -104,7 +111,7 @@ func FromFileInfo(info os.FileInfo, path string) (FileSystemResource, error) { | |
usr, _ := user.LookupId(u) | ||
group, _ := user.LookupGroupId(g) | ||
mod := strconv.FormatUint(uint64(info.Mode().Perm()), 8) | ||
inode := strconv.FormatUint(uint64(stat.Ino), 10) | ||
uri-weisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
inode := strconv.FormatUint(stat.Ino, 10) | ||
|
||
data := FileSystemResource{ | ||
FileName: info.Name(), | ||
|
@@ -113,6 +120,7 @@ func FromFileInfo(info os.FileInfo, path string) (FileSystemResource, error) { | |
Gid: group.Name, | ||
Path: path, | ||
Inode: inode, | ||
SubType: getSubType(info.IsDir()), | ||
} | ||
|
||
return data, nil | ||
|
@@ -121,10 +129,22 @@ func FromFileInfo(info os.FileInfo, path string) (FileSystemResource, error) { | |
func (f *FileSystemFetcher) Stop() { | ||
} | ||
|
||
func (r FileSystemResource) GetID() (string, error) { | ||
return r.Inode, nil | ||
} | ||
|
||
func (r FileSystemResource) GetData() interface{} { | ||
return r | ||
} | ||
|
||
func (r FileSystemResource) GetMetadata() fetching.ResourceMetadata { | ||
return fetching.ResourceMetadata{ | ||
ID: r.Inode, | ||
Type: FSResourceType, | ||
SubType: r.SubType, | ||
Name: r.Path, | ||
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. leave a note about this being the path from the container and not from the host |
||
} | ||
} | ||
|
||
func getSubType(isDir bool) string { | ||
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. that's a bit weird. |
||
if isDir { | ||
return DirSubType | ||
} | ||
return FileSubType | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,13 @@ func (r IAMResource) GetID() (string, error) { | |
func (r IAMResource) GetData() interface{} { | ||
return r.Data | ||
} | ||
|
||
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 did not remove 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. Thanks 💪 |
||
func (r IAMResource) GetMetadata() fetching.ResourceMetadata { | ||
//TODO implement me | ||
return fetching.ResourceMetadata{ | ||
ID: "", | ||
Type: "", | ||
SubType: "", | ||
Name: "", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
package fetchers | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/kubernetes" | ||
|
@@ -31,7 +30,11 @@ type K8sResource struct { | |
Data interface{} | ||
} | ||
|
||
const k8sObjMetadataField = "ObjectMeta" | ||
const ( | ||
k8sObjMetadataField = "ObjectMeta" | ||
k8sTypeMetadataField = "TypeMeta" | ||
k8sObjType = "k8s_object" | ||
) | ||
|
||
func GetKubeData(watchers []kubernetes.Watcher) []fetching.Resource { | ||
logp.L().Info("Fetching Kubernetes data") | ||
|
@@ -62,19 +65,43 @@ func GetKubeData(watchers []kubernetes.Watcher) []fetching.Resource { | |
return ret | ||
} | ||
|
||
func (r K8sResource) GetID() (string, error) { | ||
func (r K8sResource) GetData() interface{} { | ||
return r.Data | ||
} | ||
|
||
func (r K8sResource) GetMetadata() fetching.ResourceMetadata { | ||
k8sObjMeta := r.GetK8sObjectMeta() | ||
resourceID := k8sObjMeta.UID | ||
resourceName := k8sObjMeta.Name | ||
|
||
return fetching.ResourceMetadata{ | ||
ID: string(resourceID), | ||
Type: k8sObjType, | ||
SubType: r.GetSubType(), | ||
Name: resourceName, | ||
} | ||
} | ||
|
||
func (r K8sResource) GetK8sObjectMeta() metav1.ObjectMeta { | ||
k8sObj := reflect.Indirect(reflect.ValueOf(r.Data)) | ||
metadata, ok := k8sObj.FieldByName(k8sObjMetadataField).Interface().(metav1.ObjectMeta) | ||
if !ok { | ||
return "", fmt.Errorf("failed to retrieve object metadata") | ||
logp.L().Errorf("failed to retrieve object metadata, Resource: %#v", r) | ||
return metav1.ObjectMeta{} | ||
} | ||
|
||
uid := metadata.UID | ||
return string(uid), nil | ||
return metadata | ||
} | ||
|
||
func (r K8sResource) GetData() interface{} { | ||
return r.Data | ||
func (r K8sResource) GetSubType() string { | ||
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. Is there a reason not to fail and continue with an empty string value instead of the kind? 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. good question👆🏼 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. I think sending with empty subtype matches the current design pattern and is a good start (best effort). 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. Additionally, except for bugs I don't see any reason for this method ever failing so I wouldn't waste too much time thinking/debating it. 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. Thats a good point, What happens when there's no subtype? For example, in process. |
||
k8sObj := reflect.Indirect(reflect.ValueOf(r.Data)) | ||
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. try and redesign to avoid calling |
||
typeMeta, ok := k8sObj.FieldByName(k8sTypeMetadataField).Interface().(metav1.TypeMeta) | ||
if !ok { | ||
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. now i see what you meant... |
||
logp.L().Errorf("failed to retrieve type metadata, Resource: %#v", r) | ||
return "" | ||
} | ||
|
||
return typeMeta.Kind | ||
} | ||
|
||
// nullifyManagedFields ManagedFields field contains fields with dot that prevent from elasticsearch to index | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ const ( | |
// Expects format as the following: --<key><delimiter><value>. | ||
// For example: --config=a.json | ||
// The regex supports two delimiters "=" and "" | ||
CMDArgumentMatcher = "\\b%s[\\s=]\\/?(\\S+)" | ||
CMDArgumentMatcher = "\\b%s[\\s=]\\/?(\\S+)" | ||
ProcessResourceType = "process" | ||
ProcessSubType = "process" | ||
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. 💯 |
||
) | ||
|
||
type ProcessResource struct { | ||
|
@@ -163,10 +165,15 @@ func (f *ProcessesFetcher) readConfigurationFile(path string, data []byte) (inte | |
func (f *ProcessesFetcher) Stop() { | ||
} | ||
|
||
func (res ProcessResource) GetID() (string, error) { | ||
return res.PID, nil | ||
} | ||
|
||
func (res ProcessResource) GetData() interface{} { | ||
return res | ||
} | ||
|
||
func (res ProcessResource) GetMetadata() fetching.ResourceMetadata { | ||
return fetching.ResourceMetadata{ | ||
ID: res.PID, | ||
Type: ProcessResourceType, | ||
SubType: ProcessSubType, | ||
Name: res.Stat.Name, | ||
} | ||
} |
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.
please open an issue for that
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.
A task for implementing the missing
GetMetadata
method - #71