Skip to content

Commit

Permalink
Added services monitoring data sources (#4222) (#7847)
Browse files Browse the repository at this point in the history
* add service monitor data sources

* Update provider.go.erb

formatting

* Update data_source_monitoring_service_cluster_istio.go

Added comments explaining why no tests were included

* Update data_source_monitoring_service_mesh_istio.go

Added comment explaining why no testes were included

* run gofmt for two go files

Co-authored-by: Edward Sun <sunedward@google.com>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Edward Sun <sunedward@google.com>
  • Loading branch information
modular-magician and Edward Sun authored Nov 18, 2020
1 parent 9af32b3 commit 23ca819
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/4222.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:new-datasource
`google_monitoring_cluster_istio_service`
`google_monitoring_mesh_istio_service`
```
65 changes: 65 additions & 0 deletions google/data_source_monitoring_service_cluster_istio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package google

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// No tests are added in this PR as currently there is no TF-supported method that can be used to
// enable both services (Cluster Istio and Mesh Istio) in GKE
func dataSourceMonitoringServiceClusterIstio() *schema.Resource {
ciSchema := map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Required: true,
Description: `The location of the Kubernetes cluster in which this Istio service is defined.
Corresponds to the location resource label in k8s_cluster resources.`,
},
"cluster_name": {
Type: schema.TypeString,
Required: true,
Description: `The name of the Kubernetes cluster in which this Istio service is defined.
Corresponds to the clusterName resource label in k8s_cluster resources.`,
},
"service_namespace": {
Type: schema.TypeString,
Required: true,
Description: `The namespace of the Istio service underlying this service.
Corresponds to the destination_service_namespace metric label in Istio metrics.`,
},
"service_name": {
Type: schema.TypeString,
Required: true,
Description: `The name of the Istio service underlying this service.
Corresponds to the destination_service_name metric label in Istio metrics.`,
},
}
filter := `cluster_istio.cluster_name="{{cluster_name}}" AND
cluster_istio.service_namespace="{{service_namespace}}" AND
cluster_istio.service_name="{{service_name}}" AND
cluster_istio.location="{{location}}"`
return dataSourceMonitoringServiceType(ciSchema, filter, dataSourceMonitoringServiceClusterIstioRead)
}

func dataSourceMonitoringServiceClusterIstioRead(res map[string]interface{}, d *schema.ResourceData, meta interface{}) error {
var clusterIstio map[string]interface{}
if v, ok := res["cluster_istio"]; ok {
clusterIstio = v.(map[string]interface{})
}
if len(clusterIstio) == 0 {
return nil
}

if err := d.Set("location", clusterIstio["location"]); err != nil {
return err
}
if err := d.Set("service_name", clusterIstio["service_name"]); err != nil {
return err
}
if err := d.Set("service_namespace", clusterIstio["service_namespace"]); err != nil {
return err
}
if err := d.Set("cluster_name", clusterIstio["cluster_name"]); err != nil {
return err
}
return nil
}
54 changes: 54 additions & 0 deletions google/data_source_monitoring_service_mesh_istio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package google

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// No tests are added in this PR as currently there is no TF-supported method that can be used to
// enable both services (Cluster Istio and Mesh Istio) in GKE
func dataSourceMonitoringServiceMeshIstio() *schema.Resource {
miSchema := map[string]*schema.Schema{
"mesh_uid": {
Type: schema.TypeString,
Required: true,
Description: `Identifier for the mesh in which this Istio service is defined.
Corresponds to the meshUid metric label in Istio metrics.`,
},
"service_namespace": {
Type: schema.TypeString,
Required: true,
Description: `The namespace of the Istio service underlying this service.
Corresponds to the destination_service_namespace metric label in Istio metrics.`,
},
"service_name": {
Type: schema.TypeString,
Required: true,
Description: `The name of the Istio service underlying this service.
Corresponds to the destination_service_name metric label in Istio metrics.`,
},
}
t := `mesh_istio.mesh_uid="{{mesh_uid}}" AND
mesh_istio.service_name="{{service_name}}" AND
mesh_istio.service_namespace="{{service_namespace}}"`
return dataSourceMonitoringServiceType(miSchema, t, dataSourceMonitoringServiceMeshIstioRead)
}

func dataSourceMonitoringServiceMeshIstioRead(res map[string]interface{}, d *schema.ResourceData, meta interface{}) error {
var meshIstio map[string]interface{}
if v, ok := res["mesh_istio"]; ok {
meshIstio = v.(map[string]interface{})
}
if len(meshIstio) == 0 {
return nil
}
if err := d.Set("service_name", meshIstio["service_name"]); err != nil {
return err
}
if err := d.Set("service_namespace", meshIstio["service_namespace"]); err != nil {
return err
}
if err := d.Set("mesh_name", meshIstio["mesh_name"]); err != nil {
return err
}
return nil
}
2 changes: 2 additions & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ func Provider() *schema.Provider {
"google_folder": dataSourceGoogleFolder(),
"google_folder_organization_policy": dataSourceGoogleFolderOrganizationPolicy(),
"google_monitoring_notification_channel": dataSourceMonitoringNotificationChannel(),
"google_monitoring_cluster_istio_service": dataSourceMonitoringServiceClusterIstio(),
"google_monitoring_mesh_istio_service": dataSourceMonitoringServiceMeshIstio(),
"google_monitoring_app_engine_service": dataSourceMonitoringServiceAppEngine(),
"google_monitoring_uptime_check_ips": dataSourceGoogleMonitoringUptimeCheckIps(),
"google_netblock_ip_ranges": dataSourceGoogleNetblockIpRanges(),
Expand Down
88 changes: 88 additions & 0 deletions website/docs/d/monitoring_cluster_istio_service.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
subcategory: "Cloud (Stackdriver) Monitoring"
layout: "google"
page_title: "Google: google_monitoring_cluster_istio_service"
sidebar_current: "docs-google-datasource-monitoring-cluster-istio-service"
description: |-
An Monitoring Service resource created automatically by GCP to monitor an
Cluster Istio service.
---

# google\_monitoring\_cluster\_istio\_service

A Monitoring Service is the root resource under which operational aspects of a
generic service are accessible. A service is some discrete, autonomous, and
network-accessible unit, designed to solve an individual concern

An Cluster Istio monitoring service is automatically created by GCP to monitor
Cluster Istio services.


To get more information about Service, see:

* [API documentation](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/services)
* How-to Guides
* [Service Monitoring](https://cloud.google.com/monitoring/service-monitoring)
* [Monitoring API Documentation](https://cloud.google.com/monitoring/api/v3/)

## Example Usage - Monitoring Cluster Istio Service


```hcl
# Monitors the default ClusterIstio service
data "google_monitoring_cluster_istio_service" "default" {
location = "us-west2-a"
cluster_name = "west"
service_namespace = "istio-system"
service_name = "istio-policy"
}
```

## Argument Reference

The arguments of this data source act as filters for identifying a given -created service.

The given filters must match exactly one service whose data will be exported as attributes. The following arguments are supported:

The following fields must be specified:

* `location` - (Required) The location of the Kubernetes cluster in which this Istio service
is defined. Corresponds to the location resource label in k8s_cluster resources.

* `cluster_name` - (Required) The name of the Kubernetes cluster in which this Istio service
is defined. Corresponds to the clusterName resource label in k8s_cluster resources.

* `service_namespace` - (Required) The namespace of the Istio service underlying this service.
Corresponds to the destination_service_namespace metric label in Istio metrics.

* `service_name` - (Required) The name of the Istio service underlying this service.
Corresponds to the destination_service_name metric label in Istio metrics.

- - -

Other optional fields include:

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `name` -
The full REST resource name for this channel. The syntax is:
`projects/[PROJECT_ID]/services/[SERVICE_ID]`.

* `display_name` -
Name used for UI elements listing this (Monitoring) Service.

* `telemetry` -
Configuration for how to query telemetry on the Service. Structure is documented below.

The `telemetry` block includes:

* `resource_name` -
(Optional)
The full name of the resource that defines this service.
Formatted as described in
https://cloud.google.com/apis/design/resource_names.
84 changes: 84 additions & 0 deletions website/docs/d/monitoring_mesh_istio_service.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
subcategory: "Cloud (Stackdriver) Monitoring"
layout: "google"
page_title: "Google: google_monitoring_mesh_istio_service"
sidebar_current: "docs-google-datasource-monitoring-mesh-istio-service"
description: |-
An Monitoring Service resource created automatically by GCP to monitor an
Mesh Istio service.
---

# google\_monitoring\_mesh\_istio\_service

A Monitoring Service is the root resource under which operational aspects of a
generic service are accessible. A service is some discrete, autonomous, and
network-accessible unit, designed to solve an individual concern

An Mesh Istio monitoring service is automatically created by GCP to monitor
Mesh Istio services.


To get more information about Service, see:

* [API documentation](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/services)
* How-to Guides
* [Service Monitoring](https://cloud.google.com/monitoring/service-monitoring)
* [Monitoring API Documentation](https://cloud.google.com/monitoring/api/v3/)

## Example Usage - Monitoring Mesh Istio Service


```hcl
# Monitors the default MeshIstio service
data "google_monitoring_mesh_istio_service" "default" {
mesh_uid = "proj-573164786102"
service_namespace = "istio-system"
service_name = "prometheus"
}
```

## Argument Reference

The arguments of this data source act as filters for identifying a given -created service.

The given filters must match exactly one service whose data will be exported as attributes. The following arguments are supported:

The following fields must be specified:

* `mesh_uid` - (Required) Identifier for the mesh in which this Istio service is defined.
Corresponds to the meshUid metric label in Istio metrics.

* `service_namespace` - (Required) The namespace of the Istio service underlying this service.
Corresponds to the destination_service_namespace metric label in Istio metrics.

* `service_name` - (Required) The name of the Istio service underlying this service.
Corresponds to the destination_service_name metric label in Istio metrics.

- - -

Other optional fields include:

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `name` -
The full REST resource name for this channel. The syntax is:
`projects/[PROJECT_ID]/services/[SERVICE_ID]`.

* `display_name` -
Name used for UI elements listing this (Monitoring) Service.

* `telemetry` -
Configuration for how to query telemetry on the Service. Structure is documented below.

The `telemetry` block includes:

* `resource_name` -
(Optional)
The full name of the resource that defines this service.
Formatted as described in
https://cloud.google.com/apis/design/resource_names.
8 changes: 8 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@
<a href="/docs/providers/google/d/monitoring_app_engine_service.html">google_monitoring_app_engine_service</a>
</li>

<li>
<a href="/docs/providers/google/d/monitoring_cluster_istio_service.html">google_monitoring_cluster_istio_service</a>
</li>

<li>
<a href="/docs/providers/google/d/monitoring_mesh_istio_service.html">google_monitoring_mesh_istio_service</a>
</li>

<li>
<a href="/docs/providers/google/d/monitoring_notification_channel.html">google_monitoring_notification_channel</a>
</li>
Expand Down

0 comments on commit 23ca819

Please sign in to comment.