From 303eaf7356a33d62e4c0f2ab84106ae7ddcb7229 Mon Sep 17 00:00:00 2001 From: Clay Smith Date: Wed, 9 Mar 2022 09:35:17 -0800 Subject: [PATCH] Release v1.60.2 (#75) * unmark spans as deprecated * allow api_key to be set using a regular var, update docs * update acceptance test env --- .go-version | 2 +- Makefile | 2 +- README.md | 7 +++--- docs/index.md | 7 +++--- docs/resources/metric_dashboard.md | 24 ++++++++++++++---- examples/variables.tf | 5 ++++ examples/versions.tf | 6 ++--- exporter/exporter.go | 8 +++++- lightstep/provider.go | 34 +++++++++++++++++--------- lightstep/resource_metric_condition.go | 8 +++--- 10 files changed, 69 insertions(+), 34 deletions(-) diff --git a/.go-version b/.go-version index f7ba1bbd..25a7b6f8 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.60.1 \ No newline at end of file +1.60.2 \ No newline at end of file diff --git a/Makefile b/Makefile index 00d62165..ff18fecd 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ lint: .PHONY: acc-test acc-test: - @TF_ACC=true LIGHTSTEP_API_KEY=${LIGHTSTEP_API_KEY_STAGING} LIGHTSTEP_ORG="LightStep" LIGHTSTEP_ENV="staging" go test -v ./lightstep + @TF_ACC=true LIGHTSTEP_API_KEY=${LIGHTSTEP_API_KEY_PUBLIC} LIGHTSTEP_ORG="LightStep" LIGHTSTEP_ENV="public" go test -v ./lightstep .PHONY: ensure-clean-repo ensure-clean-repo: diff --git a/README.md b/README.md index 0190f719..9d15e564 100644 --- a/README.md +++ b/README.md @@ -20,21 +20,20 @@ terraform { required_providers { lightstep = { source = "lightstep/lightstep" - version = "1.60.1" + version = "1.60.2" } } } provider "lightstep" { - # Name of the *environment variable* where the API key is set - api_key_env_var = "LIGHTSTEP_API_KEY" + api_key = "your-lightstep-org-api-key" organization = "your-lightstep-organization" } # Example: Create AWS EC2 Dashboard module "aws-dashboards" { source = "lightstep/aws-dashboards/lightstep//modules/ec2-dashboard" - version = "1.60.0" + version = "1.60.2" lightstep_project = "your-lightstep-project" lightstep_oranization = "your-lightstep-organization" } diff --git a/docs/index.md b/docs/index.md index 07bfa4db..7f61af13 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,8 +14,8 @@ The [Lightstep](https://lightstep.com) Provider is for Terraform to manage Light ``` provider "lightstep" { - api_key_env_var = (environment variable where your LS API key is stored) - organization = (organization name) + api_key = "Lightstep organization API key" + organization = "Lightstep organization name" } ``` @@ -28,5 +28,6 @@ provider "lightstep" { ### Optional -- **api_key_env_var** (String) Environment variable for Lightstep api key. +- **api_key** (String) Lightstep organization api key. If not set, the provider will use the environment variable set in `api_key_env_var`. +- **api_key_env_var** (String) Environment variable to use when looking up the API Key. - **environment** (String) The name of the Lightstep environment, must be one of: staging, meta, public. diff --git a/docs/resources/metric_dashboard.md b/docs/resources/metric_dashboard.md index 4205019e..4bec7412 100644 --- a/docs/resources/metric_dashboard.md +++ b/docs/resources/metric_dashboard.md @@ -23,11 +23,6 @@ resource "lightstep_metric_dashboard" "customer_charges" { rank = 1 type = "timeseries" - y_axis { - min = 0.4 - max = 5.0 - } - query { hidden = false query_name = "a" @@ -48,6 +43,25 @@ resource "lightstep_metric_dashboard" "customer_charges" { } } } + + chart { + name = "Public API Latency" + rank = "2" + type = "timeseries" + + query { + query_name = "a" + display = "line" + hidden = false + + spans { + query = "service IN (\"public_api\")" + operator = "latency" + group_by_keys = [] + latency_percentiles = [50,95,99,99.9,] + } + } + } } ``` diff --git a/examples/variables.tf b/examples/variables.tf index 51c11e05..7735fdc9 100644 --- a/examples/variables.tf +++ b/examples/variables.tf @@ -4,6 +4,11 @@ variable "project" { type = string } +variable "lightstep_api_key" { + description = "Lightstep organization API Key" + type = string +} + variable "lightstep_organization" { description = "Name of Lightstep organization" type = string diff --git a/examples/versions.tf b/examples/versions.tf index 28cdc23d..b0101033 100644 --- a/examples/versions.tf +++ b/examples/versions.tf @@ -1,13 +1,13 @@ provider "lightstep" { - api_key_env_var = "LIGHTSTEP_API_KEY" - organization = var.lightstep_organization + api_key = var.lightstep_api_key + organization = var.lightstep_organization } terraform { required_providers { lightstep = { source = "lightstep/lightstep" - version = "1.51.6" + version = "1.60.2" } } required_version = "~> 1.1.0" diff --git a/exporter/exporter.go b/exporter/exporter.go index bd7007a7..219f7dc5 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -70,6 +70,12 @@ func Run(args ...string) error { log.Fatalf("error: LIGHTSTEP_ORG env variable must be set") } + // default to public API environment + lightstepEnv := "public" + if len(os.Getenv("LIGHTSTEP_ENV")) > 0 { + lightstepEnv = os.Getenv("LIGHTSTEP_ENV") + } + if len(args) < 4 { log.Fatalf("usage: %s export [resource-type] [project-name] [resource-id]", args[0]) } @@ -78,7 +84,7 @@ func Run(args ...string) error { log.Fatalf("error: only dashboard resources are supported at this time") } - c := client.NewClient(os.Getenv("LIGHTSTEP_API_KEY"), os.Getenv("LIGHTSTEP_ORG"), os.Getenv("LIGHTSTEP_ENV")) + c := client.NewClient(os.Getenv("LIGHTSTEP_API_KEY"), os.Getenv("LIGHTSTEP_ORG"), lightstepEnv) d, err := c.GetMetricDashboard(context.Background(), args[3], args[4]) if err != nil { diff --git a/lightstep/provider.go b/lightstep/provider.go index f93b2d03..5a64c5b1 100644 --- a/lightstep/provider.go +++ b/lightstep/provider.go @@ -3,11 +3,12 @@ package lightstep import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/meta" - "github.com/lightstep/terraform-provider-lightstep/version" "os" "regexp" + "github.com/hashicorp/terraform-plugin-sdk/v2/meta" + "github.com/lightstep/terraform-provider-lightstep/version" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -30,6 +31,11 @@ func Provider() *schema.Provider { ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(staging|meta|public)$`), "Must be one of: staging, meta, public"), Description: "The name of the Lightstep environment, must be one of: staging, meta, public.", }, + "api_key": { + Type: schema.TypeString, + Optional: true, + Description: "The API Key for a Lightstep organization.", + }, // in order to support our internal use of lightstep in staging, meta, public // and avoid resetting LIGHTSTEP_API_KEY when switching environments // allow the user to specify where to look for the key @@ -64,16 +70,20 @@ func Provider() *schema.Provider { func configureProvider(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { var diags diag.Diagnostics - envVar := d.Get("api_key_env_var").(string) - - apiKey, ok := os.LookupEnv(envVar) - if !ok { - diags = append(diags, diag.Diagnostic{ - Severity: diag.Error, - Summary: "No api key found", - Detail: fmt.Sprintf("'api_key_env_var' is set to %v - but no api key found.", envVar), - }) - return apiKey, diags + var apiKey string + apiKey = d.Get("api_key").(string) + if len(apiKey) == 0 { + envVar := d.Get("api_key_env_var").(string) + apiKeyEnv, ok := os.LookupEnv(envVar) + if !ok { + diags = append(diags, diag.Diagnostic{ + Severity: diag.Error, + Summary: "No api key found", + Detail: fmt.Sprintf("'api_key_env_var' is set to %v - but no api key found.", envVar), + }) + return apiKey, diags + } + apiKey = apiKeyEnv } client := client.NewClientWithUserAgent( diff --git a/lightstep/resource_metric_condition.go b/lightstep/resource_metric_condition.go index d6d85bd0..a6706485 100644 --- a/lightstep/resource_metric_condition.go +++ b/lightstep/resource_metric_condition.go @@ -3,11 +3,12 @@ package lightstep import ( "context" "fmt" - "github.com/hashicorp/go-cty/cty" "net/http" "strconv" "strings" + "github.com/hashicorp/go-cty/cty" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -132,9 +133,8 @@ func getAlertingRuleSchema() map[string]*schema.Schema { func getSpansQuerySchema() *schema.Schema { sma := schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Deprecated: "Spans charts are not supported by the Lightstep API.", + Type: schema.TypeList, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "query": {