Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Inspec project_metric #332

Merged
merged 1 commit into from
Jan 22, 2020
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
1 change: 0 additions & 1 deletion docs/resources/google_cloud_scheduler_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe google_cloud_scheduler_job(project: 'chef-gcp-inspec', region: us-centr
its('description') { should cmp 'A description' }
its('schedule') { should cmp '*/8 * * * *' }
its('time_zone') { should cmp 'America/New_York' }
its('attempt_deadline') { should cmp '' }
its('http_target.http_method') { should cmp 'POST' }
its('http_target.uri') { should cmp 'https://example.com/ping' }
end
Expand Down
1 change: 0 additions & 1 deletion docs/resources/google_cloud_scheduler_jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ google_cloud_scheduler_jobs(project: 'chef-gcp-inspec', region: ).names.each do
its('description') { should cmp 'A description' }
its('schedule') { should cmp '*/8 * * * *' }
its('time_zone') { should cmp 'America/New_York' }
its('attempt_deadline') { should cmp '' }
its('http_target.http_method') { should cmp 'POST' }
its('http_target.uri') { should cmp 'https://example.com/ping' }
end
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/google_compute_zone.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This resource has beta fields available. To retrieve these fields, include `beta

## Examples
```
describe google_compute_zone(project: 'chef-gcp-inspec', "us-central1-a") do
describe google_compute_zone(project: 'chef-gcp-inspec', name: "us-central1-a") do
it { should exist }
it { should be_up }
end
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/google_compute_zones.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This resource has beta fields available. To retrieve these fields, include `beta
## Examples
```
google_compute_zones(project: 'chef-gcp-inspec').zone_names.each do |zone_name|
describe google_compute_zones(project: 'chef-gcp-inspec', name: zone_name) do
describe google_compute_zone(project: 'chef-gcp-inspec', name: zone_name) do
it { should exist }
it { should be_up }
end
Expand Down
83 changes: 58 additions & 25 deletions docs/resources/google_project_metric.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,82 @@
---
title: About the google_project_metric Resource
title: About the google_project_metric resource
platform: gcp
---

# google\_project\_metric
## Syntax
A `google_project_metric` is used to test a Google Metric resource

Use the `google_project_metric` InSpec audit resource to test properties of a single GCP project metric.
## Examples
```
describe google_project_metric(project: 'chef-gcp-inspec', name: 'some/metric') do
it { should exist }
its('filter') { should cmp 'resource.type=gae_app AND severity>=ERROR' }
its('metric_descriptor.metric_kind') { should cmp 'DELTA' }
its('metric_descriptor.value_type') { should cmp 'INT64' }
end

describe google_project_metric(project: 'chef-gcp-inspec', name: 'nonexistent') do
it { should_not exist }
end
```

<br>
## Properties
Properties that can be accessed from the `google_project_metric` resource:

## Syntax

A `google_project_metric` resource block declares the tests for a single GCP zone by project and name.
* `name`: The client-assigned metric identifier. Examples - "error_count", "nginx/requests". Metric identifiers are limited to 100 characters and can include only the following characters A-Z, a-z, 0-9, and the special characters _-.,+!*',()%/. The forward-slash character (/) denotes a hierarchy of name pieces, and it cannot be the first character of the name.

describe google_project_metric(project: 'chef-inspec-gcp', metric: 'metric_name') do
it { should exist }
end
* `description`: A description of this metric, which is used in documentation. The maximum length of the description is 8000 characters.

<br>
* `filter`: An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which is used to match log entries.

## Examples
* `metric_descriptor`: The metric descriptor associated with the logs-based metric.

The following examples show how to use this InSpec audit resource.
* `unit`: The unit in which the metric value is reported. It is only applicable if the valueType is `INT64`, `DOUBLE`, or `DISTRIBUTION`. The supported units are a subset of [The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard

### Test that a GCP project metric exists
* `value_type`: Whether the measurement is an integer, a floating-point number, etc. Some combinations of metricKind and valueType might not be supported. For counter metrics, set this to INT64.

describe google_project_metric(project: 'chef-inspec-gcp', metric: 'metric_name') do
it { should exist }
end
* `metric_kind`: Whether the metric records instantaneous values, changes to a value, etc. Some combinations of metricKind and valueType might not be supported. For counter metrics, set this to DELTA.

### Test that a GCP compute zone has an expected CPU platform
* `labels`: The set of labels that can be used to describe a specific instance of this metric type. For example, the appengine.googleapis.com/http/server/response_latencies metric type has a label for the HTTP response code, response_code, so you can look at latencies for successful responses or just for responses that failed.

describe google_project_metric(project: 'chef-inspec-gcp', metric: 'metric_name') do
its('filter') { should eq "(protoPayload.serviceName=\"cloudresourcemanager.googleapis.com\")" }
end
* `key`: The label key.

<br>
* `description`: A human-readable description for the label.

## Properties
* `value_type`: The type of data that can be assigned to the label.

* `display_name`: A concise name for the metric, which can be displayed in user interfaces. Use sentence case without an ending period, for example "Request count". This field is optional but it is recommended to be set for any metrics associated with user-visible concepts, such as Quota.

* `type`: The metric type, including its DNS name prefix. The type is not URL-encoded. All user-defined metric types have the DNS name `custom.googleapis.com` or `external.googleapis.com`.

* `label_extractors`: A map from a label key string to an extractor expression which is used to extract data from a log entry field and assign as the label value. Each label key specified in the LabelDescriptor must have an associated extractor expression in this map. The syntax of the extractor expression is the same as for the valueExtractor field.

* `value_extractor`: A valueExtractor is required when using a distribution logs-based metric to extract the values to record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax (https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified log entry field. The value of the field is converted to a string before applying the regex. It is an error to specify a regex that does not include exactly one capture group.

* `bucket_options`: The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it describes the bucket boundaries used to create a histogram of the extracted values.

* `linear_buckets`: Specifies a linear sequence of buckets that all have the same width (except overflow and underflow). Each bucket represents a constant absolute uncertainty on the specific value in the bucket.

* `num_finite_buckets`: Must be greater than 0.

* `width`: Must be greater than 0.

* `offset`: Lower bound of the first bucket.

* `exponential_buckets`: Specifies an exponential sequence of buckets that have a width that is proportional to the value of the lower bound. Each bucket represents a constant relative uncertainty on a specific value in the bucket.

* `num_finite_buckets`: Must be greater than 0.

* `growth_factor`: Must be greater than 1.

* `scale`: Must be greater than 0.

* `filter`, `name`, `metric_descriptor`
* `explicit_buckets`: Specifies a set of buckets with arbitrary widths.

<br>
* `bounds`: The values must be monotonically increasing.


## GCP Permissions

Ensure the [Stackdriver Logging API](https://console.cloud.google.com/apis/api/logging.googleapis.com/) is enabled for the project.
Ensure the [Stackdriver Logging API](https://console.cloud.google.com/apis/library/logging.googleapis.com/) is enabled for the current project.
85 changes: 29 additions & 56 deletions docs/resources/google_project_metrics.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,44 @@
---
title: About the google_project_metrics Resource
title: About the google_project_metrics resource
platform: gcp
---

# google\_project\_metrics

Use the `google_project_metrics` InSpec audit resource to test properties of all, or a filtered group of, GCP project metrics.

<br>

## Syntax

A `google_project_metrics` resource block collects GCP project logging sinks by project then tests that group.

describe google_project_metrics(project: 'chef-inspec-gcp') do
it { should exist }
end

Use this InSpec resource to enumerate IDs then test in-depth using `google_project_metric`.

google_project_metrics(project: 'chef-inspec-gcp').sink_names.each do |metric_name|
describe google_project_metric(project: 'chef-inspec-gcp', metric: metric_name) do
it { should exist }
end
end

<br>
A `google_project_metrics` is used to test a Google Metric resource

## Examples

The following examples show how to use this InSpec audit resource.

### Test that there are no more than a specified number of metrics available for the project

describe google_project_metrics(project: 'chef-inspec-gcp') do
its('count') { should be <= 100}
```
describe google_project_metrics(project: 'chef-gcp-inspec') do
it { should exist }
its('metric_filters') { should include 'resource.type=gae_app AND severity>=ERROR' }
its('metric_names') { should include 'some/metric' }
end

describe.one do
google_project_metrics(project: 'chef-gcp-inspec').metric_types.each do |metric_type|
describe metric_type do
it { should match 'some/metric' }
end

### Test that an expected metric name is available for the project

describe google_project_metrics(project: 'chef-inspec-gcp') do
its('metric_names') { should include "metric-name" }
end

### Test that a subset of all metrics with name matching "*project*" have a particular writer identity

google_project_metrics(project: 'chef-inspec-gcp').where(metric_name: /project/).metric_names.each do |metric_name|
describe google_project_metric(project: 'chef-inspec-gcp', metric: metric_name) do
its('filter') { should eq "(protoPayload.serviceName=\"cloudresourcemanager.googleapis.com\")" }
end
end

<br>

## Filter Criteria

This resource supports the following filter criteria: `metric_name`; `metric_type` and `metric_filter`. Either of these may be used with `where`, as a block or as a method.
end
end
```

## Properties
Properties that can be accessed from the `google_project_metrics` resource:

* `metric_names` - an array of google_project_metric name strings
* `metric_filters`- an array of google_project_metric filter strings
* `metric_types` - an array of google_project_metric type strings

<br>
See [google_project_metric.md](google_project_metric.md) for more detailed information
* `metric_names`: an array of `google_project_metric` name
* `descriptions`: an array of `google_project_metric` description
* `metric_filters`: an array of `google_project_metric` filter
* `metric_descriptors`: an array of `google_project_metric` metric_descriptor
* `label_extractors`: an array of `google_project_metric` label_extractors
* `value_extractors`: an array of `google_project_metric` value_extractor
* `bucket_options`: an array of `google_project_metric` bucket_options

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.

## GCP Permissions

Ensure the [Stackdriver Logging API](https://console.cloud.google.com/apis/api/logging.googleapis.com/) is enabled for the project.
Ensure the [Stackdriver Logging API](https://console.cloud.google.com/apis/library/logging.googleapis.com/) is enabled for the current project.
2 changes: 1 addition & 1 deletion docs/resources/google_projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
Properties that can be accessed from the `google_projects` resource:

See [google_project.md](google_project.md) for more detailed information
* `numbers`: an array of `google_project` number
* `project_numbers`: an array of `google_project` number
* `lifecycle_states`: an array of `google_project` lifecycle_state
* `project_names`: an array of `google_project` name
* `create_times`: an array of `google_project` create_time
Expand Down
43 changes: 43 additions & 0 deletions libraries/google/logging/property/metric_bucket_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
require 'google/logging/property/metric_bucket_options_explicit_buckets'
require 'google/logging/property/metric_bucket_options_exponential_buckets'
require 'google/logging/property/metric_bucket_options_linear_buckets'
module GoogleInSpec
module Logging
module Property
class MetricBucketOptions
attr_reader :linear_buckets

attr_reader :exponential_buckets

attr_reader :explicit_buckets

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@linear_buckets = GoogleInSpec::Logging::Property::MetricBucketOptionsLinearBuckets.new(args['linearBuckets'], to_s)
@exponential_buckets = GoogleInSpec::Logging::Property::MetricBucketOptionsExponentialBuckets.new(args['exponentialBuckets'], to_s)
@explicit_buckets = GoogleInSpec::Logging::Property::MetricBucketOptionsExplicitBuckets.new(args['explicitBuckets'], to_s)
end

def to_s
"#{@parent_identifier} MetricBucketOptions"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Logging
module Property
class MetricBucketOptionsExplicitBuckets
attr_reader :bounds

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@bounds = args['bounds']
end

def to_s
"#{@parent_identifier} MetricBucketOptionsExplicitBuckets"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Logging
module Property
class MetricBucketOptionsExponentialBuckets
attr_reader :num_finite_buckets

attr_reader :growth_factor

attr_reader :scale

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@num_finite_buckets = args['numFiniteBuckets']
@growth_factor = args['growthFactor']
@scale = args['scale']
end

def to_s
"#{@parent_identifier} MetricBucketOptionsExponentialBuckets"
end
end
end
end
end
Loading