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

[ASCII-2601] Create SSI component #32123

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Add ssi comp inside tracer bundle for ssi status and flares
  • Loading branch information
louis-cqrl committed Dec 13, 2024
commit 0fe413814bd5bedaf4b50a0c6ad629009a11bf28
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
/comp/core/workloadmeta @DataDog/container-platform
/comp/metadata/packagesigning @DataDog/agent-delivery
/comp/trace/etwtracer @DataDog/windows-agent
/comp/trace/ssi @DataDog//* @DataDog/TODO
/comp/autoscaling/datadogclient @DataDog/container-integrations
/comp/etw @DataDog/windows-agent
/comp/haagent @DataDog/ndm-core
Expand Down
6 changes: 6 additions & 0 deletions comp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ component temporarily wraps pkg/trace/config.

Package etwtracer provides ETW events to the .Net tracer

### [comp/trace/ssi](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/trace/ssi)

*Datadog Team*: /* TODO

Package ssi ... /* TODO: detailed doc comment for the component */

### [comp/trace/status](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/trace/status)

Package status implements the core status component information provider interface
Expand Down
5 changes: 4 additions & 1 deletion comp/trace/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package trace
import (
traceagentfx "github.com/DataDog/datadog-agent/comp/trace/agent/fx"
"github.com/DataDog/datadog-agent/comp/trace/config"
ssi "github.com/DataDog/datadog-agent/comp/trace/ssi/fx"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

Expand All @@ -23,5 +24,7 @@ import (
func Bundle() fxutil.BundleOptions {
return fxutil.Bundle(
config.Module(),
traceagentfx.Module())
traceagentfx.Module(),
ssi.Module(),
)
}
14 changes: 14 additions & 0 deletions comp/trace/ssi/def/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package ssi ... /* TODO: detailed doc comment for the component */
package ssi

// team: /* TODO: add team name */

// Component is the component type.
type Component interface {
/* TODO: define Component interface */
}
23 changes: 23 additions & 0 deletions comp/trace/ssi/fx/fx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package fx provides the fx module for the ssi component
package fx

import (
ssi "github.com/DataDog/datadog-agent/comp/trace/ssi/def"
ssiimpl "github.com/DataDog/datadog-agent/comp/trace/ssi/impl"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

// Module defines the fx options for this component
func Module() fxutil.Module {
return fxutil.Component(
fxutil.ProvideComponentConstructor(
ssiimpl.NewComponent,
),
fxutil.ProvideOptional[ssi.Component](),
)
}
119 changes: 119 additions & 0 deletions comp/trace/ssi/impl/ssi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package ssiimpl implements the ssi component interface
package ssiimpl

import (
"embed"
"io"

"github.com/DataDog/datadog-agent/comp/core/config"
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
"github.com/DataDog/datadog-agent/comp/core/status"
defssi "github.com/DataDog/datadog-agent/comp/trace/ssi/def"
)

// Requires defines the dependencies for the ssi component
type Requires struct {
Config config.Component
}

// Provides defines the output of the ssi component
type Provides struct {
Component defssi.Component

StatusProvider status.InformationProvider
louis-cqrl marked this conversation as resolved.
Show resolved Hide resolved
FlareProvider flaretypes.Provider
}

type ssiComp struct {
config config.Component
}

// NewComponent creates a new ssi component
func NewComponent(reqs Requires) (Provides, error) {
comp := ssiComp{
config: reqs.Config,
}

return Provides{
Component: comp,
StatusProvider: status.NewInformationProvider(comp),
FlareProvider: flaretypes.NewProvider(comp.fillFlare),
}, nil
}

//go:embed status_templates
var templatesFS embed.FS

// Name returns the name
func (ssi ssiComp) Name() string {
return "Single Step Instrumentation" // TODO: fix if needed
}

// Section return the section
func (ssi ssiComp) Section() string {
return "Single Step Instrumentation" // TODO: fix if needed
}

// JSON populates the status map
func (ssi ssiComp) JSON(_ bool, stats map[string]interface{}) error {
ssi.populateStatus(stats)
return nil
}

// Text renders the text output
func (ssi ssiComp) Text(_ bool, buffer io.Writer) error {
return status.RenderText(templatesFS, "ssi.tmpl", buffer, ssi.getStatusInfo())
}

// HTML renders the html output
func (ssi ssiComp) HTML(_ bool, buffer io.Writer) error {
return status.RenderHTML(templatesFS, "ssiHTML.tmpl", buffer, ssi.getStatusInfo())
}

func (ssi ssiComp) getStatusInfo() map[string]interface{} {
stats := make(map[string]interface{})

ssi.populateStatus(stats)

return stats
}

func (ssi ssiComp) populateStatus(stats map[string]interface{}) {
// TODO: populate statusData
status := make(map[string]interface{})
status["ssiStatus"] = "disabled"
if isSSIEnabled(ssi.config) {
status["ssiStatus"] = "enabled"
status["ociInstallerVersion"] = "" //TODO: fetch and assign the version here
status["injectorVersion"] = "" //TODO: fetch and assign the version here
if installedLibraries, ok := fetchInstalledLibraries(ssi.config); ok {
status["libraries"] = installedLibraries
}
}

stats["singleStepInstrumentation"] = status
}

func isSSIEnabled(_ config.Component) bool {
// TODO: implement
return false
}

func fetchInstalledLibraries(_ config.Component) (map[string]string, bool) {
//TODO: implement
return nil, false
}

// fillFlare add the Configuration files to flares.
func (ssi ssiComp) fillFlare(fb flaretypes.FlareBuilder) error {
if !isSSIEnabled(ssi.config) {
fb.AddFile("ssi.status", []byte("SSI is not enabled"))
}
//TODO: fill flare with SSI related information
return nil
}
17 changes: 17 additions & 0 deletions comp/trace/ssi/impl/status_templates/ssi.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ with .singleStepInstrumentation }}
{{ if .ssiStatusActivated }}
Status: {{ if eq .ssiStatus "enabled" }}Enabled{{ else }}Disabled{{ end }}

OCI Installer Version: {{ if .ociInstallerVersion }}{{ .ociInstallerVersion }}{{ else }}Not available{{ end }}
Injector Version: {{ if .injectorVersion }}{{ .injectorVersion }}{{ else }}Unable to fetch the version{{ end }}

Libraries Installed:
{{ if .libraries }}
{{ range $language, $version := .libraries }}
{{ $language }}: {{ $version }}
{{ end }}
{{ else }}
None
{{ end }}
{{ end }}
{{ end }}
20 changes: 20 additions & 0 deletions comp/trace/ssi/impl/status_templates/ssiHTML.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="stat">
<span class="stat_title">Single Step Instrumentation</span>
<span class="stat_data">
{{ with .singleStepInstrumentation }}
{{ if .ssiStatusActivated }}
Status: {{ if eq .ssiStatus "enabled" }}Enabled{{ else }}Disabled{{ end }}
OCI Installer Version: {{ if .ociInstallerVersion }}{{ .ociInstallerVersion }}{{ else }}Not available{{ end }}
Injector Version: {{ if .injectorVersion }}{{ .injectorVersion }}{{ else }}Unable to fetch the version{{ end }}
Libraries Installed:
{{ if .libraries }}
{{ range $language, $version := .libraries }}
{{ $language }}: {{ $version }}
{{ end }}
{{ else }}
None
{{ end }}
{{ end }}
{{ end }}
</span>
</div>
22 changes: 22 additions & 0 deletions comp/trace/ssi/mock/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build test

// Package mock provides a mock for the ssi component
package mock

import (
"testing"

ssi "github.com/DataDog/datadog-agent/comp/trace/ssi/def"
)

// Mock returns a mock for ssi component.
// If the comp doesn't have any public method the component does not need a mock
// TODO: Implement or remove the mock depending of your needs
func Mock(_ *testing.T) ssi.Component {
return nil
}
Loading