Skip to content

Commit

Permalink
Added Version to NGINX
Browse files Browse the repository at this point in the history
  • Loading branch information
yodigos committed Aug 27, 2024
1 parent 308ae94 commit 60692ab
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func otelSdkConfigCommunity() map[common.ProgrammingLanguage]common.OtelSdk {
common.GoProgrammingLanguage: common.OtelSdkEbpfCommunity,
common.DotNetProgrammingLanguage: common.OtelSdkNativeCommunity,
common.JavascriptProgrammingLanguage: common.OtelSdkNativeCommunity,
common.NginxProgrammingLanguage: common.OtelSdkNativeCommunity,
}
}

Expand All @@ -194,6 +195,7 @@ func otelSdkConfigCloud() map[common.ProgrammingLanguage]common.OtelSdk {
common.GoProgrammingLanguage: common.OtelSdkEbpfEnterprise,
common.DotNetProgrammingLanguage: common.OtelSdkNativeCommunity,
common.JavascriptProgrammingLanguage: common.OtelSdkNativeCommunity,
common.NginxProgrammingLanguage: common.OtelSdkNativeCommunity,
}
}

Expand Down
10 changes: 10 additions & 0 deletions odiglet/pkg/instrumentation/instrumentlang/nginx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package instrumentlang

import (
"github.com/odigos-io/odigos/common"
"k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

func Nginx(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
return &v1beta1.ContainerAllocateResponse{}
}
2 changes: 1 addition & 1 deletion odiglet/pkg/kube/runtime_details/inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func runtimeInspection(pods []corev1.Pod, ignoredContainers []string) ([]odigosv
var detectErr error

for _, proc := range processes {
programLanguageDetails, detectErr = inspectors.DetectLanguage(proc)
programLanguageDetails, detectErr = inspectors.DetectLanguage(proc, pod.Status.PodIP)
if detectErr == nil && programLanguageDetails.Language != common.UnknownProgrammingLanguage {
inspectProc = &proc
break
Expand Down
11 changes: 9 additions & 2 deletions procdiscovery/pkg/inspectors/langdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package inspectors

import (
"fmt"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/nginx"

"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/dotnet"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/golang"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/java"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/mysql"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/nginx"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/nodejs"
"github.com/odigos-io/odigos/procdiscovery/pkg/inspectors/python"
"github.com/odigos-io/odigos/procdiscovery/pkg/process"
Expand Down Expand Up @@ -39,7 +39,7 @@ var inspectorsList = []inspector{
// DetectLanguage returns the detected language for the process or
// common.UnknownProgrammingLanguage if the language could not be detected, in which case error == nil
// if error or language detectors disagree common.UnknownProgrammingLanguage is also returned
func DetectLanguage(process process.Details) (common.ProgramLanguageDetails, error) {
func DetectLanguage(process process.Details, podIp string) (common.ProgramLanguageDetails, error) {
detectedProgramLanguageDetails := common.ProgramLanguageDetails{
Language: common.UnknownProgrammingLanguage,
}
Expand All @@ -62,5 +62,12 @@ func DetectLanguage(process process.Details) (common.ProgramLanguageDetails, err
}
}

if detectedProgramLanguageDetails.Language == common.NginxProgrammingLanguage {
runtimeVersion, err := nginx.GetNginxVersion(podIp)
if err == nil {
detectedProgramLanguageDetails.RuntimeVersion = runtimeVersion
}
}

return detectedProgramLanguageDetails, nil
}
23 changes: 23 additions & 0 deletions procdiscovery/pkg/inspectors/nginx/nginx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nginx

import (
"net/http"
"regexp"
"strings"

"github.com/odigos-io/odigos/common"
Expand All @@ -22,3 +24,24 @@ func (j *NginxInspector) Inspect(p *process.Details) (common.ProgramLanguageDeta

return programLanguageDetails, false
}

func GetNginxVersion(podIP string) (string, error) {
resp, err := http.Get("http://" + podIP)
if err != nil {
return "", nil
}
defer resp.Body.Close()

serverHeader := resp.Header.Get("Server")
if serverHeader == "" {
return "", nil
}

re := regexp.MustCompile(`nginx/(\d+\.\d+\.\d+)`)
match := re.FindStringSubmatch(serverHeader)
if len(match) != 2 {
return "", nil
}

return match[1], nil
}

0 comments on commit 60692ab

Please sign in to comment.