Skip to content

Commit

Permalink
feat: ram_execution_status metric
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoReboul committed Jan 15, 2021
1 parent aae4e5b commit 705ccc2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 38 deletions.
54 changes: 27 additions & 27 deletions services/setlogmetrics/meth_instancedeployment_situate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@ package setlogmetrics

import (
"fmt"
"strings"

"google.golang.org/api/logging/v2"
)

// Situate complement settings taking in account the situation for service and instance settings
func (instanceDeployment *InstanceDeployment) Situate() (err error) {
metricName := fmt.Sprintf("projects/%s/metrics/%s",
instanceDeployment.Core.SolutionSettings.Hosting.ProjectID,
instanceDeployment.Settings.Instance.GLO.MetricID)

instanceDeployment.Artifacts.LogMetric.Name = metricName
instanceDeployment.Artifacts.LogMetric.Name = instanceDeployment.Settings.Instance.GLO.MetricID
instanceDeployment.Artifacts.LogMetric.Description = instanceDeployment.Settings.Instance.GLO.Description
instanceDeployment.Artifacts.LogMetric.Filter = instanceDeployment.Settings.Instance.GLO.Filter
instanceDeployment.Artifacts.LogMetric.ValueExtractor = instanceDeployment.Settings.Instance.GLO.ValueExtractor

var explicitBuckets logging.Explicit
var exponentialBuckets logging.Exponential
var linearBuckets logging.Linear
var bucketOptions logging.BucketOptions
instanceDeployment.Artifacts.LogMetric.BucketOptions = &bucketOptions
if len(instanceDeployment.Settings.Instance.GLO.BucketOptions.ExplicitBuckets.Bounds) > 0 {
bucketOptions.ExplicitBuckets = &explicitBuckets
explicitBuckets.Bounds = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExplicitBuckets.Bounds
} else {
if instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.NumFiniteBuckets != 0 {
bucketOptions.ExponentialBuckets = &exponentialBuckets
exponentialBuckets.GrowthFactor = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.GrowthFactor
exponentialBuckets.NumFiniteBuckets = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.NumFiniteBuckets
exponentialBuckets.Scale = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.Scale
if strings.ToLower(instanceDeployment.Settings.Instance.GLO.MetricDescriptor.ValueType) == "distribution" {
var explicitBuckets logging.Explicit
var exponentialBuckets logging.Exponential
var linearBuckets logging.Linear
var bucketOptions logging.BucketOptions
instanceDeployment.Artifacts.LogMetric.BucketOptions = &bucketOptions
if len(instanceDeployment.Settings.Instance.GLO.BucketOptions.ExplicitBuckets.Bounds) > 0 {
bucketOptions.ExplicitBuckets = &explicitBuckets
explicitBuckets.Bounds = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExplicitBuckets.Bounds
} else {
if instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.NumFiniteBuckets != 0 {
bucketOptions.LinearBuckets = &linearBuckets
linearBuckets.NumFiniteBuckets = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.NumFiniteBuckets
linearBuckets.Offset = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.Offset
linearBuckets.Width = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.Width
if instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.NumFiniteBuckets != 0 {
bucketOptions.ExponentialBuckets = &exponentialBuckets
exponentialBuckets.GrowthFactor = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.GrowthFactor
exponentialBuckets.NumFiniteBuckets = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.NumFiniteBuckets
exponentialBuckets.Scale = instanceDeployment.Settings.Instance.GLO.BucketOptions.ExponentialBuckets.Scale
} else {
if instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.NumFiniteBuckets != 0 {
bucketOptions.LinearBuckets = &linearBuckets
linearBuckets.NumFiniteBuckets = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.NumFiniteBuckets
linearBuckets.Offset = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.Offset
linearBuckets.Width = instanceDeployment.Settings.Instance.GLO.BucketOptions.LinearBuckets.Width
}
}
}
} else {
instanceDeployment.Artifacts.LogMetric.BucketOptions = nil
}

var metricDescriptor logging.MetricDescriptor
instanceDeployment.Artifacts.LogMetric.MetricDescriptor = &metricDescriptor
metricDescriptor.Type = fmt.Sprintf("logging.googleapis.com/user/%s", instanceDeployment.Settings.Instance.GLO.MetricID)
metricDescriptor.Name = fmt.Sprintf("projects/%s/metricDescriptors/logging.googleapis.com/user/%s",
instanceDeployment.Core.SolutionSettings.Hosting.ProjectID,
instanceDeployment.Settings.Instance.GLO.MetricID)
metricDescriptor.Name = instanceDeployment.Settings.Instance.GLO.MetricID
metricDescriptor.DisplayName = instanceDeployment.Settings.Instance.GLO.MetricID
metricDescriptor.Description = instanceDeployment.Settings.Instance.GLO.Description
metricDescriptor.LaunchStage = instanceDeployment.Settings.Instance.GLO.MetricDescriptor.LaunchStage
metricDescriptor.MetricKind = instanceDeployment.Settings.Instance.GLO.MetricDescriptor.MetricKind
Expand Down
31 changes: 31 additions & 0 deletions utilities/ffo/func_yamlmarshallprint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ffo

import (
"fmt"
"log"

"gopkg.in/yaml.v2"
)

// YAMLMarshalPrint marshal fmt print
func YAMLMarshalPrint(v interface{}) {
bytes, err := yaml.Marshal(v)
if err != nil {
log.Printf("YAMLMarshalPrint %v", err)
}
fmt.Println(string(bytes))
}
12 changes: 6 additions & 6 deletions utilities/glo/func_checklogmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func checkLogMetric(logMetric, retrievedLogMetric *logging.LogMetric) (err error
}
}
} else {
s = fmt.Sprintf("%snot found retrievedLogMetric.BucketOptions\n", s)
// s = fmt.Sprintf("%snot found retrievedLogMetric.BucketOptions\n", s)
}
}
if logMetric.MetricDescriptor != nil {
Expand All @@ -118,11 +118,11 @@ func checkLogMetric(logMetric, retrievedLogMetric *logging.LogMetric) (err error
logMetric.MetricDescriptor.Type,
retrievedLogMetric.MetricDescriptor.Type)
}
if logMetric.MetricDescriptor.Name != retrievedLogMetric.MetricDescriptor.Name {
s = fmt.Sprintf("%sMetricDescriptor.Name\nwant %s\nhave %s\n", s,
logMetric.MetricDescriptor.Name,
retrievedLogMetric.MetricDescriptor.Name)
}
// if logMetric.MetricDescriptor.Name != retrievedLogMetric.MetricDescriptor.Name {
// s = fmt.Sprintf("%sMetricDescriptor.Name\nwant %s\nhave %s\n", s,
// logMetric.MetricDescriptor.Name,
// retrievedLogMetric.MetricDescriptor.Name)
// }
if logMetric.MetricDescriptor.Description != retrievedLogMetric.MetricDescriptor.Description {
s = fmt.Sprintf("%sMetricDescriptor.Description\nwant %s\nhave %s\n", s,
logMetric.MetricDescriptor.Description,
Expand Down
13 changes: 9 additions & 4 deletions utilities/glo/meth_metricdeployment_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func (logMetricDeployment LogMetricDeployment) Deploy() (err error) {

metricFound := true
// GET
// ffo.MarshalYAMLWrite("./metric.yaml", logMetricDeployment.Artifacts.LogMetric)
retrievedLogMetric, err := projectMetricsService.Get(logMetricDeployment.Artifacts.LogMetric.Name).Context(logMetricDeployment.Core.Ctx).Do()
metricName := fmt.Sprintf("projects/%s/metrics/%s",
logMetricDeployment.Core.SolutionSettings.Hosting.ProjectID,
logMetricDeployment.Settings.Instance.GLO.MetricID)

retrievedLogMetric, err := projectMetricsService.Get(metricName).Context(logMetricDeployment.Core.Ctx).Do()

if err != nil {
fmt.Println(err.Error())
if strings.Contains(strings.ToLower(err.Error()), "notfound") {
metricFound = false
} else {
Expand All @@ -47,22 +49,25 @@ func (logMetricDeployment LogMetricDeployment) Deploy() (err error) {
}
log.Printf("%s glo create metric start", logMetricDeployment.Core.InstanceName)
parent := fmt.Sprintf("projects/%s", logMetricDeployment.Core.SolutionSettings.Hosting.ProjectID)
// ffo.YAMLMarshalPrint(&logMetricDeployment.Artifacts.LogMetric)
createdLogMetric, err := projectMetricsService.Create(parent, &logMetricDeployment.Artifacts.LogMetric).Context(logMetricDeployment.Core.Ctx).Do()
if err != nil {
return fmt.Errorf("projectMetricsService.Create %v", err)
}
// ffo.YAMLMarshalPrint(&createdLogMetric)
log.Printf("%s glo metric created %s", logMetricDeployment.Core.InstanceName, createdLogMetric.Name)
} else {
log.Printf("%s glo found log metric %s",
logMetricDeployment.Core.InstanceName,
retrievedLogMetric.Name)
// ffo.YAMLMarshalPrint(&retrievedLogMetric)
err = checkLogMetric(&logMetricDeployment.Artifacts.LogMetric, retrievedLogMetric)
if err != nil {
if logMetricDeployment.Core.Commands.Check {
return err
}
log.Printf("%s glo metric meed to be updated", logMetricDeployment.Core.InstanceName)
updatedLogMetric, err := projectMetricsService.Update(logMetricDeployment.Artifacts.LogMetric.Name, &logMetricDeployment.Artifacts.LogMetric).Context(logMetricDeployment.Core.Ctx).Do()
updatedLogMetric, err := projectMetricsService.Update(metricName, &logMetricDeployment.Artifacts.LogMetric).Context(logMetricDeployment.Core.Ctx).Do()
if err != nil {
return fmt.Errorf("projectMetricsService.Update %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion utilities/ramcli/meth_deployment_configuresetdashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (deployment *Deployment) configureSetDashboards() (err error) {
// dashboard.microServiceNameList = []string{"stream2bq", "monitor", "upload2gcs", "publish2fs", "splitdump", "dumpinventory", "listgroupmembers", "getgroupsettings", "listgroups", "convertlog2feed"}
// dashboards["RAM latency"] = dashboard

dashboard.columns = 1
dashboard.columns = 3
dashboard.widgetTypeList = []string{"widgetRAMe2eLatency", "widgetRAMLatency", "widgetRAMTriggerAge", "widgetGCFActiveInstances", "widgetGCFExecutionCount", "widgetGCFExecutionTime", "widgetGCFMemoryUsage"}
for _, microServiceName := range []string{"stream2bq", "monitor", "upload2gcs", "publish2fs", "splitdump", "dumpinventory", "listgroupmembers", "getgroupsettings", "listgroups", "convertlog2feed"} {
dashboard.microServiceNameList = []string{microServiceName}
Expand Down
25 changes: 25 additions & 0 deletions utilities/ramcli/meth_deployment_configuresetlogmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ func (deployment *Deployment) configureSetLogMetrics() (err error) {
os.Mkdir(instancesFolderPath, 0755)
}
logMetricListYAML := []byte(`
- glo:
metric_id: ram_execution_status
description: RAM execution status
filter: resource.type="cloud_function" jsonPayload.message="noretry" OR jsonPayload.message=~"^finish"
labels:
- name: environment
extractor: EXTRACT(jsonPayload.environment)
description: dev, prd...
valueType: string
- name: instance_name
extractor: EXTRACT(jsonPayload.instance_name)
description: instance name
valueType: string
- name: microservice_name
extractor: EXTRACT(jsonPayload.microservice_name)
description: microservice name
valueType: string
- name: status
extractor: REGEXP_EXTRACT(jsonPayload.message, "^([\\w\\-]+)")
description: finish means success, noretry means failure
valueType: string
metricDescriptor:
metricKind: DELTA
unit: '1'
valueType: INT64
- glo:
metric_id: ram_latency
description: RAM latency by component
Expand Down

0 comments on commit 705ccc2

Please # to comment.