Skip to content

Commit 788df9d

Browse files
authored
Merge pull request #10 from asteurer/path-fix
fixing otel-config path bug
2 parents e6e3e96 + 29697f4 commit 788df9d

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

cmd/cleanup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func getIDs(dockerOutput []byte) []string {
2525

2626
for _, entry := range outputArray {
2727
// Each container in the Docker Compose stack will have the name of the directory
28-
if strings.Contains(entry, otelConfigDir) {
28+
if strings.Contains(entry, otelConfigDirName) {
2929
fields := strings.Fields(entry)
3030
if len(fields) > 0 {
3131
result = append(result, fields[0])

cmd/root.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"path"
67

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

17-
var otelConfigDir = "otel-config"
18+
var otelConfigDirName = "otel-config"
19+
var otelConfigPath string
20+
21+
// setOtelConfigPath allows for someone to run the otel plugin directly from source or via the Spin plugin installation
22+
func setOtelConfigPath() error {
23+
executablePath, err := os.Executable()
24+
if err != nil {
25+
return err
26+
}
27+
28+
otelConfigPath = path.Join(path.Dir(executablePath), otelConfigDirName)
29+
30+
if _, err := os.Stat(otelConfigPath); os.IsNotExist(err) {
31+
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\"")
32+
}
33+
34+
return nil
35+
}
1836

1937
func Execute() {
38+
if err := setOtelConfigPath(); err != nil {
39+
fmt.Fprintln(os.Stderr, fmt.Errorf("error finding the otel-config directory: %w", err))
40+
os.Exit(1)
41+
}
42+
2043
if err := rootCmd.Execute(); err != nil {
2144
fmt.Fprintln(os.Stderr, err)
2245
os.Exit(1)

cmd/setup.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56
"os/exec"
67
"path"
78

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

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

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

spin-pluginify.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "otel"
2-
version = "0.1.0"
2+
version = "0.1.1"
33
spin_compatibility = ">=2.5"
44
license = "Apache-2.0"
55
package = "otel"

0 commit comments

Comments
 (0)