Skip to content

Commit

Permalink
Only recreate metric descriptors when metric kind or value type is di…
Browse files Browse the repository at this point in the history
…fferent
  • Loading branch information
knyar committed Oct 3, 2019
1 parent a373b54 commit 767c769
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions stackdriver/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"google.golang.org/appengine/log"
metricpb "google.golang.org/genproto/googleapis/api/metric"
Expand Down Expand Up @@ -111,11 +110,13 @@ func (a *Adapter) setDescriptor(ctx context.Context, project, name string, desc
if err != nil {
return fmt.Errorf("Error while getting descriptor for %s: %s", name, err)
}
if proto.Equal(current, desc) {
// Metric descriptors cannot be updated in-place, and deleting a descriptor requries the metric
// to not be used for alerts. This is why the descriptor is only deleted and recreated if absolutely
// necessary, i.e. when metric kind or value type is different.
if current.GetMetricKind() == desc.GetMetricKind() && current.GetValueType() == desc.GetValueType() {
return nil
}
if current != nil {
// There's no way to update an existing metric descriptor, so we need to delete and then create a new one.
log.Infof(ctx, "Deleting existing metric descriptor (%v) which is different from desired (%v)", current, desc)
err = a.c.DeleteMetricDescriptor(ctx, &monitoringpb.DeleteMetricDescriptorRequest{Name: current.Name})
if err != nil {
Expand Down

0 comments on commit 767c769

Please sign in to comment.