dikhan / terraform-provider-openapi

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Apache License 2.0
275 stars 48 forks source link

Plugin submits resource information and operation performed as part of telemetry metrics #221

Closed dikhan closed 4 years ago

dikhan commented 4 years ago

Is your feature request related to a problem?

Currently the plugin, if the service provider is configured with telemetry in the terraform-provider-openapi.yaml plugin config file, will submit total executions any time the plugin is invoked by Terraform. This is good, but additionally I would like more insight in terms of the plugin's usage.

As an OpenAPI Terraform provider
I want the plugin to submit metrics related to resource and operation execution usage 
So that I have more level of insight of resource adoption and usage which then helps me understand the impact each resource is having.

Describe the solution you'd like

I would like the telemetry handler to submit a metric any time a resource is being provisioned. The metric should include the following information:

Proposed metric name and tags below:

tags := []string{"provider_name:" + providerName, "resource_name:" + resourceName, fmt.Sprintf("terraform_operation:%s", tfOperation)} metricName := "terraform.provider"

This should be supported for both the Graphite and HttpEndpoint telemetry providers.

Acceptance criteria

What's required to consider this feature request complete?

HTTP endpoint example:

Scenario: Plugin submits resource information and operation performed as part of telemetry data to HTTP endpoint configured
Given a new version of the OpenAPI Terraform plugin and a terraform config file (see example below)
When the plugin is executed  to create, update, read, delete a resource (eg: terraform plan/apply/destroy/refresh)
Then the plugin should submit as part of the telemetry data the service provider name, the resource executed and the operation performed.
version: '1'
services:
  openapi:
    telemetry:
      http_endpoint:
        url: http://endpoint.com/v1/metrics
curl -X POST https://my-app.com/v1/metrics -d '{"metric_type": "IncCounter", "metric_name":"<prefix>.terraform.provider", "tags": ["provider_name:cdn", "resource_name":"cdn", "terraform_operation": "create"]}' -H "Content-Type: application/json" -H "User-Agent: OpenAPI Terraform Provider/v0.26.0-b8364420eb450a34ff02e4c7832ad52165cd05b4 (darwin/amd64)"

Graphite example:

Scenario: Plugin submits resource information and operation performed as part of telemetry data to Graphite endpoint configured
Given a new version of the OpenAPI Terraform plugin and a terraform config file (see example below)
When the plugin is executed  to create, update, read, delete a resource (eg: terraform plan/apply/destroy/refresh)
Then the plugin should submit as part of the telemetry data the service provider name, the resource executed and the operation performed.
version: '1'
services:
  openapi:
    telemetry:
      graphite:
        host: endpoint.com
        port: 1234
terraform.provider:1|c|#provider_name:openapi,resource_name:cdns_v1,terraform_operation:create

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

At the moment the plugin submits when the provider ConfigureFunc is assigned. This issue requires the telemetry handler to be configured in the resourceFactory so then the handler can be called inside each of the CRUD operations.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly: