Skip to content
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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/samber/lo v1.52.0
github.com/spf13/cobra v1.10.1
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.44.0
golang.org/x/sync v0.18.0
golang.org/x/text v0.31.0
Expand Down Expand Up @@ -44,6 +45,7 @@ require (
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
Expand All @@ -56,6 +58,7 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
Expand Down
6 changes: 3 additions & 3 deletions internal/actions/db/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "time"

// ConnConfig is the top-level structure of the YAML config file (~/.draft/dbconnect.yml).
type ConnConfig struct {
Defaults map[string]DefaultConfig `yaml:"defaults"`
Environments map[string]EnvConfig `yaml:"environments"`
Connections map[string]ConnTypeConfig `yaml:"connections"`
Defaults map[string]DefaultConfig `yaml:"defaults"`
Environments map[string]EnvConfig `yaml:"environments"`
Connections map[string]ConnTypeConfig `yaml:"connections"`
}

// DefaultConfig holds per-type defaults (e.g. remote port).
Expand Down
2 changes: 2 additions & 0 deletions internal/actions/newservice/newservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (ns *NewService) createAllDirs() error {
folders := []string{
ns.input.ServicePath + "/config/app",
ns.input.ServicePath + "/config/sls",
ns.input.ServicePath + "/config/otel-layer",
}

return dirs.Create(folders...)
Expand Down Expand Up @@ -105,6 +106,7 @@ func (ns *NewService) getFileList() []dtos.FileEntry {
{Path: "/config/app/modules.pkl", Data: ns.tmpl.Config.App.ModulesPkl},
{Path: "/config/sls/environment.yml", Data: ns.tmpl.Config.Sls.EnvironmentYAML},
{Path: "/config/sls/resources.yml", Data: ns.tmpl.Config.Sls.ResourcesYAML},
{Path: "/config/otel-layer/collector.yaml", Data: ns.tmpl.Config.Sls.OtelCollectorYAML},
}

entries = append(entries, ns.getEntries()...)
Expand Down
1 change: 1 addition & 0 deletions internal/dtos/lambda_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type LambdaInput struct {
NextLambdaImportTag string
IsLegacy bool
UseDig bool
UseOtel bool
ReservedConcurrency string
UseIdempotency bool
}
1 change: 1 addition & 0 deletions internal/dtos/service_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ServiceInput struct {
NextLambdaImportTag string
IsLegacy bool
UseDig bool
UseOtel bool
ReservedConcurrency string
RoleName string
}
5 changes: 5 additions & 0 deletions internal/forms/newlambda/base_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func baseForm(input *dtos.LambdaInput) error {
if errSrv != nil {
return errSrv
}

useOtel, errOtel := project.IsOtelService(input.ServicePath)
if errOtel == nil {
input.UseOtel = useOtel
}
}

errName := inputs.Text("Lambda Name:",
Expand Down
1 change: 1 addition & 0 deletions internal/forms/newservice/newservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func GetForm(input *dtos.ServiceInput) error {
input.PackageName = data.Meta.PackageName
input.NextImportTag = data.NextImportTag
input.NextLambdaImportTag = data.NextLambdaImportTag
input.UseOtel = true

if err := baseForm(input); err != nil {
return err
Expand Down
17 changes: 13 additions & 4 deletions internal/pkg/inputs/select.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package inputs

import "github.com/charmbracelet/huh"
import (
"sort"

"github.com/charmbracelet/huh"
)

func Select[T comparable](title string, opts ...Option[T]) error {
input := huh.NewSelect[T]().Title(title)
Expand All @@ -15,10 +19,15 @@ func Select[T comparable](title string, opts ...Option[T]) error {
input.Description(inputOpts.description)
}

selectOpts := make([]huh.Option[T], 0, len(opts))
keys := make([]string, 0, len(inputOpts.options))
for k := range inputOpts.options {
keys = append(keys, k)
}
sort.Strings(keys)

for optKey, optVal := range inputOpts.options {
selectOpts = append(selectOpts, huh.NewOption(optKey, optVal))
selectOpts := make([]huh.Option[T], 0, len(inputOpts.options))
for _, optKey := range keys {
selectOpts = append(selectOpts, huh.NewOption(optKey, inputOpts.options[optKey]))
}

input.Options(selectOpts...)
Expand Down
18 changes: 18 additions & 0 deletions internal/project/detect_otel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package project

import (
"strings"

"github.com/Drafteame/draft/internal/pkg/files"
)

// IsOtelService reads the service's serverless.yml and returns true if the
// build command contains the otel build tag, indicating the service uses OpenTelemetry.
func IsOtelService(servicePath string) (bool, error) {
content, err := files.Read(servicePath + "/serverless.yml")
if err != nil {
return false, err
}

return strings.Contains(string(content), `"lambda.norpc,otel"`), nil
}
20 changes: 18 additions & 2 deletions internal/templates/config_sls.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package templates

type ConfigSls struct {
EnvironmentYAML []byte
ResourcesYAML []byte
EnvironmentYAML []byte
ResourcesYAML []byte
OtelCollectorYAML []byte
}

func loadConfigSls(v ConfigSlsSetter, data any) error {
Expand All @@ -11,6 +12,7 @@ func loadConfigSls(v ConfigSlsSetter, data any) error {
loaders := []func(*ConfigSls, any) error{
loadConfigSlsEnvironmentYAML,
loadConfigSlsResourcesYAML,
loadConfigSlsOtelCollectorYAML,
}

for _, loader := range loaders {
Expand Down Expand Up @@ -51,3 +53,17 @@ func loadConfigSlsResourcesYAML(v *ConfigSls, data any) error {

return nil
}

func loadConfigSlsOtelCollectorYAML(v *ConfigSls, data any) error {
name := "config/otel-layer/collector.yaml"
path := "tmpl/sls/config/otel-layer/collector.yaml.tmpl"

content, err := loadTemplate(name, path, data, sls)
if err != nil {
return err
}

v.OtelCollectorYAML = content

return nil
}
Loading