github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/internal/orbs/datadog/datadog.go (about)

     1  package datadog
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	circle "github.com/drone/go-convert/convert/circle/yaml"
     8  	harness "github.com/drone/spec/dist/go"
     9  )
    10  
    11  func Convert(command string, step *circle.Custom) *harness.Step {
    12  	switch command {
    13  	case "":
    14  		return nil // not supported
    15  	case "setup":
    16  		return convertSetup(step)
    17  	case "stop":
    18  		return convertStop(step)
    19  	default:
    20  		return nil // not supported
    21  	}
    22  }
    23  
    24  func convertSetup(step *circle.Custom) *harness.Step {
    25  	version := "7" // default agent version
    26  
    27  	envs := map[string]string{
    28  		"DD_HOSTNAME":     "none",
    29  		"DD_INSTALL_ONLY": "true",
    30  		"DD_APM_ENABLED":  "true",
    31  	}
    32  
    33  	if s, _ := step.Params["site"].(string); s != "" {
    34  		envs["DD_SITE"] = s
    35  	}
    36  	if s, _ := step.Params["agent_major_version"].(string); s != "" {
    37  		envs["DD_AGENT_MAJOR_VERSION"] = s
    38  		version = s
    39  	}
    40  	if s, _ := step.Params["api_key"].(string); s != "" {
    41  		envs["DD_API_KEY"] = s
    42  	}
    43  
    44  	commands := []string{
    45  		fmt.Sprintf(`bash -c "$(curl -L "https://s3.amazonaws.com/dd-agent/scripts/install_script_agent%s.sh")"`, version),
    46  		`find /etc/datadog-agent/conf.d/ -iname "*.yaml.default" -delete`,
    47  		`service datadog-agent start`,
    48  		`echo "waiting for data-dog agent to start"`,
    49  		`sleep 30`,
    50  	}
    51  
    52  	return &harness.Step{
    53  		Name: "datadog_setup",
    54  		Type: "script",
    55  		Spec: &harness.StepBackground{
    56  			Run:  strings.Join(commands, "\n"),
    57  			Envs: envs,
    58  		},
    59  	}
    60  }
    61  
    62  func convertStop(step *circle.Custom) *harness.Step {
    63  	commands := []string{
    64  		// Stop Datadog Agent
    65  		"service datadog-agent stop",
    66  	}
    67  
    68  	return &harness.Step{
    69  		Name: "datadog_stop",
    70  		Type: "script",
    71  		Spec: &harness.StepBackground{
    72  			Run: strings.Join(commands, "\n"),
    73  		},
    74  	}
    75  }