-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(instrumentor): generic instrumentation device handling (#765)
- Loading branch information
Showing
15 changed files
with
121 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package common | ||
|
||
type OdigosInstrumentationDevice string | ||
|
||
const ( | ||
JavaDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/java" | ||
PythonDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/python" | ||
GoDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/go" | ||
DotNetDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/dotnet" | ||
JavascriptDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/javascript" | ||
) | ||
|
||
var InstrumentationDevices = []OdigosInstrumentationDevice{ | ||
JavaDeviceName, | ||
PythonDeviceName, | ||
GoDeviceName, | ||
DotNetDeviceName, | ||
JavascriptDeviceName, | ||
} | ||
|
||
func ProgrammingLanguageToInstrumentationDevice(language ProgrammingLanguage) OdigosInstrumentationDevice { | ||
switch language { | ||
case JavaProgrammingLanguage: | ||
return JavaDeviceName | ||
case PythonProgrammingLanguage: | ||
return PythonDeviceName | ||
case GoProgrammingLanguage: | ||
return GoDeviceName | ||
case DotNetProgrammingLanguage: | ||
return DotNetDeviceName | ||
case JavascriptProgrammingLanguage: | ||
return JavascriptDeviceName | ||
default: | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package instrumentation | ||
|
||
import ( | ||
odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" | ||
"github.com/keyval-dev/odigos/common" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
) | ||
|
||
type CollectorInfo struct { | ||
Hostname string | ||
Port int | ||
} | ||
|
||
func ModifyObject(original *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) error { | ||
var modifiedContainers []v1.Container | ||
for _, container := range original.Spec.Containers { | ||
containerLanguage := getLanguageOfContainer(instrumentation, container.Name) | ||
if containerLanguage == nil { | ||
continue | ||
} | ||
|
||
instrumentationDeviceName := common.ProgrammingLanguageToInstrumentationDevice(*containerLanguage) | ||
if instrumentationDeviceName == "" { | ||
// should not happen, only for safety | ||
continue | ||
} | ||
|
||
if container.Resources.Limits == nil { | ||
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) | ||
} | ||
container.Resources.Limits[v1.ResourceName(instrumentationDeviceName)] = resource.MustParse("1") | ||
|
||
modifiedContainers = append(modifiedContainers, container) | ||
} | ||
|
||
original.Spec.Containers = modifiedContainers | ||
return nil | ||
} | ||
|
||
func Revert(original *v1.PodTemplateSpec) { | ||
for _, instrumentationDevice := range common.InstrumentationDevices { | ||
removeDeviceFromPodSpec(instrumentationDevice, original) | ||
} | ||
} | ||
|
||
func removeDeviceFromPodSpec(deviceName common.OdigosInstrumentationDevice, podSpec *v1.PodTemplateSpec) { | ||
for _, container := range podSpec.Spec.Containers { | ||
delete(container.Resources.Limits, v1.ResourceName(deviceName)) | ||
delete(container.Resources.Requests, v1.ResourceName(deviceName)) | ||
} | ||
} | ||
|
||
func getLanguageOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) *common.ProgrammingLanguage { | ||
for _, l := range instrumentation.Spec.Languages { | ||
if l.ContainerName == containerName { | ||
return &l.Language | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.