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

improving error messages, updating .gitignore and README #13

Merged
merged 1 commit into from
Aug 16, 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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
otel-plugin
otel
otel
*.json
*.tar.gz
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This is a plugin that makes it easy to use OTel with Spin.

Spin applications have the ability to export metrics and trace data. This plugin provides dashboards for viewing the data.

## Requirements

This plugin relies on third-party software to work properly. Please be sure you have the following installed before continuing:

- Latest version of [Docker](https://www.docker.com/products/docker-desktop)

# Installation

The trigger is installed as a Spin plugin. It can be installed from a release or build.
Expand Down Expand Up @@ -34,7 +40,7 @@ Alternatively, use the `spin pluginify` plugin to install from a fresh build. Th
```sh
spin plugins install pluginify
go build -o otel
spin pluginify install
spin pluginify --install
```

# Usage
Expand Down
4 changes: 4 additions & 0 deletions cmd/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func getIDs(dockerOutput []byte) []string {
}

func cleanUp() error {
if err := checkDocker(); err != nil {
return err
}

fmt.Println("Stopping Spin OTel Docker containers...")

getContainers := exec.Command("docker", "ps")
Expand Down
21 changes: 18 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"os/exec"
"path"

open "github.com/fermyon/otel-plugin/cmd/open"
Expand All @@ -28,20 +29,34 @@ func setOtelConfigPath() error {
otelConfigPath = path.Join(path.Dir(executablePath), otelConfigDirName)

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 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
}

// checkDocker checks whether Docker is installed and the Docker daemon is running
func checkDocker() error {
cmd := exec.Command("docker", "--version")
if err := cmd.Run(); err != nil {
return fmt.Errorf("Docker appears not to be installed, so please visit their install page and try again once installed: https://www.docker.com/products/docker-desktop")
}

cmd = exec.Command("docker", "info")
if err := cmd.Run(); err != nil {
return fmt.Errorf("The Docker daemon appears not to be running. The command to start Docker depends on your operating system. For instructions, check the correct page under https://docs.docker.com/engine/install")
}

return nil
}

func Execute() {
if err := setOtelConfigPath(); err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("error finding the otel-config directory: %w", err))
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: 6 additions & 2 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ var setUpCmd = &cobra.Command{
}

func setUp() error {
if err := checkDocker(); err != nil {
return err
}

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")
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")
Expand All @@ -36,6 +40,6 @@ func setUp() error {
return err
}

fmt.Println("The Spin OTel resources are now running. Be sure to run the `spin otel cleanup` command when you are finished using them.")
fmt.Println("The Spin OTel resources are now running. Be sure to run the \"spin otel cleanup\" command when you are finished using them.")
return nil
}
8 changes: 6 additions & 2 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var upCmd = &cobra.Command{
Use: "up",
Short: "Runs a Spin App with the default OTel environment variables.",
Long: "Runs a Spin App with the default OTel environment variables. Any flags that work with the `spin up` command, will work with the `spin otel up` command: 'spin otel up -- --help'",
Long: "Runs a Spin App with the default OTel environment variables. Any flags that work with the \"spin up\" command, will work with the \"spin otel up\" command: \"spin otel up -- --help\"",
RunE: func(cmd *cobra.Command, args []string) error {
if err := up(args); err != nil {
return err
Expand All @@ -22,9 +22,13 @@ var upCmd = &cobra.Command{
}

func up(args []string) error {
if err := checkDocker(); err != nil {
asteurer marked this conversation as resolved.
Show resolved Hide resolved
return err
}

pathToSpin := os.Getenv("SPIN_BIN_PATH")
if pathToSpin == "" {
return fmt.Errorf("please ensure that you are running 'spin otel up', rather than calling the OTel plugin binary directly")
return fmt.Errorf("Please ensure that you are running \"spin otel up\", rather than calling the OTel plugin binary directly")
}

// Passing flags and args after the '--'
Expand Down
23 changes: 0 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
package main

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

"github.com/fermyon/otel-plugin/cmd"
)

func main() {
if err := checkDependencies(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

cmd.Execute()
}

func checkDependencies() error {
cmd := exec.Command("docker", "--version")
if err := cmd.Run(); err != nil {
return fmt.Errorf("docker appears not to be installed, so please visit their install page and try again once installed: https://www.docker.com/products/docker-desktop/")
}

cmd = exec.Command("docker", "info")
if err := cmd.Run(); err != nil {
return fmt.Errorf("the docker daemon appears not to be running, so please start the daemon and try again")
}

return nil
}
Loading