diff --git a/.chloggen/gitproviderreceiver-namespace-adjustments.yaml b/.chloggen/gitproviderreceiver-namespace-adjustments.yaml new file mode 100644 index 000000000000..18fcc01fcf12 --- /dev/null +++ b/.chloggen/gitproviderreceiver-namespace-adjustments.yaml @@ -0,0 +1,31 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: gitproviderreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Changed git provider metrics to better match conventions" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [31985] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + - Renamed `git.repository.pull_request.open.time` to `git.repository.pull_request.time_open` + - Renamed `git.repository.pull_request.merged.time` to `git.repository.pull_request.time_to_merge` + - Renamed `git.repository.pull_request.approved.time` to `git.repository.pull_request.time_to_approval` + - Combined `git.repository.pull_request.merged.count` and `git.repository.pull_request.open.count` into `git.repository.pull_request.count` with an attribute of `pull_request.state` equal to `open` or `merged` + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/gitproviderreceiver/README.md b/receiver/gitproviderreceiver/README.md index 62e361c8a2db..2f1a857dd94a 100644 --- a/receiver/gitproviderreceiver/README.md +++ b/receiver/gitproviderreceiver/README.md @@ -27,12 +27,11 @@ The current metrics available via scraping from GitHub are: - [ ] Repository branch time - [x] Repository branch count - [x] Repository contributor count -- [x] Repository pull request open count - [x] Repository pull request open time -- [x] Repository pull request merged count -- [x] Repository pull request merged time -- [x] Repository pull request approved time +- [x] Repository pull request time to merge - [ ] Repository pull request deployment time +- [x] Repository pull request time to approval +- [x] Repository pull request count | stores an attribute of `pull_request.state` equal to `open` or `merged` > Note: Some metrics may be disabled by default and have to be explicitly enabled. > For example, the repository contributor count metric is one such metric. This is diff --git a/receiver/gitproviderreceiver/documentation.md b/receiver/gitproviderreceiver/documentation.md index 1401c32b4b53..ffdb07c23b62 100644 --- a/receiver/gitproviderreceiver/documentation.md +++ b/receiver/gitproviderreceiver/documentation.md @@ -34,24 +34,9 @@ Number of repositories in an organization | ---- | ----------- | ---------- | | {repository} | Gauge | Int | -### git.repository.pull_request.approved.time +### git.repository.pull_request.count -The amount of time it took a pull request to go from open to approved - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| s | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| repository.name | The name of a Git repository | Any Str | -| branch.name | The name of a Git branch | Any Str | - -### git.repository.pull_request.merged.count - -The number of merged pull requests in a repository +The number of pull requests in a repository, categorized by their state (either open or merged) | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -61,11 +46,12 @@ The number of merged pull requests in a repository | Name | Description | Values | | ---- | ----------- | ------ | +| pull_request.state | The state of a pull request | Str: ``open``, ``merged`` | | repository.name | The name of a Git repository | Any Str | -### git.repository.pull_request.merged.time +### git.repository.pull_request.time_open -The amount of time it took a pull request to go from open to merged +The amount of time a pull request has been open | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -78,23 +64,24 @@ The amount of time it took a pull request to go from open to merged | repository.name | The name of a Git repository | Any Str | | branch.name | The name of a Git branch | Any Str | -### git.repository.pull_request.open.count +### git.repository.pull_request.time_to_approval -The number of open pull requests in a repository +The amount of time it took a pull request to go from open to approved | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {pull_request} | Gauge | Int | +| s | Gauge | Int | #### Attributes | Name | Description | Values | | ---- | ----------- | ------ | | repository.name | The name of a Git repository | Any Str | +| branch.name | The name of a Git branch | Any Str | -### git.repository.pull_request.open.time +### git.repository.pull_request.time_to_merge -The amount of time a pull request has been open +The amount of time it took a pull request to go from open to merged | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | diff --git a/receiver/gitproviderreceiver/go.mod b/receiver/gitproviderreceiver/go.mod index 7952ec6c251a..f28f7420d5d6 100644 --- a/receiver/gitproviderreceiver/go.mod +++ b/receiver/gitproviderreceiver/go.mod @@ -88,7 +88,7 @@ require ( go.opentelemetry.io/collector/processor v0.98.0 // indirect go.opentelemetry.io/collector/service v0.98.0 // indirect go.opentelemetry.io/contrib/config v0.4.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 // indirect go.opentelemetry.io/contrib/propagators/b3 v1.25.0 // indirect go.opentelemetry.io/otel v1.25.0 // indirect go.opentelemetry.io/otel/bridge/opencensus v1.25.0 // indirect @@ -111,7 +111,7 @@ require ( gonum.org/v1/gonum v0.15.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect - google.golang.org/grpc v1.63.0 // indirect + google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/receiver/gitproviderreceiver/go.sum b/receiver/gitproviderreceiver/go.sum index e2f957376816..23da0c44eab0 100644 --- a/receiver/gitproviderreceiver/go.sum +++ b/receiver/gitproviderreceiver/go.sum @@ -223,8 +223,8 @@ go.opentelemetry.io/collector/service v0.98.0 h1:lLJ7VXPXcV62fSISh4GuNd5ti6WvKje go.opentelemetry.io/collector/service v0.98.0/go.mod h1:wB7ozvZTHtMefb5KTYy5nyrVYWpGk8teq8jWFs4blIU= go.opentelemetry.io/contrib/config v0.4.0 h1:Xb+ncYOqseLroMuBesGNRgVQolXcXOhMj7EhGwJCdHs= go.opentelemetry.io/contrib/config v0.4.0/go.mod h1:drNk2xRqLWW4/amk6Uh1S+sDAJTc7bcEEN1GfJzj418= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 h1:cEPbyTSEHlQR89XVlyo78gqluF8Y3oMeBkXGWzQsfXY= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0/go.mod h1:DKdbWcT4GH1D0Y3Sqt/PFXt2naRKDWtU+eE6oLdFNA8= go.opentelemetry.io/contrib/propagators/b3 v1.25.0 h1:QU8UEKyPqgr/8vCC9LlDmkPnfFmiWAUF9GtJdcLz+BU= go.opentelemetry.io/contrib/propagators/b3 v1.25.0/go.mod h1:qonC7wyvtX1E6cEpAR+bJmhcGr6IVRGc/f6ZTpvi7jA= go.opentelemetry.io/contrib/zpages v0.50.0 h1:hKC5asr83xDN4ErwSHVdk3gv053pZiF8SZKmS86IPEw= @@ -338,8 +338,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8= -google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/receiver/gitproviderreceiver/internal/metadata/generated_config.go b/receiver/gitproviderreceiver/internal/metadata/generated_config.go index 09d197fae192..64d884e82a68 100644 --- a/receiver/gitproviderreceiver/internal/metadata/generated_config.go +++ b/receiver/gitproviderreceiver/internal/metadata/generated_config.go @@ -25,14 +25,13 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for gitprovider metrics. type MetricsConfig struct { - GitRepositoryBranchCount MetricConfig `mapstructure:"git.repository.branch.count"` - GitRepositoryContributorCount MetricConfig `mapstructure:"git.repository.contributor.count"` - GitRepositoryCount MetricConfig `mapstructure:"git.repository.count"` - GitRepositoryPullRequestApprovedTime MetricConfig `mapstructure:"git.repository.pull_request.approved.time"` - GitRepositoryPullRequestMergedCount MetricConfig `mapstructure:"git.repository.pull_request.merged.count"` - GitRepositoryPullRequestMergedTime MetricConfig `mapstructure:"git.repository.pull_request.merged.time"` - GitRepositoryPullRequestOpenCount MetricConfig `mapstructure:"git.repository.pull_request.open.count"` - GitRepositoryPullRequestOpenTime MetricConfig `mapstructure:"git.repository.pull_request.open.time"` + GitRepositoryBranchCount MetricConfig `mapstructure:"git.repository.branch.count"` + GitRepositoryContributorCount MetricConfig `mapstructure:"git.repository.contributor.count"` + GitRepositoryCount MetricConfig `mapstructure:"git.repository.count"` + GitRepositoryPullRequestCount MetricConfig `mapstructure:"git.repository.pull_request.count"` + GitRepositoryPullRequestTimeOpen MetricConfig `mapstructure:"git.repository.pull_request.time_open"` + GitRepositoryPullRequestTimeToApproval MetricConfig `mapstructure:"git.repository.pull_request.time_to_approval"` + GitRepositoryPullRequestTimeToMerge MetricConfig `mapstructure:"git.repository.pull_request.time_to_merge"` } func DefaultMetricsConfig() MetricsConfig { @@ -46,19 +45,16 @@ func DefaultMetricsConfig() MetricsConfig { GitRepositoryCount: MetricConfig{ Enabled: true, }, - GitRepositoryPullRequestApprovedTime: MetricConfig{ + GitRepositoryPullRequestCount: MetricConfig{ Enabled: true, }, - GitRepositoryPullRequestMergedCount: MetricConfig{ + GitRepositoryPullRequestTimeOpen: MetricConfig{ Enabled: true, }, - GitRepositoryPullRequestMergedTime: MetricConfig{ + GitRepositoryPullRequestTimeToApproval: MetricConfig{ Enabled: true, }, - GitRepositoryPullRequestOpenCount: MetricConfig{ - Enabled: true, - }, - GitRepositoryPullRequestOpenTime: MetricConfig{ + GitRepositoryPullRequestTimeToMerge: MetricConfig{ Enabled: true, }, } diff --git a/receiver/gitproviderreceiver/internal/metadata/generated_config_test.go b/receiver/gitproviderreceiver/internal/metadata/generated_config_test.go index 33aabe5c3c73..7e432fd28356 100644 --- a/receiver/gitproviderreceiver/internal/metadata/generated_config_test.go +++ b/receiver/gitproviderreceiver/internal/metadata/generated_config_test.go @@ -26,14 +26,13 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - GitRepositoryBranchCount: MetricConfig{Enabled: true}, - GitRepositoryContributorCount: MetricConfig{Enabled: true}, - GitRepositoryCount: MetricConfig{Enabled: true}, - GitRepositoryPullRequestApprovedTime: MetricConfig{Enabled: true}, - GitRepositoryPullRequestMergedCount: MetricConfig{Enabled: true}, - GitRepositoryPullRequestMergedTime: MetricConfig{Enabled: true}, - GitRepositoryPullRequestOpenCount: MetricConfig{Enabled: true}, - GitRepositoryPullRequestOpenTime: MetricConfig{Enabled: true}, + GitRepositoryBranchCount: MetricConfig{Enabled: true}, + GitRepositoryContributorCount: MetricConfig{Enabled: true}, + GitRepositoryCount: MetricConfig{Enabled: true}, + GitRepositoryPullRequestCount: MetricConfig{Enabled: true}, + GitRepositoryPullRequestTimeOpen: MetricConfig{Enabled: true}, + GitRepositoryPullRequestTimeToApproval: MetricConfig{Enabled: true}, + GitRepositoryPullRequestTimeToMerge: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ GitVendorName: ResourceAttributeConfig{Enabled: true}, @@ -45,14 +44,13 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - GitRepositoryBranchCount: MetricConfig{Enabled: false}, - GitRepositoryContributorCount: MetricConfig{Enabled: false}, - GitRepositoryCount: MetricConfig{Enabled: false}, - GitRepositoryPullRequestApprovedTime: MetricConfig{Enabled: false}, - GitRepositoryPullRequestMergedCount: MetricConfig{Enabled: false}, - GitRepositoryPullRequestMergedTime: MetricConfig{Enabled: false}, - GitRepositoryPullRequestOpenCount: MetricConfig{Enabled: false}, - GitRepositoryPullRequestOpenTime: MetricConfig{Enabled: false}, + GitRepositoryBranchCount: MetricConfig{Enabled: false}, + GitRepositoryContributorCount: MetricConfig{Enabled: false}, + GitRepositoryCount: MetricConfig{Enabled: false}, + GitRepositoryPullRequestCount: MetricConfig{Enabled: false}, + GitRepositoryPullRequestTimeOpen: MetricConfig{Enabled: false}, + GitRepositoryPullRequestTimeToApproval: MetricConfig{Enabled: false}, + GitRepositoryPullRequestTimeToMerge: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ GitVendorName: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/gitproviderreceiver/internal/metadata/generated_metrics.go b/receiver/gitproviderreceiver/internal/metadata/generated_metrics.go index 7164629124ab..1916ea13e022 100644 --- a/receiver/gitproviderreceiver/internal/metadata/generated_metrics.go +++ b/receiver/gitproviderreceiver/internal/metadata/generated_metrics.go @@ -12,6 +12,32 @@ import ( conventions "go.opentelemetry.io/collector/semconv/v1.9.0" ) +// AttributePullRequestState specifies the a value pull_request.state attribute. +type AttributePullRequestState int + +const ( + _ AttributePullRequestState = iota + AttributePullRequestStateOpen + AttributePullRequestStateMerged +) + +// String returns the string representation of the AttributePullRequestState. +func (av AttributePullRequestState) String() string { + switch av { + case AttributePullRequestStateOpen: + return "open" + case AttributePullRequestStateMerged: + return "merged" + } + return "" +} + +// MapAttributePullRequestState is a helper map of string to AttributePullRequestState attribute value. +var MapAttributePullRequestState = map[string]AttributePullRequestState{ + "open": AttributePullRequestStateOpen, + "merged": AttributePullRequestStateMerged, +} + type metricGitRepositoryBranchCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -163,74 +189,22 @@ func newMetricGitRepositoryCount(cfg MetricConfig) metricGitRepositoryCount { return m } -type metricGitRepositoryPullRequestApprovedTime struct { +type metricGitRepositoryPullRequestCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. capacity int // max observed number of data points added to the metric. } -// init fills git.repository.pull_request.approved.time metric with initial data. -func (m *metricGitRepositoryPullRequestApprovedTime) init() { - m.data.SetName("git.repository.pull_request.approved.time") - m.data.SetDescription("The amount of time it took a pull request to go from open to approved") - m.data.SetUnit("s") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricGitRepositoryPullRequestApprovedTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("branch.name", branchNameAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricGitRepositoryPullRequestApprovedTime) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricGitRepositoryPullRequestApprovedTime) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricGitRepositoryPullRequestApprovedTime(cfg MetricConfig) metricGitRepositoryPullRequestApprovedTime { - m := metricGitRepositoryPullRequestApprovedTime{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricGitRepositoryPullRequestMergedCount struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills git.repository.pull_request.merged.count metric with initial data. -func (m *metricGitRepositoryPullRequestMergedCount) init() { - m.data.SetName("git.repository.pull_request.merged.count") - m.data.SetDescription("The number of merged pull requests in a repository") +// init fills git.repository.pull_request.count metric with initial data. +func (m *metricGitRepositoryPullRequestCount) init() { + m.data.SetName("git.repository.pull_request.count") + m.data.SetDescription("The number of pull requests in a repository, categorized by their state (either open or merged)") m.data.SetUnit("{pull_request}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricGitRepositoryPullRequestMergedCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { +func (m *metricGitRepositoryPullRequestCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, pullRequestStateAttributeValue string, repositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -238,18 +212,19 @@ func (m *metricGitRepositoryPullRequestMergedCount) recordDataPoint(start pcommo dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("pull_request.state", pullRequestStateAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricGitRepositoryPullRequestMergedCount) updateCapacity() { +func (m *metricGitRepositoryPullRequestCount) updateCapacity() { if m.data.Gauge().DataPoints().Len() > m.capacity { m.capacity = m.data.Gauge().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricGitRepositoryPullRequestMergedCount) emit(metrics pmetric.MetricSlice) { +func (m *metricGitRepositoryPullRequestCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -257,8 +232,8 @@ func (m *metricGitRepositoryPullRequestMergedCount) emit(metrics pmetric.MetricS } } -func newMetricGitRepositoryPullRequestMergedCount(cfg MetricConfig) metricGitRepositoryPullRequestMergedCount { - m := metricGitRepositoryPullRequestMergedCount{config: cfg} +func newMetricGitRepositoryPullRequestCount(cfg MetricConfig) metricGitRepositoryPullRequestCount { + m := metricGitRepositoryPullRequestCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -266,22 +241,22 @@ func newMetricGitRepositoryPullRequestMergedCount(cfg MetricConfig) metricGitRep return m } -type metricGitRepositoryPullRequestMergedTime struct { +type metricGitRepositoryPullRequestTimeOpen struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. capacity int // max observed number of data points added to the metric. } -// init fills git.repository.pull_request.merged.time metric with initial data. -func (m *metricGitRepositoryPullRequestMergedTime) init() { - m.data.SetName("git.repository.pull_request.merged.time") - m.data.SetDescription("The amount of time it took a pull request to go from open to merged") +// init fills git.repository.pull_request.time_open metric with initial data. +func (m *metricGitRepositoryPullRequestTimeOpen) init() { + m.data.SetName("git.repository.pull_request.time_open") + m.data.SetDescription("The amount of time a pull request has been open") m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricGitRepositoryPullRequestMergedTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { +func (m *metricGitRepositoryPullRequestTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { if !m.config.Enabled { return } @@ -294,14 +269,14 @@ func (m *metricGitRepositoryPullRequestMergedTime) recordDataPoint(start pcommon } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricGitRepositoryPullRequestMergedTime) updateCapacity() { +func (m *metricGitRepositoryPullRequestTimeOpen) updateCapacity() { if m.data.Gauge().DataPoints().Len() > m.capacity { m.capacity = m.data.Gauge().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricGitRepositoryPullRequestMergedTime) emit(metrics pmetric.MetricSlice) { +func (m *metricGitRepositoryPullRequestTimeOpen) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -309,8 +284,8 @@ func (m *metricGitRepositoryPullRequestMergedTime) emit(metrics pmetric.MetricSl } } -func newMetricGitRepositoryPullRequestMergedTime(cfg MetricConfig) metricGitRepositoryPullRequestMergedTime { - m := metricGitRepositoryPullRequestMergedTime{config: cfg} +func newMetricGitRepositoryPullRequestTimeOpen(cfg MetricConfig) metricGitRepositoryPullRequestTimeOpen { + m := metricGitRepositoryPullRequestTimeOpen{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -318,22 +293,22 @@ func newMetricGitRepositoryPullRequestMergedTime(cfg MetricConfig) metricGitRepo return m } -type metricGitRepositoryPullRequestOpenCount struct { +type metricGitRepositoryPullRequestTimeToApproval struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. capacity int // max observed number of data points added to the metric. } -// init fills git.repository.pull_request.open.count metric with initial data. -func (m *metricGitRepositoryPullRequestOpenCount) init() { - m.data.SetName("git.repository.pull_request.open.count") - m.data.SetDescription("The number of open pull requests in a repository") - m.data.SetUnit("{pull_request}") +// init fills git.repository.pull_request.time_to_approval metric with initial data. +func (m *metricGitRepositoryPullRequestTimeToApproval) init() { + m.data.SetName("git.repository.pull_request.time_to_approval") + m.data.SetDescription("The amount of time it took a pull request to go from open to approved") + m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricGitRepositoryPullRequestOpenCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { +func (m *metricGitRepositoryPullRequestTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { if !m.config.Enabled { return } @@ -342,17 +317,18 @@ func (m *metricGitRepositoryPullRequestOpenCount) recordDataPoint(start pcommon. dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("branch.name", branchNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricGitRepositoryPullRequestOpenCount) updateCapacity() { +func (m *metricGitRepositoryPullRequestTimeToApproval) updateCapacity() { if m.data.Gauge().DataPoints().Len() > m.capacity { m.capacity = m.data.Gauge().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricGitRepositoryPullRequestOpenCount) emit(metrics pmetric.MetricSlice) { +func (m *metricGitRepositoryPullRequestTimeToApproval) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -360,8 +336,8 @@ func (m *metricGitRepositoryPullRequestOpenCount) emit(metrics pmetric.MetricSli } } -func newMetricGitRepositoryPullRequestOpenCount(cfg MetricConfig) metricGitRepositoryPullRequestOpenCount { - m := metricGitRepositoryPullRequestOpenCount{config: cfg} +func newMetricGitRepositoryPullRequestTimeToApproval(cfg MetricConfig) metricGitRepositoryPullRequestTimeToApproval { + m := metricGitRepositoryPullRequestTimeToApproval{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -369,22 +345,22 @@ func newMetricGitRepositoryPullRequestOpenCount(cfg MetricConfig) metricGitRepos return m } -type metricGitRepositoryPullRequestOpenTime struct { +type metricGitRepositoryPullRequestTimeToMerge struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. capacity int // max observed number of data points added to the metric. } -// init fills git.repository.pull_request.open.time metric with initial data. -func (m *metricGitRepositoryPullRequestOpenTime) init() { - m.data.SetName("git.repository.pull_request.open.time") - m.data.SetDescription("The amount of time a pull request has been open") +// init fills git.repository.pull_request.time_to_merge metric with initial data. +func (m *metricGitRepositoryPullRequestTimeToMerge) init() { + m.data.SetName("git.repository.pull_request.time_to_merge") + m.data.SetDescription("The amount of time it took a pull request to go from open to merged") m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricGitRepositoryPullRequestOpenTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { +func (m *metricGitRepositoryPullRequestTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { if !m.config.Enabled { return } @@ -397,14 +373,14 @@ func (m *metricGitRepositoryPullRequestOpenTime) recordDataPoint(start pcommon.T } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricGitRepositoryPullRequestOpenTime) updateCapacity() { +func (m *metricGitRepositoryPullRequestTimeToMerge) updateCapacity() { if m.data.Gauge().DataPoints().Len() > m.capacity { m.capacity = m.data.Gauge().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricGitRepositoryPullRequestOpenTime) emit(metrics pmetric.MetricSlice) { +func (m *metricGitRepositoryPullRequestTimeToMerge) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -412,8 +388,8 @@ func (m *metricGitRepositoryPullRequestOpenTime) emit(metrics pmetric.MetricSlic } } -func newMetricGitRepositoryPullRequestOpenTime(cfg MetricConfig) metricGitRepositoryPullRequestOpenTime { - m := metricGitRepositoryPullRequestOpenTime{config: cfg} +func newMetricGitRepositoryPullRequestTimeToMerge(cfg MetricConfig) metricGitRepositoryPullRequestTimeToMerge { + m := metricGitRepositoryPullRequestTimeToMerge{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -424,19 +400,18 @@ func newMetricGitRepositoryPullRequestOpenTime(cfg MetricConfig) metricGitReposi // MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations // required to produce metric representation defined in metadata and user config. type MetricsBuilder struct { - config MetricsBuilderConfig // config of the metrics builder. - startTime pcommon.Timestamp // start time that will be applied to all recorded data points. - metricsCapacity int // maximum observed number of metrics per resource. - metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. - buildInfo component.BuildInfo // contains version information. - metricGitRepositoryBranchCount metricGitRepositoryBranchCount - metricGitRepositoryContributorCount metricGitRepositoryContributorCount - metricGitRepositoryCount metricGitRepositoryCount - metricGitRepositoryPullRequestApprovedTime metricGitRepositoryPullRequestApprovedTime - metricGitRepositoryPullRequestMergedCount metricGitRepositoryPullRequestMergedCount - metricGitRepositoryPullRequestMergedTime metricGitRepositoryPullRequestMergedTime - metricGitRepositoryPullRequestOpenCount metricGitRepositoryPullRequestOpenCount - metricGitRepositoryPullRequestOpenTime metricGitRepositoryPullRequestOpenTime + config MetricsBuilderConfig // config of the metrics builder. + startTime pcommon.Timestamp // start time that will be applied to all recorded data points. + metricsCapacity int // maximum observed number of metrics per resource. + metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. + buildInfo component.BuildInfo // contains version information. + metricGitRepositoryBranchCount metricGitRepositoryBranchCount + metricGitRepositoryContributorCount metricGitRepositoryContributorCount + metricGitRepositoryCount metricGitRepositoryCount + metricGitRepositoryPullRequestCount metricGitRepositoryPullRequestCount + metricGitRepositoryPullRequestTimeOpen metricGitRepositoryPullRequestTimeOpen + metricGitRepositoryPullRequestTimeToApproval metricGitRepositoryPullRequestTimeToApproval + metricGitRepositoryPullRequestTimeToMerge metricGitRepositoryPullRequestTimeToMerge } // metricBuilderOption applies changes to default metrics builder. @@ -451,18 +426,17 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ - config: mbc, - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: settings.BuildInfo, - metricGitRepositoryBranchCount: newMetricGitRepositoryBranchCount(mbc.Metrics.GitRepositoryBranchCount), - metricGitRepositoryContributorCount: newMetricGitRepositoryContributorCount(mbc.Metrics.GitRepositoryContributorCount), - metricGitRepositoryCount: newMetricGitRepositoryCount(mbc.Metrics.GitRepositoryCount), - metricGitRepositoryPullRequestApprovedTime: newMetricGitRepositoryPullRequestApprovedTime(mbc.Metrics.GitRepositoryPullRequestApprovedTime), - metricGitRepositoryPullRequestMergedCount: newMetricGitRepositoryPullRequestMergedCount(mbc.Metrics.GitRepositoryPullRequestMergedCount), - metricGitRepositoryPullRequestMergedTime: newMetricGitRepositoryPullRequestMergedTime(mbc.Metrics.GitRepositoryPullRequestMergedTime), - metricGitRepositoryPullRequestOpenCount: newMetricGitRepositoryPullRequestOpenCount(mbc.Metrics.GitRepositoryPullRequestOpenCount), - metricGitRepositoryPullRequestOpenTime: newMetricGitRepositoryPullRequestOpenTime(mbc.Metrics.GitRepositoryPullRequestOpenTime), + config: mbc, + startTime: pcommon.NewTimestampFromTime(time.Now()), + metricsBuffer: pmetric.NewMetrics(), + buildInfo: settings.BuildInfo, + metricGitRepositoryBranchCount: newMetricGitRepositoryBranchCount(mbc.Metrics.GitRepositoryBranchCount), + metricGitRepositoryContributorCount: newMetricGitRepositoryContributorCount(mbc.Metrics.GitRepositoryContributorCount), + metricGitRepositoryCount: newMetricGitRepositoryCount(mbc.Metrics.GitRepositoryCount), + metricGitRepositoryPullRequestCount: newMetricGitRepositoryPullRequestCount(mbc.Metrics.GitRepositoryPullRequestCount), + metricGitRepositoryPullRequestTimeOpen: newMetricGitRepositoryPullRequestTimeOpen(mbc.Metrics.GitRepositoryPullRequestTimeOpen), + metricGitRepositoryPullRequestTimeToApproval: newMetricGitRepositoryPullRequestTimeToApproval(mbc.Metrics.GitRepositoryPullRequestTimeToApproval), + metricGitRepositoryPullRequestTimeToMerge: newMetricGitRepositoryPullRequestTimeToMerge(mbc.Metrics.GitRepositoryPullRequestTimeToMerge), } for _, op := range options { op(mb) @@ -528,11 +502,10 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricGitRepositoryBranchCount.emit(ils.Metrics()) mb.metricGitRepositoryContributorCount.emit(ils.Metrics()) mb.metricGitRepositoryCount.emit(ils.Metrics()) - mb.metricGitRepositoryPullRequestApprovedTime.emit(ils.Metrics()) - mb.metricGitRepositoryPullRequestMergedCount.emit(ils.Metrics()) - mb.metricGitRepositoryPullRequestMergedTime.emit(ils.Metrics()) - mb.metricGitRepositoryPullRequestOpenCount.emit(ils.Metrics()) - mb.metricGitRepositoryPullRequestOpenTime.emit(ils.Metrics()) + mb.metricGitRepositoryPullRequestCount.emit(ils.Metrics()) + mb.metricGitRepositoryPullRequestTimeOpen.emit(ils.Metrics()) + mb.metricGitRepositoryPullRequestTimeToApproval.emit(ils.Metrics()) + mb.metricGitRepositoryPullRequestTimeToMerge.emit(ils.Metrics()) for _, op := range rmo { op(rm) @@ -568,29 +541,24 @@ func (mb *MetricsBuilder) RecordGitRepositoryCountDataPoint(ts pcommon.Timestamp mb.metricGitRepositoryCount.recordDataPoint(mb.startTime, ts, val) } -// RecordGitRepositoryPullRequestApprovedTimeDataPoint adds a data point to git.repository.pull_request.approved.time metric. -func (mb *MetricsBuilder) RecordGitRepositoryPullRequestApprovedTimeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { - mb.metricGitRepositoryPullRequestApprovedTime.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) -} - -// RecordGitRepositoryPullRequestMergedCountDataPoint adds a data point to git.repository.pull_request.merged.count metric. -func (mb *MetricsBuilder) RecordGitRepositoryPullRequestMergedCountDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { - mb.metricGitRepositoryPullRequestMergedCount.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue) +// RecordGitRepositoryPullRequestCountDataPoint adds a data point to git.repository.pull_request.count metric. +func (mb *MetricsBuilder) RecordGitRepositoryPullRequestCountDataPoint(ts pcommon.Timestamp, val int64, pullRequestStateAttributeValue AttributePullRequestState, repositoryNameAttributeValue string) { + mb.metricGitRepositoryPullRequestCount.recordDataPoint(mb.startTime, ts, val, pullRequestStateAttributeValue.String(), repositoryNameAttributeValue) } -// RecordGitRepositoryPullRequestMergedTimeDataPoint adds a data point to git.repository.pull_request.merged.time metric. -func (mb *MetricsBuilder) RecordGitRepositoryPullRequestMergedTimeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { - mb.metricGitRepositoryPullRequestMergedTime.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) +// RecordGitRepositoryPullRequestTimeOpenDataPoint adds a data point to git.repository.pull_request.time_open metric. +func (mb *MetricsBuilder) RecordGitRepositoryPullRequestTimeOpenDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { + mb.metricGitRepositoryPullRequestTimeOpen.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) } -// RecordGitRepositoryPullRequestOpenCountDataPoint adds a data point to git.repository.pull_request.open.count metric. -func (mb *MetricsBuilder) RecordGitRepositoryPullRequestOpenCountDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { - mb.metricGitRepositoryPullRequestOpenCount.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue) +// RecordGitRepositoryPullRequestTimeToApprovalDataPoint adds a data point to git.repository.pull_request.time_to_approval metric. +func (mb *MetricsBuilder) RecordGitRepositoryPullRequestTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { + mb.metricGitRepositoryPullRequestTimeToApproval.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) } -// RecordGitRepositoryPullRequestOpenTimeDataPoint adds a data point to git.repository.pull_request.open.time metric. -func (mb *MetricsBuilder) RecordGitRepositoryPullRequestOpenTimeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { - mb.metricGitRepositoryPullRequestOpenTime.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) +// RecordGitRepositoryPullRequestTimeToMergeDataPoint adds a data point to git.repository.pull_request.time_to_merge metric. +func (mb *MetricsBuilder) RecordGitRepositoryPullRequestTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, branchNameAttributeValue string) { + mb.metricGitRepositoryPullRequestTimeToMerge.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, branchNameAttributeValue) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/receiver/gitproviderreceiver/internal/metadata/generated_metrics_test.go b/receiver/gitproviderreceiver/internal/metadata/generated_metrics_test.go index 14aa1af5623f..b32d398a8f79 100644 --- a/receiver/gitproviderreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/gitproviderreceiver/internal/metadata/generated_metrics_test.go @@ -68,23 +68,19 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordGitRepositoryPullRequestApprovedTimeDataPoint(ts, 1, "repository.name-val", "branch.name-val") + mb.RecordGitRepositoryPullRequestCountDataPoint(ts, 1, AttributePullRequestStateOpen, "repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordGitRepositoryPullRequestMergedCountDataPoint(ts, 1, "repository.name-val") + mb.RecordGitRepositoryPullRequestTimeOpenDataPoint(ts, 1, "repository.name-val", "branch.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordGitRepositoryPullRequestMergedTimeDataPoint(ts, 1, "repository.name-val", "branch.name-val") + mb.RecordGitRepositoryPullRequestTimeToApprovalDataPoint(ts, 1, "repository.name-val", "branch.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordGitRepositoryPullRequestOpenCountDataPoint(ts, 1, "repository.name-val") - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordGitRepositoryPullRequestOpenTimeDataPoint(ts, 1, "repository.name-val", "branch.name-val") + mb.RecordGitRepositoryPullRequestTimeToMergeDataPoint(ts, 1, "repository.name-val", "branch.name-val") rb := mb.NewResourceBuilder() rb.SetGitVendorName("git.vendor.name-val") @@ -153,45 +149,30 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) - case "git.repository.pull_request.approved.time": - assert.False(t, validatedMetrics["git.repository.pull_request.approved.time"], "Found a duplicate in the metrics slice: git.repository.pull_request.approved.time") - validatedMetrics["git.repository.pull_request.approved.time"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The amount of time it took a pull request to go from open to approved", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) - assert.Equal(t, int64(1), dp.IntValue()) - attrVal, ok := dp.Attributes().Get("repository.name") - assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("branch.name") - assert.True(t, ok) - assert.EqualValues(t, "branch.name-val", attrVal.Str()) - case "git.repository.pull_request.merged.count": - assert.False(t, validatedMetrics["git.repository.pull_request.merged.count"], "Found a duplicate in the metrics slice: git.repository.pull_request.merged.count") - validatedMetrics["git.repository.pull_request.merged.count"] = true + case "git.repository.pull_request.count": + assert.False(t, validatedMetrics["git.repository.pull_request.count"], "Found a duplicate in the metrics slice: git.repository.pull_request.count") + validatedMetrics["git.repository.pull_request.count"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The number of merged pull requests in a repository", ms.At(i).Description()) + assert.Equal(t, "The number of pull requests in a repository, categorized by their state (either open or merged)", ms.At(i).Description()) assert.Equal(t, "{pull_request}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("pull_request.state") + assert.True(t, ok) + assert.EqualValues(t, "open", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) - case "git.repository.pull_request.merged.time": - assert.False(t, validatedMetrics["git.repository.pull_request.merged.time"], "Found a duplicate in the metrics slice: git.repository.pull_request.merged.time") - validatedMetrics["git.repository.pull_request.merged.time"] = true + case "git.repository.pull_request.time_open": + assert.False(t, validatedMetrics["git.repository.pull_request.time_open"], "Found a duplicate in the metrics slice: git.repository.pull_request.time_open") + validatedMetrics["git.repository.pull_request.time_open"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The amount of time it took a pull request to go from open to merged", ms.At(i).Description()) + assert.Equal(t, "The amount of time a pull request has been open", ms.At(i).Description()) assert.Equal(t, "s", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) @@ -204,13 +185,13 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("branch.name") assert.True(t, ok) assert.EqualValues(t, "branch.name-val", attrVal.Str()) - case "git.repository.pull_request.open.count": - assert.False(t, validatedMetrics["git.repository.pull_request.open.count"], "Found a duplicate in the metrics slice: git.repository.pull_request.open.count") - validatedMetrics["git.repository.pull_request.open.count"] = true + case "git.repository.pull_request.time_to_approval": + assert.False(t, validatedMetrics["git.repository.pull_request.time_to_approval"], "Found a duplicate in the metrics slice: git.repository.pull_request.time_to_approval") + validatedMetrics["git.repository.pull_request.time_to_approval"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The number of open pull requests in a repository", ms.At(i).Description()) - assert.Equal(t, "{pull_request}", ms.At(i).Unit()) + assert.Equal(t, "The amount of time it took a pull request to go from open to approved", ms.At(i).Description()) + assert.Equal(t, "s", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -219,12 +200,15 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) - case "git.repository.pull_request.open.time": - assert.False(t, validatedMetrics["git.repository.pull_request.open.time"], "Found a duplicate in the metrics slice: git.repository.pull_request.open.time") - validatedMetrics["git.repository.pull_request.open.time"] = true + attrVal, ok = dp.Attributes().Get("branch.name") + assert.True(t, ok) + assert.EqualValues(t, "branch.name-val", attrVal.Str()) + case "git.repository.pull_request.time_to_merge": + assert.False(t, validatedMetrics["git.repository.pull_request.time_to_merge"], "Found a duplicate in the metrics slice: git.repository.pull_request.time_to_merge") + validatedMetrics["git.repository.pull_request.time_to_merge"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The amount of time a pull request has been open", ms.At(i).Description()) + assert.Equal(t, "The amount of time it took a pull request to go from open to merged", ms.At(i).Description()) assert.Equal(t, "s", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) diff --git a/receiver/gitproviderreceiver/internal/metadata/testdata/config.yaml b/receiver/gitproviderreceiver/internal/metadata/testdata/config.yaml index b650230a6769..cc2fa0fd2bd6 100644 --- a/receiver/gitproviderreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/gitproviderreceiver/internal/metadata/testdata/config.yaml @@ -7,15 +7,13 @@ all_set: enabled: true git.repository.count: enabled: true - git.repository.pull_request.approved.time: + git.repository.pull_request.count: enabled: true - git.repository.pull_request.merged.count: + git.repository.pull_request.time_open: enabled: true - git.repository.pull_request.merged.time: + git.repository.pull_request.time_to_approval: enabled: true - git.repository.pull_request.open.count: - enabled: true - git.repository.pull_request.open.time: + git.repository.pull_request.time_to_merge: enabled: true resource_attributes: git.vendor.name: @@ -30,15 +28,13 @@ none_set: enabled: false git.repository.count: enabled: false - git.repository.pull_request.approved.time: - enabled: false - git.repository.pull_request.merged.count: + git.repository.pull_request.count: enabled: false - git.repository.pull_request.merged.time: + git.repository.pull_request.time_open: enabled: false - git.repository.pull_request.open.count: + git.repository.pull_request.time_to_approval: enabled: false - git.repository.pull_request.open.time: + git.repository.pull_request.time_to_merge: enabled: false resource_attributes: git.vendor.name: diff --git a/receiver/gitproviderreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/gitproviderreceiver/internal/scraper/githubscraper/github_scraper.go index c2c22d8081a7..4aa15fe5d44e 100644 --- a/receiver/gitproviderreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/gitproviderreceiver/internal/scraper/githubscraper/github_scraper.go @@ -136,25 +136,25 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { age := getAge(pr.CreatedAt, pr.MergedAt) - ghs.mb.RecordGitRepositoryPullRequestMergedTimeDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordGitRepositoryPullRequestTimeToMergeDataPoint(now, age, name, pr.HeadRefName) } else { open++ age := getAge(pr.CreatedAt, now.AsTime()) - ghs.mb.RecordGitRepositoryPullRequestOpenTimeDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordGitRepositoryPullRequestTimeOpenDataPoint(now, age, name, pr.HeadRefName) if pr.Reviews.TotalCount > 0 { age := getAge(pr.CreatedAt, pr.Reviews.Nodes[0].CreatedAt) - ghs.mb.RecordGitRepositoryPullRequestApprovedTimeDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordGitRepositoryPullRequestTimeToApprovalDataPoint(now, age, name, pr.HeadRefName) } } } - ghs.mb.RecordGitRepositoryPullRequestOpenCountDataPoint(now, int64(open), name) - ghs.mb.RecordGitRepositoryPullRequestMergedCountDataPoint(now, int64(merged), name) + ghs.mb.RecordGitRepositoryPullRequestCountDataPoint(now, int64(open), metadata.AttributePullRequestStateOpen, name) + ghs.mb.RecordGitRepositoryPullRequestCountDataPoint(now, int64(merged), metadata.AttributePullRequestStateMerged, name) }() } diff --git a/receiver/gitproviderreceiver/metadata.yaml b/receiver/gitproviderreceiver/metadata.yaml index 469110181680..de285f0a7f1d 100644 --- a/receiver/gitproviderreceiver/metadata.yaml +++ b/receiver/gitproviderreceiver/metadata.yaml @@ -31,6 +31,12 @@ attributes: branch.name: description: The name of a Git branch type: string + pull_request.state: + description: The state of a pull request + type: string + enum: + - open + - merged metrics: git.repository.count: @@ -54,41 +60,34 @@ metrics: gauge: value_type: int attributes: [repository.name] - git.repository.pull_request.merged.count: - enabled: true - description: The number of merged pull requests in a repository - unit: "{pull_request}" - gauge: - value_type: int - attributes: [repository.name] - git.repository.pull_request.open.count: - enabled: true - description: The number of open pull requests in a repository - unit: "{pull_request}" - gauge: - value_type: int - attributes: [repository.name] - git.repository.pull_request.open.time: + git.repository.pull_request.time_open: enabled: true description: The amount of time a pull request has been open unit: s gauge: value_type: int attributes: [repository.name, branch.name] - git.repository.pull_request.merged.time: + git.repository.pull_request.time_to_merge: enabled: true description: The amount of time it took a pull request to go from open to merged unit: s gauge: value_type: int attributes: [repository.name, branch.name] - git.repository.pull_request.approved.time: + git.repository.pull_request.time_to_approval: enabled: true description: The amount of time it took a pull request to go from open to approved unit: s gauge: value_type: int attributes: [repository.name, branch.name] + git.repository.pull_request.count: + description: The number of pull requests in a repository, categorized by their state (either open or merged) + enabled: true + gauge: + value_type: int + unit: '{pull_request}' + attributes: [pull_request.state, repository.name] tests: config: