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

fixing otel-config path bug #10

Merged
merged 3 commits into from
Aug 15, 2024
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
2 changes: 1 addition & 1 deletion cmd/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getIDs(dockerOutput []byte) []string {

for _, entry := range outputArray {
// Each container in the Docker Compose stack will have the name of the directory
if strings.Contains(entry, otelConfigDir) {
if strings.Contains(entry, otelConfigDirName) {
fields := strings.Fields(entry)
if len(fields) > 0 {
result = append(result, fields[0])
Expand Down
25 changes: 24 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"path"

open "github.com/fermyon/otel-plugin/cmd/open"
"github.com/spf13/cobra"
Expand All @@ -14,9 +15,31 @@ var rootCmd = &cobra.Command{
Long: "A plugin that makes using Spin with OTel easy by automatically standing up dependencies, sourcing environment variables, and linking to dashboards.",
}

var otelConfigDir = "otel-config"
var otelConfigDirName = "otel-config"
var otelConfigPath string

// setOtelConfigPath allows for someone to run the otel plugin directly from source or via the Spin plugin installation
func setOtelConfigPath() error {
executablePath, err := os.Executable()
if err != nil {
return err
}

otelConfigPath = path.Join(path.Dir(executablePath), otelConfigDirName)

asteurer marked this conversation as resolved.
Show resolved Hide resolved
if _, err := os.Stat(otelConfigPath); os.IsNotExist(err) {
return fmt.Errorf("the directory in which the plugin binary is executed is missing necessary files, so please make sure the plugin was installed using \"spin plugins install otel\"")
}

return nil
}

func Execute() {
if err := setOtelConfigPath(); err != nil {
calebschoepp marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintln(os.Stderr, fmt.Errorf("error finding the otel-config directory: %w", err))
os.Exit(1)
}

if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
8 changes: 7 additions & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"
"os/exec"
"path"

Expand All @@ -20,7 +21,12 @@ var setUpCmd = &cobra.Command{
}

func setUp() error {
cmd := exec.Command("docker", "compose", "-f", path.Join(otelConfigDir, "compose.yaml"), "up", "-d")
composeFile := path.Join(otelConfigPath, "compose.yaml")
if _, err := os.Stat(composeFile); os.IsNotExist(err) {
return fmt.Errorf("the otel-config directory is missing the \"compose.yaml\" file, so please consider removing and re-installing the otel plugin")
}

cmd := exec.Command("docker", "compose", "-f", composeFile, "up", "-d")

fmt.Println("Pulling and running Spin OTel resources...")

Expand Down
2 changes: 1 addition & 1 deletion spin-pluginify.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "otel"
version = "0.1.0"
version = "0.1.1"
spin_compatibility = ">=2.5"
license = "Apache-2.0"
package = "otel"
Expand Down
Loading