-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
9af32b3
commit 23ca819
Showing
7 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
website/docs/d/monitoring_cluster_istio_service.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
website/docs/d/monitoring_mesh_istio_service.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters