-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rhel-dockerfile-ci
- Loading branch information
Showing
141 changed files
with
1,657 additions
and
1,149 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
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 |
---|---|---|
@@ -1,53 +1,156 @@ | ||
package distros | ||
|
||
import ( | ||
"embed" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/odigos-io/odigos/common" | ||
"github.com/odigos-io/odigos/distros/distro" | ||
"github.com/odigos-io/odigos/distros/yamls" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func GetDefaultDistroNames(tier common.OdigosTier) map[common.ProgrammingLanguage]string { | ||
switch tier { | ||
case common.CommunityOdigosTier: | ||
return map[common.ProgrammingLanguage]string{ | ||
common.JavascriptProgrammingLanguage: "nodejs-community", | ||
common.PythonProgrammingLanguage: "python-community", | ||
common.DotNetProgrammingLanguage: "dotnet-community", | ||
common.JavaProgrammingLanguage: "java-community", | ||
common.GoProgrammingLanguage: "golang-community", | ||
type Defaulter interface { | ||
GetDefaultDistroNames() map[common.ProgrammingLanguage]string | ||
} | ||
|
||
type communityDefaulter struct{} | ||
|
||
var _ Defaulter = &communityDefaulter{} | ||
|
||
// TODO: remove/rename this once we have an enterprise instrumentor | ||
func NewCommunityDefaulter() *communityDefaulter { | ||
return &communityDefaulter{} | ||
} | ||
|
||
// TODO: remove this once we have an enterprise instrumentor | ||
func NewOnPremDefaulter() *onPremDefaulter { | ||
return &onPremDefaulter{} | ||
} | ||
|
||
// TODO: once we split the distros package this should be renamed | ||
func NewGetter() (*Getter, error) { | ||
g := Getter{} | ||
|
||
distrosByName, err := getDistrosMap(yamls.GetFS()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
g.distrosByName = distrosByName | ||
|
||
return &g, nil | ||
} | ||
|
||
func (c *communityDefaulter) GetDefaultDistroNames() map[common.ProgrammingLanguage]string { | ||
return map[common.ProgrammingLanguage]string{ | ||
common.JavascriptProgrammingLanguage: "nodejs-community", | ||
common.PythonProgrammingLanguage: "python-community", | ||
common.DotNetProgrammingLanguage: "dotnet-community", | ||
common.JavaProgrammingLanguage: "java-community", | ||
common.GoProgrammingLanguage: "golang-community", | ||
} | ||
} | ||
|
||
// TODO: remove this once we have an enterprise instrumentor | ||
type onPremDefaulter struct{} | ||
|
||
var _ Defaulter = &onPremDefaulter{} | ||
|
||
func (o *onPremDefaulter) GetDefaultDistroNames() map[common.ProgrammingLanguage]string { | ||
return map[common.ProgrammingLanguage]string{ | ||
common.JavascriptProgrammingLanguage: "nodejs-enterprise", | ||
common.PythonProgrammingLanguage: "python-enterprise", | ||
common.DotNetProgrammingLanguage: "dotnet-community", | ||
common.JavaProgrammingLanguage: "java-enterprise", | ||
common.GoProgrammingLanguage: "golang-enterprise", | ||
common.MySQLProgrammingLanguage: "mysql-enterprise", | ||
} | ||
} | ||
|
||
type Getter struct { | ||
distrosByName map[string]*distro.OtelDistro | ||
} | ||
|
||
func (g *Getter) GetDistroByName(distroName string) *distro.OtelDistro { | ||
return g.distrosByName[distroName] | ||
} | ||
|
||
type Provider struct { | ||
Defaulter | ||
*Getter | ||
} | ||
|
||
// NewProvider creates a new distributions provider. | ||
// A provider is a combination of a defaulter and a getter. | ||
// The defaulter is used to get the default distro names for each programming language. | ||
// The getter is used to get the distro object itself from the available distros. | ||
// | ||
// A provider is constructed from a single defaulter and one or more getters. | ||
// The getters are unioned together to create a single getter for the provider. | ||
// | ||
// Each default distribution must be provided by at least one of the getters. | ||
func NewProvider(defaulter Defaulter, getters ...*Getter) (*Provider, error) { | ||
if len(getters) == 0 { | ||
return nil, errors.New("at least one getter must be provided") | ||
} | ||
|
||
distros := make(map[string]*distro.OtelDistro) | ||
for _, g := range getters { | ||
for k, v := range g.distrosByName { | ||
distros[k] = v | ||
} | ||
case common.OnPremOdigosTier: | ||
return map[common.ProgrammingLanguage]string{ | ||
common.JavascriptProgrammingLanguage: "nodejs-enterprise", | ||
common.PythonProgrammingLanguage: "python-enterprise", | ||
common.DotNetProgrammingLanguage: "dotnet-community", | ||
common.JavaProgrammingLanguage: "java-enterprise", | ||
common.GoProgrammingLanguage: "golang-enterprise", | ||
common.MySQLProgrammingLanguage: "mysql-enterprise", | ||
} | ||
|
||
// make sure the default distributions are provided by at least one of the getters | ||
defaultDistroNames := defaulter.GetDefaultDistroNames() | ||
for _, distroName := range defaultDistroNames { | ||
if _, ok := distros[distroName]; !ok { | ||
return nil, fmt.Errorf("default distribution %s not found in any getter", distroName) | ||
} | ||
default: | ||
return nil | ||
} | ||
|
||
return &Provider{ | ||
Defaulter: defaulter, | ||
Getter: &Getter{ | ||
distrosByName: distros, | ||
}, | ||
}, nil | ||
} | ||
|
||
type distroResource struct { | ||
ApiVersion string `json:"apiVersion"` | ||
Spec distro.OtelDistro `json:"spec"` | ||
} | ||
|
||
var allDistros = []distro.OtelDistro{} | ||
func getDistrosMap(fs embed.FS) (map[string]*distro.OtelDistro, error) { | ||
files, err := fs.ReadDir(".") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
func init() { | ||
distroNames := yamls.GetAllDistroNames() | ||
for _, distroName := range distroNames { | ||
distro, err := yamls.ReadDistroFromYamlManifest(distroName) | ||
if err != nil { | ||
distrosByName := make(map[string]*distro.OtelDistro) | ||
|
||
for _, file := range files { | ||
if file.IsDir() { | ||
continue | ||
} | ||
allDistros = append(allDistros, *distro) | ||
} | ||
} | ||
|
||
func GetDistroByName(distroName string) *distro.OtelDistro { | ||
for i := range allDistros { | ||
if allDistros[i].Name == distroName { | ||
return &allDistros[i] | ||
yamlBytes, err := fs.ReadFile(file.Name()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
otelDistro := distroResource{} | ||
err = yaml.Unmarshal(yamlBytes, &otelDistro) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
distrosByName[otelDistro.Spec.Name] = &otelDistro.Spec | ||
} | ||
return nil | ||
|
||
return distrosByName, nil | ||
} |
Oops, something went wrong.