Skip to content

Commit

Permalink
Add changes missing after splitting the branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Molter73 committed Apr 1, 2024
1 parent b623e54 commit d7fb9bc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 60 deletions.
44 changes: 44 additions & 0 deletions collector/lib/ContainerMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef _CONTAINER_METADATA_H_
#define _CONTAINER_METADATA_H_

#include "system-inspector/EventExtractor.h"

namespace collector {

class ContainerMetadata {
public:
ContainerMetadata(sinsp* inspector) : inspector_(inspector) {
event_extractor_.Init(inspector);
}

inline std::string GetNamespace(sinsp_evt* event) {
const char* ns = event_extractor_.get_k8s_namespace(event);
return ns != nullptr ? ns : "";
}

inline std::string GetNamespace(const std::string& container_id) {
return GetContainerLabel(container_id, "io.kubernetes.pod.namespace");
}

inline std::string GetContainerLabel(const std::string& container_id, const std::string& label) {
const auto& containers = *inspector_->m_container_manager.get_containers();
if (containers.count(container_id) == 0) {
return "";
}

const auto& container = containers.at(container_id);
if (container->m_labels.count(label) == 0) {
return "";
}

return container->m_labels.at(label);
}

private:
system_inspector::EventExtractor event_extractor_;
sinsp* inspector_;
};

} // namespace collector

#endif // _CONTAINER_METADATA_H_
56 changes: 0 additions & 56 deletions collector/lib/K8s.h

This file was deleted.

2 changes: 1 addition & 1 deletion collector/lib/ProcessSignalFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ ProcessSignal* ProcessSignalFormatter::CreateProcessSignal(sinsp_evt* event) {
}

CLOG(DEBUG) << "Process (" << signal->container_id() << ": " << signal->pid() << "): "
<< signal->name() << "[" << k8s_.GetNamespace(event) << "] "
<< signal->name() << "[" << container_metadata_.GetNamespace(event) << "] "
<< " (" << signal->exec_file_path() << ")"
<< " " << signal->args();

Expand Down
6 changes: 3 additions & 3 deletions collector/lib/ProcessSignalFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#include "storage/process_indicator.pb.h"

#include "CollectorStats.h"
#include "ContainerMetadata.h"
#include "EventNames.h"
#include "K8s.h"
#include "ProtoSignalFormatter.h"
#include "system-inspector/EventExtractor.h"

namespace collector {

class ProcessSignalFormatter : public ProtoSignalFormatter<sensor::SignalStreamMessage> {
public:
ProcessSignalFormatter(sinsp* inspector) : event_names_(EventNames::GetInstance()), k8s_(inspector) {
ProcessSignalFormatter(sinsp* inspector) : event_names_(EventNames::GetInstance()), container_metadata_(inspector) {
event_extractor_.Init(inspector);
}

Expand All @@ -42,7 +42,7 @@ class ProcessSignalFormatter : public ProtoSignalFormatter<sensor::SignalStreamM

const EventNames& event_names_;
system_inspector::EventExtractor event_extractor_;
K8s k8s_;
ContainerMetadata container_metadata_;
};

} // namespace collector
Expand Down

0 comments on commit d7fb9bc

Please sign in to comment.