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

Add new resource, google_logging_metric #1531

Closed

Conversation

JoeStanton
Copy link

@JoeStanton JoeStanton commented Mar 15, 2019

Opening this as a draft PR, though I hope it won't kick off the build robot. I wanted to validate my approach early, and will finish over the next couple of days.

Usage as follows

resource "google_logging_metric" "api_latency" {
  name        = "api-latency"
  filter      = "resource.type=\"k8s_container\" resource.labels.cluster_name=\"cluster\" resource.labels.namespace_name=\"default\" resource.labels.container_name=\"api\" jsonPayload.type=\"request\""
  description = "API latency"

  metric_descriptor = {
    metric_kind = "DELTA"
    value_type  = "DISTRIBUTION"

    labels = [
      {
        key         = "path"
        description = "The request path"
        value_type  = "STRING"
      },
    ]
  }

  value_extractor = "EXTRACT(jsonPayload.event.responseTimeMs)"

  label_extractors = {
    path = "EXTRACT(jsonPayload.event.url)"
  }

  bucket_options = {
    exponential_buckets = {
      num_finite_buckets = 64
      growth_factor      = 2
      scale              = 0.01
    }
  }
}

[all]

[terraform]

Logs-based metrics support

[terraform-beta]

[ansible]

[inspec]

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review. They will authorize it to run through our CI pipeline, which will generate downstream PRs.

Thanks for your contribution! A human will be with you soon.

@JoeStanton
Copy link
Author

Just signed the CLA.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@chrisst chrisst self-assigned this Mar 26, 2019
Copy link
Contributor

@chrisst chrisst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeStanton Thanks for contributing! I'm not sure where you are on this PR so I haven't done a full review yet. If you are ready please move this out of draft status and I'll look at it in more depth.

Just FYI, at a quick glance this PR will need more test coverage before we're able to merge it in. The example you added will generate 1 small test, but with a more complicated object like this I'd like to see a few more that cover more of the fields. Additionally since this is an updatable resource one of the tests should also cover updating the resource. Tests at this point are still hand written and added in the third_party/terraform directory.

Logs-based metric can also be used to extract values from logs and create a a distribution of the values. The distribution records the statistics of the extracted values along with an optional histogram of the values as specified by the bucket options.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
"Official Documentation": "https://cloud.google.com/logging/docs/reference/v2/rest/v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link 404's. We usually point this link to the overview for the product, such as https://cloud.google.com/logging/docs/apis

@chrisst
Copy link
Contributor

chrisst commented Apr 2, 2019

@JoeStanton
Copy link
Author

JoeStanton commented Apr 2, 2019

Hi @chrisst thanks for getting back to me. We are using this code to provision and update custom metrics in the project I'm working on (success!), but I've been super busy so have not been able to tidy this up yet so it's ready for merge. Definitely needs more test coverage.

Could you point me in the right direction for the following:

  • How can I specify that order doesn't matter, for key-value labels? Otherwise we sometimes end up with a diff after the changes have been applied. I've been looking for an example but none seem to apply.

  • Would you recommend mirroring exactly the GCP API behind this? For example, the UI for custom metrics shows label extractors as a sub-field of the label itself, whereas the API specifies labelExtractor as a completely separate top-level field. Just curious if there is a rule-of-thumb here.

  • Is the naming of this resource okay? Not sure if logging sits under the StackDriver brand, or is being moved out into GCP proper.

I think in the next week or two I should be able to finish this up. Beyond tests, do I need to consider all of the Ansible/Inspec use-cases to make this mergeable?

@chrisst
Copy link
Contributor

chrisst commented Apr 2, 2019

To ignore ordering you can look at using a Terraform TypeSet https://www.terraform.io/docs/extend/schemas/schema-types.html#typeset which in MagicModules is created with is_set: true. I did a quick check and it doesn't look like we have any examples of KeyValue sets so this may be uncharted territory. If you find it doesn't generate the right code I'll be happy to help out.

Our general rule of thumb is to mirror the api as closely as possible. The API is committed to not making breaking changes whereas the UI doesn't have that guarantee.

As for Ansible, we often add new resources here just for a single provider (Terraform) and will exclude the others. If there is sufficient demand for the other tools then we work with somebody who has more experience with those tools to help add that support. Just by adding this it gets us way closer to getting Ansible support so it's still a big step in the right direction.

@chrisst
Copy link
Contributor

chrisst commented Apr 2, 2019

I double checked on the ordering, and MM will turn the KeyValue object into a TypeMap in Terraform which is already ordering agnostic. So you actually should be fine with what you have already. No need to use is_set

@bukzor
Copy link

bukzor commented Apr 7, 2019

What's next?

@chrisst
Copy link
Contributor

chrisst commented Apr 21, 2019

@JoeStanton it looks like there is a lot of excitement for this to land so we'd love to get this in soon. If you have time this week to finish the PR please let us know, otherwise we might build off of what you have started so that we can get this out. Thanks!

@tysen tysen self-assigned this Apr 25, 2019
@tysen
Copy link

tysen commented May 3, 2019

#1702

@tysen tysen closed this May 3, 2019
@JoeStanton JoeStanton deleted the logging-custom-metric branch July 17, 2019 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants