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

feat: run python agent alogside NR #1886

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions common/envOverwrite/overwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ func GetPatchedEnvValue(envName string, observedValue string, currentSdk *common

// temporary fix clean up observed value from the known webhook injected value
parts := strings.Split(observedValue, envMetadata.delim)
ignoreEnvValue := "-javaagent:/opt/sre-agent/sre-agent.jar"
const (
ignoredJavaAgentValue = "-javaagent:/opt/sre-agent/sre-agent.jar"
ignoredNRPythonPathAddition = "newrelic/bootstrap"
)
newValues := []string{}
for _, part := range parts {
if part == ignoreEnvValue {
if part == ignoredJavaAgentValue || strings.Contains(part, ignoredNRPythonPathAddition) {
continue
}
if strings.TrimSpace(part) == "" {
Expand Down
6 changes: 3 additions & 3 deletions instrumentor/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func ApplyInstrumentationDevicesToPodTemplate(original *corev1.PodTemplateSpec,
containerLanguage := getLanguageOfContainer(runtimeDetails, container.Name)
containerHaveOtherAgent := getContainerOtherAgents(runtimeDetails, container.Name)

// In case there is another agent in the container, we should not apply the instrumentation device.
if containerHaveOtherAgent != nil {
// In case there is another agent in the container, we should not apply the instrumentation device '*'.
// '*' - In Python, we can run it with New Relic (the only one we detect), but not in other languages.
if containerHaveOtherAgent != nil && containerLanguage != common.PythonProgrammingLanguage {
logger.Info("Container is running other agent, skip applying instrumentation device", "agent", containerHaveOtherAgent.Name, "container", container.Name)

// Not actually modifying the container, but we need to append it to the list.
modifiedContainers = append(modifiedContainers, container)
deviceSkippedDueToOtherAgent = true
continue

}
// handle containers with unknown language or ignored language
if containerLanguage == common.UnknownProgrammingLanguage || containerLanguage == common.IgnoredProgrammingLanguage || containerLanguage == common.NginxProgrammingLanguage {
Expand Down
12 changes: 12 additions & 0 deletions opampserver/pkg/connection/conncache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,21 @@ func (c *ConnectionsCache) AddConnection(instanceUid string, conn *ConnectionInf
connCopy := *conn
c.mux.Lock()
defer c.mux.Unlock()
c.RemoveMatchingConnections(conn.Pod.Name, conn.Pid)
c.liveConnections[instanceUid] = &connCopy
}

// RemoveMatchingConnections removes all connections that match the given podName and pid.
// This ensures that outdated connections are cleaned up, such as when a new process
// is spawned within the same pod (e.g., using os.execl in Python).
func (c *ConnectionsCache) RemoveMatchingConnections(podName string, pid int64) {
for k, v := range c.liveConnections {
if v.Pod.Name == podName && v.Pid == pid {
delete(c.liveConnections, k)
}
}
}

func (c *ConnectionsCache) RemoveConnection(instanceUid string) {
c.mux.Lock()
defer c.mux.Unlock()
Expand Down
Loading