-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a build duration metric with a few easy attributes. We should implement more attributes in the future, but these ones were the easiest to implement in the current CLI. The backend attribute gives a named backend for this build and the status is either completed, failed, or canceled when the context canceled error is returned. This also modifies some aspects of how the resource is configured by including `service.instance.id`. This id is used to uniquely identify the CLI invocation for use in downstream aggregators. This allows downstream aggregators to know that the metric for an instance has not reset and that it is a unique invocation for future aggregation. Some work will have to be done in the aggregator to prevent the storage of this instance id as it can cause issues with cardinality limitations, but it's necessary for the initial reporter to include this. The temporality selector is still the same, but has been removed from the otlp exporter options since that one doesn't seem to do anything. I also recently learned the temporality didn't do what I thought it did. I thought it would allow for multiple different invocations to be treated as the same instance for the purposes of aggregation. It does not work this way as the metric sdk considers each of these a gap reset. That's the reason the instance id was added. This makes the difference between cumulative and delta mostly cosmetic, but delta temporality has some benefits for downstream consumers for aggregation so it's likely good to keep. Signed-off-by: Jonathan A. Sternberg <[email protected]>
- Loading branch information
1 parent
78adfc8
commit 7ec0de2
Showing
7 changed files
with
156 additions
and
44 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
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
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
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,15 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
// IsExperimental checks if the experimental flag has been configured. | ||
func IsExperimental() bool { | ||
if v, ok := os.LookupEnv("BUILDX_EXPERIMENTAL"); ok { | ||
vv, _ := strconv.ParseBool(v) | ||
return vv | ||
} | ||
return false | ||
} |
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
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
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,35 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
const ( | ||
TimeUnit string = "ms" | ||
) | ||
|
||
type RecordFunc func(ctx context.Context, attrs ...attribute.KeyValue) | ||
|
||
func Measure(mp metric.MeterProvider, name string, opts ...metric.Int64HistogramOption) RecordFunc { | ||
allOpts := []metric.Int64HistogramOption{ | ||
metric.WithUnit(TimeUnit), | ||
} | ||
if len(opts) > 0 { | ||
allOpts = append(allOpts, opts...) | ||
} | ||
histogram, err := Meter(mp).Int64Histogram(name, allOpts...) | ||
if err != nil { | ||
otel.Handle(err) | ||
} | ||
|
||
start := time.Now() | ||
return func(ctx context.Context, attrs ...attribute.KeyValue) { | ||
dur := int64(time.Since(start) / time.Millisecond) | ||
histogram.Record(ctx, dur, metric.WithAttributes(attrs...)) | ||
} | ||
} |