84
84
"cluster_config.0.software_config.0.optional_components" ,
85
85
}
86
86
87
+ dataprocMetricConfigKeys = []string {
88
+ "cluster_config.0.dataproc_metric_config.0.metrics" ,
89
+ }
90
+
91
+ metricKeys = []string {
92
+ "cluster_config.0.dataproc_metric_config.0.metrics.0.metric_source" ,
93
+ "cluster_config.0.dataproc_metric_config.0.metrics.0.metric_overrides" ,
94
+ }
95
+
87
96
clusterConfigKeys = []string {
88
97
"cluster_config.0.staging_bucket" ,
89
98
"cluster_config.0.temp_bucket" ,
99
108
"cluster_config.0.metastore_config" ,
100
109
"cluster_config.0.lifecycle_config" ,
101
110
"cluster_config.0.endpoint_config" ,
111
+ "cluster_config.0.dataproc_metric_config" ,
102
112
}
103
113
)
104
114
@@ -1086,6 +1096,24 @@ by Dataproc`,
1086
1096
},
1087
1097
},
1088
1098
},
1099
+
1100
+ "dataproc_metric_config" : {
1101
+ Type : schema .TypeList ,
1102
+ Optional : true ,
1103
+ MaxItems : 1 ,
1104
+ Description : `The config for Dataproc metrics.` ,
1105
+ AtLeastOneOf : clusterConfigKeys ,
1106
+ Elem : & schema.Resource {
1107
+ Schema : map [string ]* schema.Schema {
1108
+ "metrics" : {
1109
+ Type : schema .TypeList ,
1110
+ Required : true ,
1111
+ Description : `Metrics sources to enable.` ,
1112
+ Elem : metricsSchema (),
1113
+ },
1114
+ },
1115
+ },
1116
+ },
1089
1117
},
1090
1118
},
1091
1119
},
@@ -1094,6 +1122,28 @@ by Dataproc`,
1094
1122
}
1095
1123
}
1096
1124
1125
+ // We need to pull metrics' schema out so we can use it to make a set hash func
1126
+ func metricsSchema () * schema.Resource {
1127
+ return & schema.Resource {
1128
+ Schema : map [string ]* schema.Schema {
1129
+ "metric_source" : {
1130
+ Type : schema .TypeString ,
1131
+ ForceNew : true ,
1132
+ Required : true ,
1133
+ ValidateFunc : validation .StringInSlice ([]string {"MONITORING_AGENT_DEFAULTS" , "HDFS" , "SPARK" , "YARN" , "SPARK_HISTORY_SERVER" , "HIVESERVER2" }, false ),
1134
+ Description : `A source for the collection of Dataproc OSS metrics (see [available OSS metrics] (https://cloud.google.com//dataproc/docs/guides/monitoring#available_oss_metrics)).` ,
1135
+ },
1136
+ "metric_overrides" : {
1137
+ Type : schema .TypeSet ,
1138
+ Elem : & schema.Schema {Type : schema .TypeString },
1139
+ Optional : true ,
1140
+ ForceNew : true ,
1141
+ Description : `Specify one or more [available OSS metrics] (https://cloud.google.com/dataproc/docs/guides/monitoring#available_oss_metrics) to collect.` ,
1142
+ },
1143
+ },
1144
+ }
1145
+ }
1146
+
1097
1147
func instanceConfigSchema (parent string ) * schema.Schema {
1098
1148
var instanceConfigKeys = []string {
1099
1149
"cluster_config.0." + parent + ".0.num_instances" ,
@@ -1544,6 +1594,10 @@ func expandClusterConfig(d *schema.ResourceData, config *Config) (*dataproc.Clus
1544
1594
conf .EndpointConfig = expandEndpointConfig (cfg )
1545
1595
}
1546
1596
1597
+ if cfg , ok := configOptions (d , "cluster_config.0.dataproc_metric_config" ); ok {
1598
+ conf .DataprocMetricConfig = expandDataprocMetricConfig (cfg )
1599
+ }
1600
+
1547
1601
if cfg , ok := configOptions (d , "cluster_config.0.master_config" ); ok {
1548
1602
log .Println ("[INFO] got master_config" )
1549
1603
conf .MasterConfig = expandInstanceGroupConfig (cfg )
@@ -1762,6 +1816,23 @@ func expandEndpointConfig(cfg map[string]interface{}) *dataproc.EndpointConfig {
1762
1816
return conf
1763
1817
}
1764
1818
1819
+ func expandDataprocMetricConfig (cfg map [string ]interface {}) * dataproc.DataprocMetricConfig {
1820
+ conf := & dataproc.DataprocMetricConfig {}
1821
+ metricsConfigs := cfg ["metrics" ].([]interface {})
1822
+ metricsSet := make ([]* dataproc.Metric , 0 , len (metricsConfigs ))
1823
+
1824
+ for _ , raw := range metricsConfigs {
1825
+ data := raw .(map [string ]interface {})
1826
+ metric := dataproc.Metric {
1827
+ MetricSource : data ["metric_source" ].(string ),
1828
+ MetricOverrides : convertStringSet (data ["metric_overrides" ].(* schema.Set )),
1829
+ }
1830
+ metricsSet = append (metricsSet , & metric )
1831
+ }
1832
+ conf .Metrics = metricsSet
1833
+ return conf
1834
+ }
1835
+
1765
1836
func expandMetastoreConfig (cfg map [string ]interface {}) * dataproc.MetastoreConfig {
1766
1837
conf := & dataproc.MetastoreConfig {}
1767
1838
if v , ok := cfg ["dataproc_metastore_service" ]; ok {
@@ -2171,6 +2242,7 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) (
2171
2242
"metastore_config" : flattenMetastoreConfig (d , cfg .MetastoreConfig ),
2172
2243
"lifecycle_config" : flattenLifecycleConfig (d , cfg .LifecycleConfig ),
2173
2244
"endpoint_config" : flattenEndpointConfig (d , cfg .EndpointConfig ),
2245
+ "dataproc_metric_config" : flattenDataprocMetricConfig (d , cfg .DataprocMetricConfig ),
2174
2246
}
2175
2247
2176
2248
if len (cfg .InitializationActions ) > 0 {
@@ -2277,6 +2349,26 @@ func flattenEndpointConfig(d *schema.ResourceData, ec *dataproc.EndpointConfig)
2277
2349
return []map [string ]interface {}{data }
2278
2350
}
2279
2351
2352
+ func flattenDataprocMetricConfig (d * schema.ResourceData , dmc * dataproc.DataprocMetricConfig ) []map [string ]interface {} {
2353
+ if dmc == nil {
2354
+ return nil
2355
+ }
2356
+
2357
+ metrics := map [string ]interface {}{}
2358
+ metricsTypeList := schema .NewSet (schema .HashResource (metricsSchema ()), []interface {}{}).List ()
2359
+ for _ , metric := range dmc .Metrics {
2360
+ data := map [string ]interface {}{
2361
+ "metric_source" : metric .MetricSource ,
2362
+ "metric_overrides" : metric .MetricOverrides ,
2363
+ }
2364
+
2365
+ metricsTypeList = append (metricsTypeList , & data )
2366
+ }
2367
+ metrics ["metrics" ] = metricsTypeList
2368
+
2369
+ return []map [string ]interface {}{metrics }
2370
+ }
2371
+
2280
2372
func flattenMetastoreConfig (d * schema.ResourceData , ec * dataproc.MetastoreConfig ) []map [string ]interface {} {
2281
2373
if ec == nil {
2282
2374
return nil
0 commit comments