From 83514ec15023945defa25d113d2ceb1f73e76ebe Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Tue, 3 Dec 2024 21:19:00 -0500 Subject: [PATCH 01/18] [receiver/github] add `vcs.repository.url.full` attribute --- receiver/githubreceiver/documentation.md | 11 +++ .../githubreceiver/generated_package_test.go | 3 +- .../internal/metadata/generated_metrics.go | 77 +++++++++++-------- .../metadata/generated_metrics_test.go | 77 +++++++++++++------ .../githubscraper/generated_graphql.go | 7 ++ .../scraper/githubscraper/genqlient.graphql | 1 + .../scraper/githubscraper/genqlient.yaml | 2 + .../scraper/githubscraper/github_scraper.go | 26 ++++--- .../testdata/scraper/expected_happy_path.yaml | 30 ++++++++ receiver/githubreceiver/metadata.yaml | 25 +++--- 10 files changed, 179 insertions(+), 80 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index a95f684a1fd7..49cb6b9954ac 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -24,6 +24,7 @@ The number of changes (pull requests) in a repository, categorized by their stat | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | | repository.name | The name of a VCS repository | Any Str | @@ -39,6 +40,7 @@ The amount of time a change (pull request) has been open. | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | @@ -54,6 +56,7 @@ The amount of time it took a change (pull request) to go from open to approved. | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | @@ -69,6 +72,7 @@ The amount of time it took a change (pull request) to go from open to merged. | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | @@ -92,6 +96,7 @@ The number of refs of type branch in a repository. | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -107,6 +112,7 @@ The number of lines added in a ref (branch) relative to the default branch (trun | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -123,6 +129,7 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -139,6 +146,7 @@ The number of revisions (commits) a ref (branch) is ahead of the default branch | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -155,6 +163,7 @@ The number of revisions (commits) a ref (branch) is behind the default branch (t | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -171,6 +180,7 @@ Time a ref (branch) created from the default branch (trunk) has existed. The `re | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -197,6 +207,7 @@ The number of unique contributors to a repository. | Name | Description | Values | | ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | repository.name | The name of a VCS repository | Any Str | ## Resource Attributes diff --git a/receiver/githubreceiver/generated_package_test.go b/receiver/githubreceiver/generated_package_test.go index 08b03a769078..23f7579ccba3 100644 --- a/receiver/githubreceiver/generated_package_test.go +++ b/receiver/githubreceiver/generated_package_test.go @@ -3,9 +3,8 @@ package githubreceiver import ( - "testing" - "go.uber.org/goleak" + "testing" ) func TestMain(m *testing.M) { diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 440151dea48f..1ad836545d5c 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -80,7 +80,7 @@ func (m *metricVcsRepositoryChangeCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, changeStateAttributeValue string, repositoryNameAttributeValue string) { +func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue string, repositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -88,6 +88,7 @@ func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("change.state", changeStateAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) } @@ -132,7 +133,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -140,6 +141,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timest dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -184,7 +186,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -192,6 +194,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon. dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -236,7 +239,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -244,6 +247,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Tim dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -288,7 +292,7 @@ func (m *metricVcsRepositoryContributorCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { +func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -296,6 +300,7 @@ func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Time dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) } @@ -388,7 +393,7 @@ func (m *metricVcsRepositoryRefCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -396,6 +401,7 @@ func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, t dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -440,7 +446,7 @@ func (m *metricVcsRepositoryRefLinesAdded) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -448,6 +454,7 @@ func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timesta dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) @@ -493,7 +500,7 @@ func (m *metricVcsRepositoryRefLinesDeleted) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -501,6 +508,7 @@ func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Times dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) @@ -546,7 +554,7 @@ func (m *metricVcsRepositoryRefRevisionsAhead) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -554,6 +562,7 @@ func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Tim dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) @@ -599,7 +608,7 @@ func (m *metricVcsRepositoryRefRevisionsBehind) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -607,6 +616,7 @@ func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Ti dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) @@ -652,7 +662,7 @@ func (m *metricVcsRepositoryRefTime) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -660,6 +670,7 @@ func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) @@ -879,28 +890,28 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics } // RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, changeStateAttributeValue AttributeChangeState, repositoryNameAttributeValue string) { - mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, changeStateAttributeValue.String(), repositoryNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue AttributeChangeState, repositoryNameAttributeValue string) { + mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, changeStateAttributeValue.String(), repositoryNameAttributeValue) } // RecordVcsRepositoryChangeTimeOpenDataPoint adds a data point to vcs.repository.change.time_open metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryChangeTimeToApprovalDataPoint adds a data point to vcs.repository.change.time_to_approval metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryChangeTimeToMergeDataPoint adds a data point to vcs.repository.change.time_to_merge metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryContributorCountDataPoint adds a data point to vcs.repository.contributor.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryContributorCountDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { - mb.metricVcsRepositoryContributorCount.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string) { + mb.metricVcsRepositoryContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue) } // RecordVcsRepositoryCountDataPoint adds a data point to vcs.repository.count metric. @@ -909,33 +920,33 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp } // RecordVcsRepositoryRefCountDataPoint adds a data point to vcs.repository.ref.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesAddedDataPoint adds a data point to vcs.repository.ref.lines_added metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesDeletedDataPoint adds a data point to vcs.repository.ref.lines_deleted metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsAheadDataPoint adds a data point to vcs.repository.ref.revisions_ahead metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsBehindDataPoint adds a data point to vcs.repository.ref.revisions_behind metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefTimeDataPoint adds a data point to vcs.repository.ref.time metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index cde077b95c6b..11f42c13dc3d 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -70,22 +70,22 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, AttributeChangeStateOpen, "repository.name-val") + mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeChangeStateOpen, "repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") allMetricsCount++ - mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "repository.name-val") + mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val") defaultMetricsCount++ allMetricsCount++ @@ -93,27 +93,27 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "repository.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") @@ -152,7 +152,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("change.state") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("change.state") assert.True(t, ok) assert.EqualValues(t, "open", attrVal.Str()) attrVal, ok = dp.Attributes().Get("repository.name") @@ -170,7 +173,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -188,7 +194,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -206,7 +215,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -224,7 +236,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) case "vcs.repository.count": @@ -251,7 +266,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.type") @@ -269,7 +287,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -290,7 +311,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -311,7 +335,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -332,7 +359,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") @@ -353,7 +383,10 @@ 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()) - attrVal, ok := dp.Attributes().Get("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("repository.name") assert.True(t, ok) assert.EqualValues(t, "repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go index db5f5271fb75..de96d4ae168a 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "net/url" "time" "github.com/Khan/genqlient/graphql" @@ -749,6 +750,8 @@ type SearchNodeRepository struct { Name string `json:"name"` // The Ref associated with the repository's default branch. DefaultBranchRef SearchNodeDefaultBranchRef `json:"defaultBranchRef"` + // The HTTP URL for this repository + Url url.URL `json:"url"` } // GetTypename returns SearchNodeRepository.Typename, and is useful for accessing the field via an interface. @@ -765,6 +768,9 @@ func (v *SearchNodeRepository) GetDefaultBranchRef() SearchNodeDefaultBranchRef return v.DefaultBranchRef } +// GetUrl returns SearchNodeRepository.Url, and is useful for accessing the field via an interface. +func (v *SearchNodeRepository) GetUrl() url.URL { return v.Url } + // SearchNodeUser includes the requested fields of the GraphQL type User. // The GraphQL type's documentation follows. // @@ -1463,6 +1469,7 @@ query getRepoDataBySearch ($searchQuery: String!, $repoCursor: String) { defaultBranchRef { name } + url } } pageInfo { diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql index 7a66c245fbcb..1d89fdad565d 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql +++ b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql @@ -18,6 +18,7 @@ query getRepoDataBySearch( defaultBranchRef { name } + url } } pageInfo { diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml index fc6183da61bf..088eab8ef795 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml @@ -11,4 +11,6 @@ generated: generated_graphql.go bindings: DateTime: type: time.Time + URI: + type: net/url.URL diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 70bf35f059fa..5b9fff9cdc35 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -8,6 +8,7 @@ package githubscraper // import "github.com/open-telemetry/opentelemetry-collect import ( "context" "errors" + "fmt" "net/http" "sync" "time" @@ -104,6 +105,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { for _, repo := range repos { repo := repo name := repo.Name + url := fmt.Sprint(repo.Url) trunk := repo.DefaultBranchRef.Name now := now @@ -120,7 +122,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { mux.Lock() refType := metadata.AttributeRefTypeBranch - ghs.mb.RecordVcsRepositoryRefCountDataPoint(now, int64(count), name, refType) + ghs.mb.RecordVcsRepositoryRefCountDataPoint(now, int64(count), url, name, refType) // Iterate through the refs (branches) populating the Branch focused // metrics @@ -136,8 +138,8 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { // See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/githubreceiver/internal/scraper/githubscraper/README.md#github-limitations // for more information as to why `BehindBy` and `AheadBy` are // swapped. - ghs.mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(now, int64(branch.Compare.BehindBy), branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(now, int64(branch.Compare.AheadBy), branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType) var additions int var deletions int @@ -149,9 +151,9 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { continue } - ghs.mb.RecordVcsRepositoryRefTimeDataPoint(now, age, branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefLinesAddedDataPoint(now, int64(additions), branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefLinesDeletedDataPoint(now, int64(deletions), branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRepositoryRefTimeDataPoint(now, age, url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRepositoryRefLinesAddedDataPoint(now, int64(additions), url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRepositoryRefLinesDeletedDataPoint(now, int64(deletions), url, branch.Repository.Name, branch.Name, refType) } // Get the contributor count for each of the repositories @@ -159,7 +161,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { if err != nil { ghs.logger.Sugar().Errorf("error getting contributor count: %v", zap.Error(err)) } - ghs.mb.RecordVcsRepositoryContributorCountDataPoint(now, int64(contribs), name) + ghs.mb.RecordVcsRepositoryContributorCountDataPoint(now, int64(contribs), url, name) // Get change (pull request) data prs, err := ghs.getPullRequests(ctx, genClient, name) @@ -176,24 +178,24 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { age := getAge(pr.CreatedAt, pr.MergedAt) - ghs.mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(now, age, url, name, pr.HeadRefName) } else { open++ age := getAge(pr.CreatedAt, now.AsTime()) - ghs.mb.RecordVcsRepositoryChangeTimeOpenDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordVcsRepositoryChangeTimeOpenDataPoint(now, age, url, name, pr.HeadRefName) if pr.Reviews.TotalCount > 0 { age := getAge(pr.CreatedAt, pr.Reviews.Nodes[0].CreatedAt) - ghs.mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(now, age, name, pr.HeadRefName) + ghs.mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(now, age, url, name, pr.HeadRefName) } } } - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(open), metadata.AttributeChangeStateOpen, name) - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(merged), metadata.AttributeChangeStateMerged, name) + ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(open), url, metadata.AttributeChangeStateOpen, name) + ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(merged), url, metadata.AttributeChangeStateMerged, name) mux.Unlock() }() } diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 45cc52ce905d..28ed9a825358 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -21,6 +21,9 @@ resourceMetrics: - key: repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" - asInt: "1" @@ -31,6 +34,9 @@ resourceMetrics: - key: repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.change.count @@ -46,6 +52,9 @@ resourceMetrics: - key: repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.change.time_open @@ -61,6 +70,9 @@ resourceMetrics: - key: repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.change.time_to_merge @@ -84,6 +96,9 @@ resourceMetrics: - key: repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.count @@ -102,6 +117,9 @@ resourceMetrics: - key: repository.name value: stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.lines_added @@ -120,6 +138,9 @@ resourceMetrics: - key: repository.name value: stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.lines_deleted @@ -138,6 +159,9 @@ resourceMetrics: - key: repository.name value: stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.revisions_ahead @@ -156,6 +180,9 @@ resourceMetrics: - key: repository.name value: stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.revisions_behind @@ -174,6 +201,9 @@ resourceMetrics: - key: repository.name value: stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.repository.ref.time diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 5b505c498998..aae565fdd7f9 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -21,6 +21,9 @@ resource_attributes: type: string attributes: + vcs.repository.url.full: + description: The canonical URL of the repository providing the complete HTTPS address. + type: string repository.name: description: The name of a VCS repository type: string @@ -54,77 +57,77 @@ metrics: unit: "{ref}" gauge: value_type: int - attributes: [repository.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.type] vcs.repository.ref.time: enabled: true description: Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. unit: s gauge: value_type: int - attributes: [repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] vcs.repository.ref.revisions_ahead: enabled: true description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] vcs.repository.ref.revisions_behind: enabled: true description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] vcs.repository.ref.lines_added: enabled: true description: The number of lines added in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] vcs.repository.ref.lines_deleted: enabled: true description: The number of lines deleted in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] vcs.repository.contributor.count: enabled: false description: The number of unique contributors to a repository. unit: "{contributor}" gauge: value_type: int - attributes: [repository.name] + attributes: [vcs.repository.url.full, repository.name] vcs.repository.change.time_open: enabled: true description: The amount of time a change (pull request) has been open. unit: s gauge: value_type: int - attributes: [repository.name, ref.name] + attributes: [vcs.repository.url.full, repository.name, ref.name] vcs.repository.change.time_to_merge: enabled: true description: The amount of time it took a change (pull request) to go from open to merged. unit: s gauge: value_type: int - attributes: [repository.name, ref.name] + attributes: [vcs.repository.url.full, repository.name, ref.name] vcs.repository.change.time_to_approval: enabled: true description: The amount of time it took a change (pull request) to go from open to approved. unit: s gauge: value_type: int - attributes: [repository.name, ref.name] + attributes: [vcs.repository.url.full, repository.name, ref.name] vcs.repository.change.count: description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). enabled: true gauge: value_type: int unit: "{change}" - attributes: [change.state, repository.name] + attributes: [vcs.repository.url.full, change.state, repository.name] tests: config: From 7d4eb20ea4fedb29134b350719fac38e7d50dbbd Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 21:34:03 -0500 Subject: [PATCH 02/18] [receiver/github] change repository.name to vcs.repository.name --- receiver/githubreceiver/documentation.md | 22 ++--- .../internal/metadata/generated_metrics.go | 88 +++++++++---------- .../metadata/generated_metrics_test.go | 66 +++++++------- .../testdata/scraper/expected_happy_path.yaml | 20 ++--- receiver/githubreceiver/metadata.yaml | 26 +++--- 5 files changed, 111 insertions(+), 111 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 49cb6b9954ac..392fb8c5e17d 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -26,7 +26,7 @@ The number of changes (pull requests) in a repository, categorized by their stat | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | ### vcs.repository.change.time_open @@ -41,7 +41,7 @@ The amount of time a change (pull request) has been open. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | ### vcs.repository.change.time_to_approval @@ -57,7 +57,7 @@ The amount of time it took a change (pull request) to go from open to approved. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | ### vcs.repository.change.time_to_merge @@ -73,7 +73,7 @@ The amount of time it took a change (pull request) to go from open to merged. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | ### vcs.repository.count @@ -97,7 +97,7 @@ The number of refs of type branch in a repository. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.lines_added @@ -113,7 +113,7 @@ The number of lines added in a ref (branch) relative to the default branch (trun | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -130,7 +130,7 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -147,7 +147,7 @@ The number of revisions (commits) a ref (branch) is ahead of the default branch | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -164,7 +164,7 @@ The number of revisions (commits) a ref (branch) is behind the default branch (t | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -181,7 +181,7 @@ Time a ref (branch) created from the default branch (trunk) has existed. The `re | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | | ref.name | The name of a VCS branch | Any Str | | ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | @@ -208,7 +208,7 @@ The number of unique contributors to a repository. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| repository.name | The name of a VCS repository | Any Str | +| vcs.repository.name | The name of a VCS repository. | Any Str | ## Resource Attributes diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 1ad836545d5c..d444c44c3b54 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -80,7 +80,7 @@ func (m *metricVcsRepositoryChangeCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue string, repositoryNameAttributeValue string) { +func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -90,7 +90,7 @@ func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("change.state", changeStateAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -133,7 +133,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -142,7 +142,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timest dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -186,7 +186,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -195,7 +195,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon. dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -239,7 +239,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { if !m.config.Enabled { return } @@ -248,7 +248,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Tim dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) } @@ -292,7 +292,7 @@ func (m *metricVcsRepositoryContributorCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string) { +func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -301,7 +301,7 @@ func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Time dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -393,7 +393,7 @@ func (m *metricVcsRepositoryRefCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -402,7 +402,7 @@ func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, t dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -446,7 +446,7 @@ func (m *metricVcsRepositoryRefLinesAdded) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -455,7 +455,7 @@ func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timesta dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -500,7 +500,7 @@ func (m *metricVcsRepositoryRefLinesDeleted) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -509,7 +509,7 @@ func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Times dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -554,7 +554,7 @@ func (m *metricVcsRepositoryRefRevisionsAhead) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -563,7 +563,7 @@ func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Tim dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -608,7 +608,7 @@ func (m *metricVcsRepositoryRefRevisionsBehind) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -617,7 +617,7 @@ func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Ti dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -662,7 +662,7 @@ func (m *metricVcsRepositoryRefTime) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { if !m.config.Enabled { return } @@ -671,7 +671,7 @@ func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("ref.name", refNameAttributeValue) dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } @@ -890,28 +890,28 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics } // RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue AttributeChangeState, repositoryNameAttributeValue string) { - mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, changeStateAttributeValue.String(), repositoryNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue AttributeChangeState, vcsRepositoryNameAttributeValue string) { + mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, changeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) } // RecordVcsRepositoryChangeTimeOpenDataPoint adds a data point to vcs.repository.change.time_open metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryChangeTimeToApprovalDataPoint adds a data point to vcs.repository.change.time_to_approval metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryChangeTimeToMergeDataPoint adds a data point to vcs.repository.change.time_to_merge metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) } // RecordVcsRepositoryContributorCountDataPoint adds a data point to vcs.repository.contributor.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string) { - mb.metricVcsRepositoryContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { + mb.metricVcsRepositoryContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue) } // RecordVcsRepositoryCountDataPoint adds a data point to vcs.repository.count metric. @@ -920,33 +920,33 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp } // RecordVcsRepositoryRefCountDataPoint adds a data point to vcs.repository.ref.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesAddedDataPoint adds a data point to vcs.repository.ref.lines_added metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesDeletedDataPoint adds a data point to vcs.repository.ref.lines_deleted metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsAheadDataPoint adds a data point to vcs.repository.ref.revisions_ahead metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsBehindDataPoint adds a data point to vcs.repository.ref.revisions_behind metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // RecordVcsRepositoryRefTimeDataPoint adds a data point to vcs.repository.ref.time metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, repositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { + mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 11f42c13dc3d..d48c1f597cab 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -70,22 +70,22 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeChangeStateOpen, "repository.name-val") + mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeChangeStateOpen, "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") allMetricsCount++ - mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val") + mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ @@ -93,27 +93,27 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") @@ -158,9 +158,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("change.state") assert.True(t, ok) assert.EqualValues(t, "open", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) case "vcs.repository.change.time_open": assert.False(t, validatedMetrics["vcs.repository.change.time_open"], "Found a duplicate in the metrics slice: vcs.repository.change.time_open") validatedMetrics["vcs.repository.change.time_open"] = true @@ -176,9 +176,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -197,9 +197,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -218,9 +218,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -239,9 +239,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) case "vcs.repository.count": assert.False(t, validatedMetrics["vcs.repository.count"], "Found a duplicate in the metrics slice: vcs.repository.count") validatedMetrics["vcs.repository.count"] = true @@ -269,9 +269,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) @@ -290,9 +290,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -314,9 +314,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -338,9 +338,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -362,9 +362,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) @@ -386,9 +386,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("repository.name") + attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) attrVal, ok = dp.Attributes().Get("ref.name") assert.True(t, ok) assert.EqualValues(t, "ref.name-val", attrVal.Str()) diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 28ed9a825358..730c0c79aa4a 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -18,7 +18,7 @@ resourceMetrics: - key: change.state value: stringValue: merged - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 - key: vcs.repository.url.full @@ -31,7 +31,7 @@ resourceMetrics: - key: change.state value: stringValue: open - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 - key: vcs.repository.url.full @@ -49,7 +49,7 @@ resourceMetrics: - key: ref.name value: stringValue: "" - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 - key: vcs.repository.url.full @@ -67,7 +67,7 @@ resourceMetrics: - key: ref.name value: stringValue: "" - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 - key: vcs.repository.url.full @@ -93,7 +93,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 - key: vcs.repository.url.full @@ -114,7 +114,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: "" - key: vcs.repository.url.full @@ -135,7 +135,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: "" - key: vcs.repository.url.full @@ -156,7 +156,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: "" - key: vcs.repository.url.full @@ -177,7 +177,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: "" - key: vcs.repository.url.full @@ -198,7 +198,7 @@ resourceMetrics: - key: ref.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: "" - key: vcs.repository.url.full diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index aae565fdd7f9..5d0a8695b9d4 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -24,8 +24,8 @@ attributes: vcs.repository.url.full: description: The canonical URL of the repository providing the complete HTTPS address. type: string - repository.name: - description: The name of a VCS repository + vcs.repository.name: + description: The name of a VCS repository. type: string ref.name: description: The name of a VCS branch @@ -57,77 +57,77 @@ metrics: unit: "{ref}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.type] vcs.repository.ref.time: enabled: true description: Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] vcs.repository.ref.revisions_ahead: enabled: true description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] vcs.repository.ref.revisions_behind: enabled: true description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] vcs.repository.ref.lines_added: enabled: true description: The number of lines added in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] vcs.repository.ref.lines_deleted: enabled: true description: The number of lines deleted in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] vcs.repository.contributor.count: enabled: false description: The number of unique contributors to a repository. unit: "{contributor}" gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name] + attributes: [vcs.repository.url.full, vcs.repository.name] vcs.repository.change.time_open: enabled: true description: The amount of time a change (pull request) has been open. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] vcs.repository.change.time_to_merge: enabled: true description: The amount of time it took a change (pull request) to go from open to merged. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] vcs.repository.change.time_to_approval: enabled: true description: The amount of time it took a change (pull request) to go from open to approved. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] vcs.repository.change.count: description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). enabled: true gauge: value_type: int unit: "{change}" - attributes: [vcs.repository.url.full, change.state, repository.name] + attributes: [vcs.repository.url.full, change.state, vcs.repository.name] tests: config: From 0ff433fa4bb41533534e208373f99d8a831f83c8 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 21:44:47 -0500 Subject: [PATCH 03/18] [receiver/github] update ref.name and ref.type to match semconv * `ref.name` becomes `vcs.ref.head.name` * `ref.type` becomes `vcs.ref.head.type` --- receiver/githubreceiver/documentation.md | 52 ++++----- .../internal/metadata/generated_metrics.go | 110 +++++++++--------- .../metadata/generated_metrics_test.go | 64 +++++----- .../scraper/githubscraper/github_scraper.go | 2 +- .../testdata/scraper/expected_happy_path.yaml | 28 ++--- receiver/githubreceiver/metadata.yaml | 30 ++--- 6 files changed, 143 insertions(+), 143 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 392fb8c5e17d..7d9df7944a73 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -26,7 +26,7 @@ The number of changes (pull requests) in a repository, categorized by their stat | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | -| vcs.repository.name | The name of a VCS repository. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | ### vcs.repository.change.time_open @@ -41,8 +41,8 @@ The amount of time a change (pull request) has been open. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | ### vcs.repository.change.time_to_approval @@ -57,8 +57,8 @@ The amount of time it took a change (pull request) to go from open to approved. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | ### vcs.repository.change.time_to_merge @@ -73,8 +73,8 @@ The amount of time it took a change (pull request) to go from open to merged. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | ### vcs.repository.count @@ -97,8 +97,8 @@ The number of refs of type branch in a repository. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.lines_added @@ -113,9 +113,9 @@ The number of lines added in a ref (branch) relative to the default branch (trun | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.lines_deleted @@ -130,9 +130,9 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.revisions_ahead @@ -147,9 +147,9 @@ The number of revisions (commits) a ref (branch) is ahead of the default branch | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.revisions_behind @@ -164,13 +164,13 @@ The number of revisions (commits) a ref (branch) is behind the default branch (t | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.ref.time -Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. +Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -181,9 +181,9 @@ Time a ref (branch) created from the default branch (trunk) has existed. The `re | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | -| ref.name | The name of a VCS branch | Any Str | -| ref.type | The type of ref (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ## Optional Metrics @@ -208,7 +208,7 @@ The number of unique contributors to a repository. | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of a VCS repository. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | ## Resource Attributes diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index d444c44c3b54..cdb8714005b6 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -39,30 +39,30 @@ var MapAttributeChangeState = map[string]AttributeChangeState{ "merged": AttributeChangeStateMerged, } -// AttributeRefType specifies the a value ref.type attribute. -type AttributeRefType int +// AttributeVcsRefHeadType specifies the a value vcs.ref.head.type attribute. +type AttributeVcsRefHeadType int const ( - _ AttributeRefType = iota - AttributeRefTypeBranch - AttributeRefTypeTag + _ AttributeVcsRefHeadType = iota + AttributeVcsRefHeadTypeBranch + AttributeVcsRefHeadTypeTag ) -// String returns the string representation of the AttributeRefType. -func (av AttributeRefType) String() string { +// String returns the string representation of the AttributeVcsRefHeadType. +func (av AttributeVcsRefHeadType) String() string { switch av { - case AttributeRefTypeBranch: + case AttributeVcsRefHeadTypeBranch: return "branch" - case AttributeRefTypeTag: + case AttributeVcsRefHeadTypeTag: return "tag" } return "" } -// MapAttributeRefType is a helper map of string to AttributeRefType attribute value. -var MapAttributeRefType = map[string]AttributeRefType{ - "branch": AttributeRefTypeBranch, - "tag": AttributeRefTypeTag, +// MapAttributeVcsRefHeadType is a helper map of string to AttributeVcsRefHeadType attribute value. +var MapAttributeVcsRefHeadType = map[string]AttributeVcsRefHeadType{ + "branch": AttributeVcsRefHeadTypeBranch, + "tag": AttributeVcsRefHeadTypeTag, } type metricVcsRepositoryChangeCount struct { @@ -133,7 +133,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -143,7 +143,7 @@ func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timest dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -186,7 +186,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -196,7 +196,7 @@ func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon. dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -239,7 +239,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -249,7 +249,7 @@ func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Tim dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -393,7 +393,7 @@ func (m *metricVcsRepositoryRefCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -403,7 +403,7 @@ func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, t dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -446,7 +446,7 @@ func (m *metricVcsRepositoryRefLinesAdded) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -456,8 +456,8 @@ func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timesta dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -500,7 +500,7 @@ func (m *metricVcsRepositoryRefLinesDeleted) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -510,8 +510,8 @@ func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Times dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -554,7 +554,7 @@ func (m *metricVcsRepositoryRefRevisionsAhead) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -564,8 +564,8 @@ func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Tim dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -608,7 +608,7 @@ func (m *metricVcsRepositoryRefRevisionsBehind) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -618,8 +618,8 @@ func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Ti dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -656,13 +656,13 @@ type metricVcsRepositoryRefTime struct { // init fills vcs.repository.ref.time metric with initial data. func (m *metricVcsRepositoryRefTime) init() { m.data.SetName("vcs.repository.ref.time") - m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`.") + m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.") m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -672,8 +672,8 @@ func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -895,18 +895,18 @@ func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Tim } // RecordVcsRepositoryChangeTimeOpenDataPoint adds a data point to vcs.repository.change.time_open metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) } // RecordVcsRepositoryChangeTimeToApprovalDataPoint adds a data point to vcs.repository.change.time_to_approval metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) } // RecordVcsRepositoryChangeTimeToMergeDataPoint adds a data point to vcs.repository.change.time_to_merge metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { + mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) } // RecordVcsRepositoryContributorCountDataPoint adds a data point to vcs.repository.contributor.count metric. @@ -920,33 +920,33 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp } // RecordVcsRepositoryRefCountDataPoint adds a data point to vcs.repository.ref.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesAddedDataPoint adds a data point to vcs.repository.ref.lines_added metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // RecordVcsRepositoryRefLinesDeletedDataPoint adds a data point to vcs.repository.ref.lines_deleted metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsAheadDataPoint adds a data point to vcs.repository.ref.revisions_ahead metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // RecordVcsRepositoryRefRevisionsBehindDataPoint adds a data point to vcs.repository.ref.revisions_behind metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // RecordVcsRepositoryRefTimeDataPoint adds a data point to vcs.repository.ref.time metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue AttributeRefType) { - mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, refNameAttributeValue, refTypeAttributeValue.String()) +func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index d48c1f597cab..80e9e424df69 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -74,15 +74,15 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val") + mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") allMetricsCount++ mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") @@ -93,27 +93,27 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") @@ -179,9 +179,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) case "vcs.repository.change.time_to_approval": assert.False(t, validatedMetrics["vcs.repository.change.time_to_approval"], "Found a duplicate in the metrics slice: vcs.repository.change.time_to_approval") validatedMetrics["vcs.repository.change.time_to_approval"] = true @@ -200,9 +200,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) case "vcs.repository.change.time_to_merge": assert.False(t, validatedMetrics["vcs.repository.change.time_to_merge"], "Found a duplicate in the metrics slice: vcs.repository.change.time_to_merge") validatedMetrics["vcs.repository.change.time_to_merge"] = true @@ -221,9 +221,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) case "vcs.repository.contributor.count": assert.False(t, validatedMetrics["vcs.repository.contributor.count"], "Found a duplicate in the metrics slice: vcs.repository.contributor.count") validatedMetrics["vcs.repository.contributor.count"] = true @@ -272,7 +272,7 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.lines_added": @@ -293,10 +293,10 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.lines_deleted": @@ -317,10 +317,10 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.revisions_ahead": @@ -341,10 +341,10 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.revisions_behind": @@ -365,10 +365,10 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.time": @@ -376,7 +376,7 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics["vcs.repository.ref.time"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`.", ms.At(i).Description()) + assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.", 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()) @@ -389,10 +389,10 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) } diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 5b9fff9cdc35..61db5407f14c 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -121,7 +121,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { // SetStartTimestamp call from having a nil pointer panic mux.Lock() - refType := metadata.AttributeRefTypeBranch + refType := metadata.AttributeVcsRefHeadTypeBranch ghs.mb.RecordVcsRepositoryRefCountDataPoint(now, int64(count), url, name, refType) // Iterate through the refs (branches) populating the Branch focused diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 730c0c79aa4a..ae9f25a54a14 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -46,7 +46,7 @@ resourceMetrics: dataPoints: - asInt: "9223372036" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: "" - key: vcs.repository.name @@ -64,7 +64,7 @@ resourceMetrics: dataPoints: - asInt: "0" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: "" - key: vcs.repository.name @@ -90,7 +90,7 @@ resourceMetrics: dataPoints: - asInt: "1" attributes: - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name @@ -108,10 +108,10 @@ resourceMetrics: dataPoints: - asInt: "10" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name @@ -129,10 +129,10 @@ resourceMetrics: dataPoints: - asInt: "9" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name @@ -150,10 +150,10 @@ resourceMetrics: dataPoints: - asInt: "1" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name @@ -171,10 +171,10 @@ resourceMetrics: dataPoints: - asInt: "0" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name @@ -187,15 +187,15 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.ref.revisions_behind unit: '{revision}' - - description: Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. + - description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. gauge: dataPoints: - asInt: "86400" attributes: - - key: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - key: vcs.repository.name diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 5d0a8695b9d4..da97e5f49890 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -25,13 +25,13 @@ attributes: description: The canonical URL of the repository providing the complete HTTPS address. type: string vcs.repository.name: - description: The name of a VCS repository. + description: The name of the VCS repository. type: string - ref.name: - description: The name of a VCS branch + vcs.ref.head.name: + description: The name of the VCS head reference (branch). type: string - ref.type: - description: The type of ref (branch, tag). + vcs.ref.head.type: + description: The type of the head reference (branch, tag). type: string enum: - branch @@ -57,42 +57,42 @@ metrics: unit: "{ref}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.type] vcs.repository.ref.time: enabled: true - description: Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. + description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.revisions_ahead: enabled: true description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.revisions_behind: enabled: true description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). unit: "{revision}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.lines_added: enabled: true description: The number of lines added in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.lines_deleted: enabled: true description: The number of lines deleted in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name, ref.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.contributor.count: enabled: false description: The number of unique contributors to a repository. @@ -106,21 +106,21 @@ metrics: unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] vcs.repository.change.time_to_merge: enabled: true description: The amount of time it took a change (pull request) to go from open to merged. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] vcs.repository.change.time_to_approval: enabled: true description: The amount of time it took a change (pull request) to go from open to approved. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, ref.name] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] vcs.repository.change.count: description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). enabled: true From d26ad38c51083adce22fb818c53797c5c1d41f51 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 21:48:13 -0500 Subject: [PATCH 04/18] [receiver/github] update change.state to vcs.change.state --- receiver/githubreceiver/documentation.md | 2 +- .../internal/metadata/generated_metrics.go | 34 +++++++++---------- .../metadata/generated_metrics_test.go | 4 +-- .../scraper/githubscraper/github_scraper.go | 4 +-- .../testdata/scraper/expected_happy_path.yaml | 4 +-- receiver/githubreceiver/metadata.yaml | 4 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 7d9df7944a73..cae73c211943 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -25,7 +25,7 @@ The number of changes (pull requests) in a repository, categorized by their stat | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | +| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | | vcs.repository.name | The name of the VCS repository. | Any Str | ### vcs.repository.change.time_open diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index cdb8714005b6..c69468fe4161 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -13,30 +13,30 @@ import ( conventions "go.opentelemetry.io/collector/semconv/v1.27.0" ) -// AttributeChangeState specifies the a value change.state attribute. -type AttributeChangeState int +// AttributeVcsChangeState specifies the a value vcs.change.state attribute. +type AttributeVcsChangeState int const ( - _ AttributeChangeState = iota - AttributeChangeStateOpen - AttributeChangeStateMerged + _ AttributeVcsChangeState = iota + AttributeVcsChangeStateOpen + AttributeVcsChangeStateMerged ) -// String returns the string representation of the AttributeChangeState. -func (av AttributeChangeState) String() string { +// String returns the string representation of the AttributeVcsChangeState. +func (av AttributeVcsChangeState) String() string { switch av { - case AttributeChangeStateOpen: + case AttributeVcsChangeStateOpen: return "open" - case AttributeChangeStateMerged: + case AttributeVcsChangeStateMerged: return "merged" } return "" } -// MapAttributeChangeState is a helper map of string to AttributeChangeState attribute value. -var MapAttributeChangeState = map[string]AttributeChangeState{ - "open": AttributeChangeStateOpen, - "merged": AttributeChangeStateMerged, +// MapAttributeVcsChangeState is a helper map of string to AttributeVcsChangeState attribute value. +var MapAttributeVcsChangeState = map[string]AttributeVcsChangeState{ + "open": AttributeVcsChangeStateOpen, + "merged": AttributeVcsChangeStateMerged, } // AttributeVcsRefHeadType specifies the a value vcs.ref.head.type attribute. @@ -80,7 +80,7 @@ func (m *metricVcsRepositoryChangeCount) init() { m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { +func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -89,7 +89,7 @@ func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("change.state", changeStateAttributeValue) + dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) } @@ -890,8 +890,8 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics } // RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, changeStateAttributeValue AttributeChangeState, vcsRepositoryNameAttributeValue string) { - mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, changeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) +func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState, vcsRepositoryNameAttributeValue string) { + mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) } // RecordVcsRepositoryChangeTimeOpenDataPoint adds a data point to vcs.repository.change.time_open metric. diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 80e9e424df69..bfec032567db 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -70,7 +70,7 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeChangeStateOpen, "vcs.repository.name-val") + mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ @@ -155,7 +155,7 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("change.state") + attrVal, ok = dp.Attributes().Get("vcs.change.state") assert.True(t, ok) assert.EqualValues(t, "open", attrVal.Str()) attrVal, ok = dp.Attributes().Get("vcs.repository.name") diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 61db5407f14c..f75d1f45f158 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -194,8 +194,8 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { } } - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(open), url, metadata.AttributeChangeStateOpen, name) - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(merged), url, metadata.AttributeChangeStateMerged, name) + ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(open), url, metadata.AttributeVcsChangeStateOpen, name) + ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(merged), url, metadata.AttributeVcsChangeStateMerged, name) mux.Unlock() }() } diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index ae9f25a54a14..3cfde81eb3da 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -15,7 +15,7 @@ resourceMetrics: dataPoints: - asInt: "1" attributes: - - key: change.state + - key: vcs.change.state value: stringValue: merged - key: vcs.repository.name @@ -28,7 +28,7 @@ resourceMetrics: timeUnixNano: "2000000" - asInt: "1" attributes: - - key: change.state + - key: vcs.change.state value: stringValue: open - key: vcs.repository.name diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index da97e5f49890..6102932f2648 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -36,7 +36,7 @@ attributes: enum: - branch - tag - change.state: + vcs.change.state: description: The state of a change (pull request) type: string enum: @@ -127,7 +127,7 @@ metrics: gauge: value_type: int unit: "{change}" - attributes: [vcs.repository.url.full, change.state, vcs.repository.name] + attributes: [vcs.repository.url.full, vcs.change.state, vcs.repository.name] tests: config: From 2e8b6593ce737a590bcfe2c60d4fbff1749f2544 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 22:06:25 -0500 Subject: [PATCH 05/18] [receiver/github] convert rev behind and rev ahead to rev delta --- receiver/githubreceiver/documentation.md | 52 ++--- .../internal/metadata/generated_config.go | 12 +- .../metadata/generated_config_test.go | 6 +- .../internal/metadata/generated_metrics.go | 213 ++++++++---------- .../metadata/generated_metrics_test.go | 87 +++---- .../internal/metadata/testdata/config.yaml | 12 +- .../scraper/githubscraper/github_scraper.go | 6 +- .../testdata/scraper/expected_happy_path.yaml | 85 +++---- receiver/githubreceiver/metadata.yaml | 26 ++- 9 files changed, 211 insertions(+), 288 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index cae73c211943..473d06914fa4 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -12,6 +12,24 @@ metrics: enabled: false ``` +### vcs.ref.revisions_delta + +The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {revision} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.revision_delta.direction | The type of revision comparison. | Str: ``ahead``, ``behind`` | + ### vcs.repository.change.count The number of changes (pull requests) in a repository, categorized by their state (either open or merged). @@ -134,40 +152,6 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | | vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -### vcs.repository.ref.revisions_ahead - -The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {revision} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - -### vcs.repository.ref.revisions_behind - -The number of revisions (commits) a ref (branch) is behind the default branch (trunk). - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {revision} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - ### vcs.repository.ref.time Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index d16a2a6316c2..183cb3726626 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -28,6 +28,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { + VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` VcsRepositoryChangeCount MetricConfig `mapstructure:"vcs.repository.change.count"` VcsRepositoryChangeTimeOpen MetricConfig `mapstructure:"vcs.repository.change.time_open"` VcsRepositoryChangeTimeToApproval MetricConfig `mapstructure:"vcs.repository.change.time_to_approval"` @@ -37,13 +38,14 @@ type MetricsConfig struct { VcsRepositoryRefCount MetricConfig `mapstructure:"vcs.repository.ref.count"` VcsRepositoryRefLinesAdded MetricConfig `mapstructure:"vcs.repository.ref.lines_added"` VcsRepositoryRefLinesDeleted MetricConfig `mapstructure:"vcs.repository.ref.lines_deleted"` - VcsRepositoryRefRevisionsAhead MetricConfig `mapstructure:"vcs.repository.ref.revisions_ahead"` - VcsRepositoryRefRevisionsBehind MetricConfig `mapstructure:"vcs.repository.ref.revisions_behind"` VcsRepositoryRefTime MetricConfig `mapstructure:"vcs.repository.ref.time"` } func DefaultMetricsConfig() MetricsConfig { return MetricsConfig{ + VcsRefRevisionsDelta: MetricConfig{ + Enabled: true, + }, VcsRepositoryChangeCount: MetricConfig{ Enabled: true, }, @@ -71,12 +73,6 @@ func DefaultMetricsConfig() MetricsConfig { VcsRepositoryRefLinesDeleted: MetricConfig{ Enabled: true, }, - VcsRepositoryRefRevisionsAhead: MetricConfig{ - Enabled: true, - }, - VcsRepositoryRefRevisionsBehind: MetricConfig{ - Enabled: true, - }, VcsRepositoryRefTime: MetricConfig{ Enabled: true, }, diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 4747288dcaea..75562a793867 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -25,6 +25,7 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsRefRevisionsDelta: MetricConfig{Enabled: true}, VcsRepositoryChangeCount: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: true}, @@ -34,8 +35,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryRefCount: MetricConfig{Enabled: true}, VcsRepositoryRefLinesAdded: MetricConfig{Enabled: true}, VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: true}, - VcsRepositoryRefRevisionsAhead: MetricConfig{Enabled: true}, - VcsRepositoryRefRevisionsBehind: MetricConfig{Enabled: true}, VcsRepositoryRefTime: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ @@ -48,6 +47,7 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsRefRevisionsDelta: MetricConfig{Enabled: false}, VcsRepositoryChangeCount: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: false}, @@ -57,8 +57,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryRefCount: MetricConfig{Enabled: false}, VcsRepositoryRefLinesAdded: MetricConfig{Enabled: false}, VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: false}, - VcsRepositoryRefRevisionsAhead: MetricConfig{Enabled: false}, - VcsRepositoryRefRevisionsBehind: MetricConfig{Enabled: false}, VcsRepositoryRefTime: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index c69468fe4161..b6a097e48295 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -65,6 +65,87 @@ var MapAttributeVcsRefHeadType = map[string]AttributeVcsRefHeadType{ "tag": AttributeVcsRefHeadTypeTag, } +// AttributeVcsRevisionDeltaDirection specifies the a value vcs.revision_delta.direction attribute. +type AttributeVcsRevisionDeltaDirection int + +const ( + _ AttributeVcsRevisionDeltaDirection = iota + AttributeVcsRevisionDeltaDirectionAhead + AttributeVcsRevisionDeltaDirectionBehind +) + +// String returns the string representation of the AttributeVcsRevisionDeltaDirection. +func (av AttributeVcsRevisionDeltaDirection) String() string { + switch av { + case AttributeVcsRevisionDeltaDirectionAhead: + return "ahead" + case AttributeVcsRevisionDeltaDirectionBehind: + return "behind" + } + return "" +} + +// MapAttributeVcsRevisionDeltaDirection is a helper map of string to AttributeVcsRevisionDeltaDirection attribute value. +var MapAttributeVcsRevisionDeltaDirection = map[string]AttributeVcsRevisionDeltaDirection{ + "ahead": AttributeVcsRevisionDeltaDirectionAhead, + "behind": AttributeVcsRevisionDeltaDirectionBehind, +} + +type metricVcsRefRevisionsDelta 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 vcs.ref.revisions_delta metric with initial data. +func (m *metricVcsRefRevisionsDelta) init() { + m.data.SetName("vcs.ref.revisions_delta") + m.data.SetDescription("The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).") + m.data.SetUnit("{revision}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricVcsRefRevisionsDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsRevisionDeltaDirectionAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) + dp.Attributes().PutStr("vcs.revision_delta.direction", vcsRevisionDeltaDirectionAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricVcsRefRevisionsDelta) 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 *metricVcsRefRevisionsDelta) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta { + m := metricVcsRefRevisionsDelta{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricVcsRepositoryChangeCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -539,114 +620,6 @@ func newMetricVcsRepositoryRefLinesDeleted(cfg MetricConfig) metricVcsRepository return m } -type metricVcsRepositoryRefRevisionsAhead 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 vcs.repository.ref.revisions_ahead metric with initial data. -func (m *metricVcsRepositoryRefRevisionsAhead) init() { - m.data.SetName("vcs.repository.ref.revisions_ahead") - m.data.SetDescription("The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk).") - m.data.SetUnit("{revision}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefRevisionsAhead) 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 *metricVcsRepositoryRefRevisionsAhead) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefRevisionsAhead(cfg MetricConfig) metricVcsRepositoryRefRevisionsAhead { - m := metricVcsRepositoryRefRevisionsAhead{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricVcsRepositoryRefRevisionsBehind 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 vcs.repository.ref.revisions_behind metric with initial data. -func (m *metricVcsRepositoryRefRevisionsBehind) init() { - m.data.SetName("vcs.repository.ref.revisions_behind") - m.data.SetDescription("The number of revisions (commits) a ref (branch) is behind the default branch (trunk).") - m.data.SetUnit("{revision}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefRevisionsBehind) 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 *metricVcsRepositoryRefRevisionsBehind) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefRevisionsBehind(cfg MetricConfig) metricVcsRepositoryRefRevisionsBehind { - m := metricVcsRepositoryRefRevisionsBehind{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - type metricVcsRepositoryRefTime struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -711,6 +684,7 @@ type MetricsBuilder struct { buildInfo component.BuildInfo // contains version information. resourceAttributeIncludeFilter map[string]filter.Filter resourceAttributeExcludeFilter map[string]filter.Filter + metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval @@ -720,8 +694,6 @@ type MetricsBuilder struct { metricVcsRepositoryRefCount metricVcsRepositoryRefCount metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesDeleted metricVcsRepositoryRefLinesDeleted - metricVcsRepositoryRefRevisionsAhead metricVcsRepositoryRefRevisionsAhead - metricVcsRepositoryRefRevisionsBehind metricVcsRepositoryRefRevisionsBehind metricVcsRepositoryRefTime metricVcsRepositoryRefTime } @@ -749,6 +721,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt startTime: pcommon.NewTimestampFromTime(time.Now()), metricsBuffer: pmetric.NewMetrics(), buildInfo: settings.BuildInfo, + metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), metricVcsRepositoryChangeCount: newMetricVcsRepositoryChangeCount(mbc.Metrics.VcsRepositoryChangeCount), metricVcsRepositoryChangeTimeOpen: newMetricVcsRepositoryChangeTimeOpen(mbc.Metrics.VcsRepositoryChangeTimeOpen), metricVcsRepositoryChangeTimeToApproval: newMetricVcsRepositoryChangeTimeToApproval(mbc.Metrics.VcsRepositoryChangeTimeToApproval), @@ -758,8 +731,6 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricVcsRepositoryRefCount: newMetricVcsRepositoryRefCount(mbc.Metrics.VcsRepositoryRefCount), metricVcsRepositoryRefLinesAdded: newMetricVcsRepositoryRefLinesAdded(mbc.Metrics.VcsRepositoryRefLinesAdded), metricVcsRepositoryRefLinesDeleted: newMetricVcsRepositoryRefLinesDeleted(mbc.Metrics.VcsRepositoryRefLinesDeleted), - metricVcsRepositoryRefRevisionsAhead: newMetricVcsRepositoryRefRevisionsAhead(mbc.Metrics.VcsRepositoryRefRevisionsAhead), - metricVcsRepositoryRefRevisionsBehind: newMetricVcsRepositoryRefRevisionsBehind(mbc.Metrics.VcsRepositoryRefRevisionsBehind), metricVcsRepositoryRefTime: newMetricVcsRepositoryRefTime(mbc.Metrics.VcsRepositoryRefTime), resourceAttributeIncludeFilter: make(map[string]filter.Filter), resourceAttributeExcludeFilter: make(map[string]filter.Filter), @@ -846,6 +817,7 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) + mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) mb.metricVcsRepositoryChangeCount.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeOpen.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToApproval.emit(ils.Metrics()) @@ -855,8 +827,6 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { mb.metricVcsRepositoryRefCount.emit(ils.Metrics()) mb.metricVcsRepositoryRefLinesAdded.emit(ils.Metrics()) mb.metricVcsRepositoryRefLinesDeleted.emit(ils.Metrics()) - mb.metricVcsRepositoryRefRevisionsAhead.emit(ils.Metrics()) - mb.metricVcsRepositoryRefRevisionsBehind.emit(ils.Metrics()) mb.metricVcsRepositoryRefTime.emit(ils.Metrics()) for _, op := range options { @@ -889,6 +859,11 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics return metrics } +// RecordVcsRefRevisionsDeltaDataPoint adds a data point to vcs.ref.revisions_delta metric. +func (mb *MetricsBuilder) RecordVcsRefRevisionsDeltaDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType, vcsRevisionDeltaDirectionAttributeValue AttributeVcsRevisionDeltaDirection) { + mb.metricVcsRefRevisionsDelta.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String(), vcsRevisionDeltaDirectionAttributeValue.String()) +} + // RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState, vcsRepositoryNameAttributeValue string) { mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) @@ -934,16 +909,6 @@ func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } -// RecordVcsRepositoryRefRevisionsAheadDataPoint adds a data point to vcs.repository.ref.revisions_ahead metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsAheadDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefRevisionsAhead.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - -// RecordVcsRepositoryRefRevisionsBehindDataPoint adds a data point to vcs.repository.ref.revisions_behind metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefRevisionsBehindDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefRevisionsBehind.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - // RecordVcsRepositoryRefTimeDataPoint adds a data point to vcs.repository.ref.time metric. func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index bfec032567db..bc431c734f5e 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -68,6 +68,10 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount := 0 allMetricsCount := 0 + defaultMetricsCount++ + allMetricsCount++ + mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) + defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") @@ -103,14 +107,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) @@ -140,6 +136,33 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { + case "vcs.ref.revisions_delta": + assert.False(t, validatedMetrics["vcs.ref.revisions_delta"], "Found a duplicate in the metrics slice: vcs.ref.revisions_delta") + validatedMetrics["vcs.ref.revisions_delta"] = 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 revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).", ms.At(i).Description()) + assert.Equal(t, "{revision}", 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("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.repository.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.revision_delta.direction") + assert.True(t, ok) + assert.EqualValues(t, "ahead", attrVal.Str()) case "vcs.repository.change.count": assert.False(t, validatedMetrics["vcs.repository.change.count"], "Found a duplicate in the metrics slice: vcs.repository.change.count") validatedMetrics["vcs.repository.change.count"] = true @@ -323,54 +346,6 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.repository.ref.revisions_ahead": - assert.False(t, validatedMetrics["vcs.repository.ref.revisions_ahead"], "Found a duplicate in the metrics slice: vcs.repository.ref.revisions_ahead") - validatedMetrics["vcs.repository.ref.revisions_ahead"] = 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 revisions (commits) a ref (branch) is ahead of the default branch (trunk).", ms.At(i).Description()) - assert.Equal(t, "{revision}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.repository.ref.revisions_behind": - assert.False(t, validatedMetrics["vcs.repository.ref.revisions_behind"], "Found a duplicate in the metrics slice: vcs.repository.ref.revisions_behind") - validatedMetrics["vcs.repository.ref.revisions_behind"] = 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 revisions (commits) a ref (branch) is behind the default branch (trunk).", ms.At(i).Description()) - assert.Equal(t, "{revision}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.time": assert.False(t, validatedMetrics["vcs.repository.ref.time"], "Found a duplicate in the metrics slice: vcs.repository.ref.time") validatedMetrics["vcs.repository.ref.time"] = true diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index 8dd9bc3c44a3..7ede8c76ef71 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -1,6 +1,8 @@ default: all_set: metrics: + vcs.ref.revisions_delta: + enabled: true vcs.repository.change.count: enabled: true vcs.repository.change.time_open: @@ -19,10 +21,6 @@ all_set: enabled: true vcs.repository.ref.lines_deleted: enabled: true - vcs.repository.ref.revisions_ahead: - enabled: true - vcs.repository.ref.revisions_behind: - enabled: true vcs.repository.ref.time: enabled: true resource_attributes: @@ -32,6 +30,8 @@ all_set: enabled: true none_set: metrics: + vcs.ref.revisions_delta: + enabled: false vcs.repository.change.count: enabled: false vcs.repository.change.time_open: @@ -50,10 +50,6 @@ none_set: enabled: false vcs.repository.ref.lines_deleted: enabled: false - vcs.repository.ref.revisions_ahead: - enabled: false - vcs.repository.ref.revisions_behind: - enabled: false vcs.repository.ref.time: enabled: false resource_attributes: diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index f75d1f45f158..b43cd9a56f9e 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -138,8 +138,10 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { // See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/githubreceiver/internal/scraper/githubscraper/README.md#github-limitations // for more information as to why `BehindBy` and `AheadBy` are // swapped. - ghs.mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType) + // ghs.mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType) + // ghs.mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRefRevisionsDeltaDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsRevisionDeltaDirectionAhead) + ghs.mb.RecordVcsRefRevisionsDeltaDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsRevisionDeltaDirectionBehind) var additions int var deletions int diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 3cfde81eb3da..8d5a68383fca 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -10,6 +10,49 @@ resourceMetrics: schemaUrl: https://opentelemetry.io/schemas/1.27.0 scopeMetrics: - metrics: + - description: The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). + gauge: + dataPoints: + - asInt: "1" + attributes: + - key: vcs.ref.head.name + value: + stringValue: main + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + - key: vcs.revision_delta.direction + value: + stringValue: ahead + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: vcs.ref.head.name + value: + stringValue: main + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + - key: vcs.revision_delta.direction + value: + stringValue: behind + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.ref.revisions_delta + unit: '{revision}' - description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). gauge: dataPoints: @@ -145,48 +188,6 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.ref.lines_deleted unit: '{line}' - - description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). - gauge: - dataPoints: - - asInt: "1" - attributes: - - key: vcs.ref.head.name - value: - stringValue: main - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: "" - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.revisions_ahead - unit: '{revision}' - - description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). - gauge: - dataPoints: - - asInt: "0" - attributes: - - key: vcs.ref.head.name - value: - stringValue: main - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: "" - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.revisions_behind - unit: '{revision}' - description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. gauge: dataPoints: diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 6102932f2648..e3e84d4cf6cf 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -42,6 +42,12 @@ attributes: enum: - open - merged + vcs.revision_delta.direction: + description: The type of revision comparison. + type: string + enum: + - ahead + - behind metrics: vcs.repository.count: @@ -65,20 +71,20 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] - vcs.repository.ref.revisions_ahead: - enabled: true - description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). - unit: "{revision}" - gauge: - value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] - vcs.repository.ref.revisions_behind: + vcs.ref.revisions_delta: enabled: true - description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). + description: The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). unit: "{revision}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.revision_delta.direction] + # vcs.repository.ref.revisions_behind: + # enabled: true + # description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). + # unit: "{revision}" + # gauge: + # value_type: int + # attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.lines_added: enabled: true description: The number of lines added in a ref (branch) relative to the default branch (trunk). From cd4b56f25815d3e97bd9697b8064a3ec6dd90cdc Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 22:09:44 -0500 Subject: [PATCH 06/18] [receiver/github] update ref.time and ref.count metric names --- receiver/githubreceiver/documentation.md | 66 ++--- .../internal/metadata/generated_config.go | 16 +- .../metadata/generated_config_test.go | 8 +- .../internal/metadata/generated_metrics.go | 246 +++++++++--------- .../metadata/generated_metrics_test.go | 106 ++++---- .../internal/metadata/testdata/config.yaml | 16 +- .../scraper/githubscraper/github_scraper.go | 4 +- .../testdata/scraper/expected_happy_path.yaml | 78 +++--- receiver/githubreceiver/metadata.yaml | 11 +- 9 files changed, 272 insertions(+), 279 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 473d06914fa4..1f476422b319 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -12,6 +12,22 @@ metrics: enabled: false ``` +### vcs.ref.count + +The number of refs of type branch in a repository. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {ref} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | + ### vcs.ref.revisions_delta The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). @@ -30,6 +46,23 @@ The number of revisions (commits) a ref (branch) is ahead/behind the branch from | vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | | vcs.revision_delta.direction | The type of revision comparison. | Str: ``ahead``, ``behind`` | +### vcs.ref.time + +Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| s | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | + ### vcs.repository.change.count The number of changes (pull requests) in a repository, categorized by their state (either open or merged). @@ -102,22 +135,6 @@ The number of repositories in an organization. | ---- | ----------- | ---------- | | {repository} | Gauge | Int | -### vcs.repository.ref.count - -The number of refs of type branch in a repository. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {ref} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - ### vcs.repository.ref.lines_added The number of lines added in a ref (branch) relative to the default branch (trunk). @@ -152,23 +169,6 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | | vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -### vcs.repository.ref.time - -Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| s | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - ## Optional Metrics The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration: diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index 183cb3726626..cd9ca2451b1e 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -28,24 +28,30 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { + VcsRefCount MetricConfig `mapstructure:"vcs.ref.count"` VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` + VcsRefTime MetricConfig `mapstructure:"vcs.ref.time"` VcsRepositoryChangeCount MetricConfig `mapstructure:"vcs.repository.change.count"` VcsRepositoryChangeTimeOpen MetricConfig `mapstructure:"vcs.repository.change.time_open"` VcsRepositoryChangeTimeToApproval MetricConfig `mapstructure:"vcs.repository.change.time_to_approval"` VcsRepositoryChangeTimeToMerge MetricConfig `mapstructure:"vcs.repository.change.time_to_merge"` VcsRepositoryContributorCount MetricConfig `mapstructure:"vcs.repository.contributor.count"` VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` - VcsRepositoryRefCount MetricConfig `mapstructure:"vcs.repository.ref.count"` VcsRepositoryRefLinesAdded MetricConfig `mapstructure:"vcs.repository.ref.lines_added"` VcsRepositoryRefLinesDeleted MetricConfig `mapstructure:"vcs.repository.ref.lines_deleted"` - VcsRepositoryRefTime MetricConfig `mapstructure:"vcs.repository.ref.time"` } func DefaultMetricsConfig() MetricsConfig { return MetricsConfig{ + VcsRefCount: MetricConfig{ + Enabled: true, + }, VcsRefRevisionsDelta: MetricConfig{ Enabled: true, }, + VcsRefTime: MetricConfig{ + Enabled: true, + }, VcsRepositoryChangeCount: MetricConfig{ Enabled: true, }, @@ -64,18 +70,12 @@ func DefaultMetricsConfig() MetricsConfig { VcsRepositoryCount: MetricConfig{ Enabled: true, }, - VcsRepositoryRefCount: MetricConfig{ - Enabled: true, - }, VcsRepositoryRefLinesAdded: MetricConfig{ Enabled: true, }, VcsRepositoryRefLinesDeleted: MetricConfig{ Enabled: true, }, - VcsRepositoryRefTime: MetricConfig{ - Enabled: true, - }, } } diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 75562a793867..0652e26f2db2 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -25,17 +25,17 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsRefCount: MetricConfig{Enabled: true}, VcsRefRevisionsDelta: MetricConfig{Enabled: true}, + VcsRefTime: MetricConfig{Enabled: true}, VcsRepositoryChangeCount: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: true}, VcsRepositoryContributorCount: MetricConfig{Enabled: true}, VcsRepositoryCount: MetricConfig{Enabled: true}, - VcsRepositoryRefCount: MetricConfig{Enabled: true}, VcsRepositoryRefLinesAdded: MetricConfig{Enabled: true}, VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: true}, - VcsRepositoryRefTime: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: true}, @@ -47,17 +47,17 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsRefCount: MetricConfig{Enabled: false}, VcsRefRevisionsDelta: MetricConfig{Enabled: false}, + VcsRefTime: MetricConfig{Enabled: false}, VcsRepositoryChangeCount: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: false}, VcsRepositoryContributorCount: MetricConfig{Enabled: false}, VcsRepositoryCount: MetricConfig{Enabled: false}, - VcsRepositoryRefCount: MetricConfig{Enabled: false}, VcsRepositoryRefLinesAdded: MetricConfig{Enabled: false}, VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: false}, - VcsRepositoryRefTime: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index b6a097e48295..1916a65e3040 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -91,6 +91,59 @@ var MapAttributeVcsRevisionDeltaDirection = map[string]AttributeVcsRevisionDelta "behind": AttributeVcsRevisionDeltaDirectionBehind, } +type metricVcsRefCount 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 vcs.ref.count metric with initial data. +func (m *metricVcsRefCount) init() { + m.data.SetName("vcs.ref.count") + m.data.SetDescription("The number of refs of type branch in a repository.") + m.data.SetUnit("{ref}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricVcsRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricVcsRefCount) 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 *metricVcsRefCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { + m := metricVcsRefCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricVcsRefRevisionsDelta struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -146,6 +199,60 @@ func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta return m } +type metricVcsRefTime 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 vcs.ref.time metric with initial data. +func (m *metricVcsRefTime) init() { + m.data.SetName("vcs.ref.time") + m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.") + m.data.SetUnit("s") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricVcsRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricVcsRefTime) 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 *metricVcsRefTime) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricVcsRefTime(cfg MetricConfig) metricVcsRefTime { + m := metricVcsRefTime{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricVcsRepositoryChangeCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -459,59 +566,6 @@ func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { return m } -type metricVcsRepositoryRefCount 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 vcs.repository.ref.count metric with initial data. -func (m *metricVcsRepositoryRefCount) init() { - m.data.SetName("vcs.repository.ref.count") - m.data.SetDescription("The number of refs of type branch in a repository.") - m.data.SetUnit("{ref}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefCount) 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 *metricVcsRepositoryRefCount) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefCount(cfg MetricConfig) metricVcsRepositoryRefCount { - m := metricVcsRepositoryRefCount{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - type metricVcsRepositoryRefLinesAdded struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -620,60 +674,6 @@ func newMetricVcsRepositoryRefLinesDeleted(cfg MetricConfig) metricVcsRepository return m } -type metricVcsRepositoryRefTime 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 vcs.repository.ref.time metric with initial data. -func (m *metricVcsRepositoryRefTime) init() { - m.data.SetName("vcs.repository.ref.time") - m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.") - m.data.SetUnit("s") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefTime) 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 *metricVcsRepositoryRefTime) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefTime(cfg MetricConfig) metricVcsRepositoryRefTime { - m := metricVcsRepositoryRefTime{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - // 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 { @@ -684,17 +684,17 @@ type MetricsBuilder struct { buildInfo component.BuildInfo // contains version information. resourceAttributeIncludeFilter map[string]filter.Filter resourceAttributeExcludeFilter map[string]filter.Filter + metricVcsRefCount metricVcsRefCount metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta + metricVcsRefTime metricVcsRefTime metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryContributorCount metricVcsRepositoryContributorCount metricVcsRepositoryCount metricVcsRepositoryCount - metricVcsRepositoryRefCount metricVcsRepositoryRefCount metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesDeleted metricVcsRepositoryRefLinesDeleted - metricVcsRepositoryRefTime metricVcsRepositoryRefTime } // MetricBuilderOption applies changes to default metrics builder. @@ -721,17 +721,17 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt startTime: pcommon.NewTimestampFromTime(time.Now()), metricsBuffer: pmetric.NewMetrics(), buildInfo: settings.BuildInfo, + metricVcsRefCount: newMetricVcsRefCount(mbc.Metrics.VcsRefCount), metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), + metricVcsRefTime: newMetricVcsRefTime(mbc.Metrics.VcsRefTime), metricVcsRepositoryChangeCount: newMetricVcsRepositoryChangeCount(mbc.Metrics.VcsRepositoryChangeCount), metricVcsRepositoryChangeTimeOpen: newMetricVcsRepositoryChangeTimeOpen(mbc.Metrics.VcsRepositoryChangeTimeOpen), metricVcsRepositoryChangeTimeToApproval: newMetricVcsRepositoryChangeTimeToApproval(mbc.Metrics.VcsRepositoryChangeTimeToApproval), metricVcsRepositoryChangeTimeToMerge: newMetricVcsRepositoryChangeTimeToMerge(mbc.Metrics.VcsRepositoryChangeTimeToMerge), metricVcsRepositoryContributorCount: newMetricVcsRepositoryContributorCount(mbc.Metrics.VcsRepositoryContributorCount), metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), - metricVcsRepositoryRefCount: newMetricVcsRepositoryRefCount(mbc.Metrics.VcsRepositoryRefCount), metricVcsRepositoryRefLinesAdded: newMetricVcsRepositoryRefLinesAdded(mbc.Metrics.VcsRepositoryRefLinesAdded), metricVcsRepositoryRefLinesDeleted: newMetricVcsRepositoryRefLinesDeleted(mbc.Metrics.VcsRepositoryRefLinesDeleted), - metricVcsRepositoryRefTime: newMetricVcsRepositoryRefTime(mbc.Metrics.VcsRepositoryRefTime), resourceAttributeIncludeFilter: make(map[string]filter.Filter), resourceAttributeExcludeFilter: make(map[string]filter.Filter), } @@ -817,17 +817,17 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) + mb.metricVcsRefCount.emit(ils.Metrics()) mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) + mb.metricVcsRefTime.emit(ils.Metrics()) mb.metricVcsRepositoryChangeCount.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeOpen.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToApproval.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsRepositoryContributorCount.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) - mb.metricVcsRepositoryRefCount.emit(ils.Metrics()) mb.metricVcsRepositoryRefLinesAdded.emit(ils.Metrics()) mb.metricVcsRepositoryRefLinesDeleted.emit(ils.Metrics()) - mb.metricVcsRepositoryRefTime.emit(ils.Metrics()) for _, op := range options { op.apply(rm) @@ -859,11 +859,21 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics return metrics } +// RecordVcsRefCountDataPoint adds a data point to vcs.ref.count metric. +func (mb *MetricsBuilder) RecordVcsRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) +} + // RecordVcsRefRevisionsDeltaDataPoint adds a data point to vcs.ref.revisions_delta metric. func (mb *MetricsBuilder) RecordVcsRefRevisionsDeltaDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType, vcsRevisionDeltaDirectionAttributeValue AttributeVcsRevisionDeltaDirection) { mb.metricVcsRefRevisionsDelta.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String(), vcsRevisionDeltaDirectionAttributeValue.String()) } +// RecordVcsRefTimeDataPoint adds a data point to vcs.ref.time metric. +func (mb *MetricsBuilder) RecordVcsRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { + mb.metricVcsRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) +} + // RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState, vcsRepositoryNameAttributeValue string) { mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) @@ -894,11 +904,6 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp mb.metricVcsRepositoryCount.recordDataPoint(mb.startTime, ts, val) } -// RecordVcsRepositoryRefCountDataPoint adds a data point to vcs.repository.ref.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - // RecordVcsRepositoryRefLinesAddedDataPoint adds a data point to vcs.repository.ref.lines_added metric. func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) @@ -909,11 +914,6 @@ func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } -// RecordVcsRepositoryRefTimeDataPoint adds a data point to vcs.repository.ref.time metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefTimeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, // and metrics builder should update its startTime and reset it's internal state accordingly. func (mb *MetricsBuilder) Reset(options ...MetricBuilderOption) { diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index bc431c734f5e..2ed480c81c86 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -68,10 +68,18 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount := 0 allMetricsCount := 0 + defaultMetricsCount++ + allMetricsCount++ + mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) + defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) + defaultMetricsCount++ + allMetricsCount++ + mb.RecordVcsRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) + defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") @@ -95,10 +103,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRepositoryCountDataPoint(ts, 1) - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) - defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) @@ -107,10 +111,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") rb.SetVcsVendorName("vcs.vendor.name-val") @@ -136,6 +136,27 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { + case "vcs.ref.count": + assert.False(t, validatedMetrics["vcs.ref.count"], "Found a duplicate in the metrics slice: vcs.ref.count") + validatedMetrics["vcs.ref.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 refs of type branch in a repository.", ms.At(i).Description()) + assert.Equal(t, "{ref}", 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("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.repository.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.ref.revisions_delta": assert.False(t, validatedMetrics["vcs.ref.revisions_delta"], "Found a duplicate in the metrics slice: vcs.ref.revisions_delta") validatedMetrics["vcs.ref.revisions_delta"] = true @@ -163,6 +184,30 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.revision_delta.direction") assert.True(t, ok) assert.EqualValues(t, "ahead", attrVal.Str()) + case "vcs.ref.time": + assert.False(t, validatedMetrics["vcs.ref.time"], "Found a duplicate in the metrics slice: vcs.ref.time") + validatedMetrics["vcs.ref.time"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.", 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("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.repository.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.change.count": assert.False(t, validatedMetrics["vcs.repository.change.count"], "Found a duplicate in the metrics slice: vcs.repository.change.count") validatedMetrics["vcs.repository.change.count"] = true @@ -277,27 +322,6 @@ 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 "vcs.repository.ref.count": - assert.False(t, validatedMetrics["vcs.repository.ref.count"], "Found a duplicate in the metrics slice: vcs.repository.ref.count") - validatedMetrics["vcs.repository.ref.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 refs of type branch in a repository.", ms.At(i).Description()) - assert.Equal(t, "{ref}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.ref.lines_added": assert.False(t, validatedMetrics["vcs.repository.ref.lines_added"], "Found a duplicate in the metrics slice: vcs.repository.ref.lines_added") validatedMetrics["vcs.repository.ref.lines_added"] = true @@ -346,30 +370,6 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.repository.ref.time": - assert.False(t, validatedMetrics["vcs.repository.ref.time"], "Found a duplicate in the metrics slice: vcs.repository.ref.time") - validatedMetrics["vcs.repository.ref.time"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) } } }) diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index 7ede8c76ef71..a804b6d3fdee 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -1,8 +1,12 @@ default: all_set: metrics: + vcs.ref.count: + enabled: true vcs.ref.revisions_delta: enabled: true + vcs.ref.time: + enabled: true vcs.repository.change.count: enabled: true vcs.repository.change.time_open: @@ -15,14 +19,10 @@ all_set: enabled: true vcs.repository.count: enabled: true - vcs.repository.ref.count: - enabled: true vcs.repository.ref.lines_added: enabled: true vcs.repository.ref.lines_deleted: enabled: true - vcs.repository.ref.time: - enabled: true resource_attributes: organization.name: enabled: true @@ -30,8 +30,12 @@ all_set: enabled: true none_set: metrics: + vcs.ref.count: + enabled: false vcs.ref.revisions_delta: enabled: false + vcs.ref.time: + enabled: false vcs.repository.change.count: enabled: false vcs.repository.change.time_open: @@ -44,14 +48,10 @@ none_set: enabled: false vcs.repository.count: enabled: false - vcs.repository.ref.count: - enabled: false vcs.repository.ref.lines_added: enabled: false vcs.repository.ref.lines_deleted: enabled: false - vcs.repository.ref.time: - enabled: false resource_attributes: organization.name: enabled: false diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index b43cd9a56f9e..306741f77f17 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -122,7 +122,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { mux.Lock() refType := metadata.AttributeVcsRefHeadTypeBranch - ghs.mb.RecordVcsRepositoryRefCountDataPoint(now, int64(count), url, name, refType) + ghs.mb.RecordVcsRefCountDataPoint(now, int64(count), url, name, refType) // Iterate through the refs (branches) populating the Branch focused // metrics @@ -153,7 +153,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { continue } - ghs.mb.RecordVcsRepositoryRefTimeDataPoint(now, age, url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRefTimeDataPoint(now, age, url, branch.Repository.Name, branch.Name, refType) ghs.mb.RecordVcsRepositoryRefLinesAddedDataPoint(now, int64(additions), url, branch.Repository.Name, branch.Name, refType) ghs.mb.RecordVcsRepositoryRefLinesDeletedDataPoint(now, int64(deletions), url, branch.Repository.Name, branch.Name, refType) } diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 8d5a68383fca..e72aea6e9427 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -10,6 +10,24 @@ resourceMetrics: schemaUrl: https://opentelemetry.io/schemas/1.27.0 scopeMetrics: - metrics: + - description: The number of refs of type branch in a repository. + gauge: + dataPoints: + - asInt: "1" + attributes: + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.ref.count + unit: '{ref}' - description: The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). gauge: dataPoints: @@ -53,6 +71,27 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.ref.revisions_delta unit: '{revision}' + - description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. + gauge: + dataPoints: + - asInt: "86400" + attributes: + - key: vcs.ref.head.name + value: + stringValue: main + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.ref.time + unit: s - description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). gauge: dataPoints: @@ -128,24 +167,6 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.count unit: '{repository}' - - description: The number of refs of type branch in a repository. - gauge: - dataPoints: - - asInt: "1" - attributes: - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: repo1 - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.count - unit: '{ref}' - description: The number of lines added in a ref (branch) relative to the default branch (trunk). gauge: dataPoints: @@ -188,27 +209,6 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.ref.lines_deleted unit: '{line}' - - description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. - gauge: - dataPoints: - - asInt: "86400" - attributes: - - key: vcs.ref.head.name - value: - stringValue: main - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: "" - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.time - unit: s scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver version: latest diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index e3e84d4cf6cf..8fe6c65a57ab 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -57,14 +57,14 @@ metrics: gauge: value_type: int attributes: [] - vcs.repository.ref.count: + vcs.ref.count: enabled: true description: The number of refs of type branch in a repository. unit: "{ref}" gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.type] - vcs.repository.ref.time: + vcs.ref.time: enabled: true description: Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. unit: s @@ -78,13 +78,6 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.revision_delta.direction] - # vcs.repository.ref.revisions_behind: - # enabled: true - # description: The number of revisions (commits) a ref (branch) is behind the default branch (trunk). - # unit: "{revision}" - # gauge: - # value_type: int - # attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] vcs.repository.ref.lines_added: enabled: true description: The number of lines added in a ref (branch) relative to the default branch (trunk). From 2aaba530825116226d5ead1db40c18ecd253a290 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 22:28:45 -0500 Subject: [PATCH 07/18] [receiver/github] convert lines added and removed to lines_delta --- receiver/githubreceiver/documentation.md | 52 ++--- .../internal/metadata/generated_config.go | 12 +- .../metadata/generated_config_test.go | 6 +- .../internal/metadata/generated_metrics.go | 213 ++++++++---------- .../metadata/generated_metrics_test.go | 87 +++---- .../internal/metadata/testdata/config.yaml | 12 +- .../scraper/githubscraper/github_scraper.go | 4 +- .../testdata/scraper/expected_happy_path.yaml | 85 +++---- receiver/githubreceiver/metadata.yaml | 19 +- 9 files changed, 202 insertions(+), 288 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 1f476422b319..58d23847bf5c 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -28,6 +28,24 @@ The number of refs of type branch in a repository. | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | +### vcs.ref.lines_delta + +The number of lines added/removed in a ref (branch) relative to the default branch (trunk). + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {line} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | +| vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.line_change.type | The type of line change being measured on a ref (branch). | Str: ``added``, ``removed`` | + ### vcs.ref.revisions_delta The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). @@ -135,40 +153,6 @@ The number of repositories in an organization. | ---- | ----------- | ---------- | | {repository} | Gauge | Int | -### vcs.repository.ref.lines_added - -The number of lines added in a ref (branch) relative to the default branch (trunk). - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {line} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - -### vcs.repository.ref.lines_deleted - -The number of lines deleted in a ref (branch) relative to the default branch (trunk). - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {line} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | - ## Optional Metrics The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration: diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index cd9ca2451b1e..6bfc34d680dc 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -29,6 +29,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { VcsRefCount MetricConfig `mapstructure:"vcs.ref.count"` + VcsRefLinesDelta MetricConfig `mapstructure:"vcs.ref.lines_delta"` VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` VcsRefTime MetricConfig `mapstructure:"vcs.ref.time"` VcsRepositoryChangeCount MetricConfig `mapstructure:"vcs.repository.change.count"` @@ -37,8 +38,6 @@ type MetricsConfig struct { VcsRepositoryChangeTimeToMerge MetricConfig `mapstructure:"vcs.repository.change.time_to_merge"` VcsRepositoryContributorCount MetricConfig `mapstructure:"vcs.repository.contributor.count"` VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` - VcsRepositoryRefLinesAdded MetricConfig `mapstructure:"vcs.repository.ref.lines_added"` - VcsRepositoryRefLinesDeleted MetricConfig `mapstructure:"vcs.repository.ref.lines_deleted"` } func DefaultMetricsConfig() MetricsConfig { @@ -46,6 +45,9 @@ func DefaultMetricsConfig() MetricsConfig { VcsRefCount: MetricConfig{ Enabled: true, }, + VcsRefLinesDelta: MetricConfig{ + Enabled: true, + }, VcsRefRevisionsDelta: MetricConfig{ Enabled: true, }, @@ -70,12 +72,6 @@ func DefaultMetricsConfig() MetricsConfig { VcsRepositoryCount: MetricConfig{ Enabled: true, }, - VcsRepositoryRefLinesAdded: MetricConfig{ - Enabled: true, - }, - VcsRepositoryRefLinesDeleted: MetricConfig{ - Enabled: true, - }, } } diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 0652e26f2db2..b8f9d0e5e3b4 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -26,6 +26,7 @@ func TestMetricsBuilderConfig(t *testing.T) { want: MetricsBuilderConfig{ Metrics: MetricsConfig{ VcsRefCount: MetricConfig{Enabled: true}, + VcsRefLinesDelta: MetricConfig{Enabled: true}, VcsRefRevisionsDelta: MetricConfig{Enabled: true}, VcsRefTime: MetricConfig{Enabled: true}, VcsRepositoryChangeCount: MetricConfig{Enabled: true}, @@ -34,8 +35,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: true}, VcsRepositoryContributorCount: MetricConfig{Enabled: true}, VcsRepositoryCount: MetricConfig{Enabled: true}, - VcsRepositoryRefLinesAdded: MetricConfig{Enabled: true}, - VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: true}, @@ -48,6 +47,7 @@ func TestMetricsBuilderConfig(t *testing.T) { want: MetricsBuilderConfig{ Metrics: MetricsConfig{ VcsRefCount: MetricConfig{Enabled: false}, + VcsRefLinesDelta: MetricConfig{Enabled: false}, VcsRefRevisionsDelta: MetricConfig{Enabled: false}, VcsRefTime: MetricConfig{Enabled: false}, VcsRepositoryChangeCount: MetricConfig{Enabled: false}, @@ -56,8 +56,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: false}, VcsRepositoryContributorCount: MetricConfig{Enabled: false}, VcsRepositoryCount: MetricConfig{Enabled: false}, - VcsRepositoryRefLinesAdded: MetricConfig{Enabled: false}, - VcsRepositoryRefLinesDeleted: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 1916a65e3040..045f42a11f93 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -39,6 +39,32 @@ var MapAttributeVcsChangeState = map[string]AttributeVcsChangeState{ "merged": AttributeVcsChangeStateMerged, } +// AttributeVcsLineChangeType specifies the a value vcs.line_change.type attribute. +type AttributeVcsLineChangeType int + +const ( + _ AttributeVcsLineChangeType = iota + AttributeVcsLineChangeTypeAdded + AttributeVcsLineChangeTypeRemoved +) + +// String returns the string representation of the AttributeVcsLineChangeType. +func (av AttributeVcsLineChangeType) String() string { + switch av { + case AttributeVcsLineChangeTypeAdded: + return "added" + case AttributeVcsLineChangeTypeRemoved: + return "removed" + } + return "" +} + +// MapAttributeVcsLineChangeType is a helper map of string to AttributeVcsLineChangeType attribute value. +var MapAttributeVcsLineChangeType = map[string]AttributeVcsLineChangeType{ + "added": AttributeVcsLineChangeTypeAdded, + "removed": AttributeVcsLineChangeTypeRemoved, +} + // AttributeVcsRefHeadType specifies the a value vcs.ref.head.type attribute. type AttributeVcsRefHeadType int @@ -144,6 +170,61 @@ func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { return m } +type metricVcsRefLinesDelta 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 vcs.ref.lines_delta metric with initial data. +func (m *metricVcsRefLinesDelta) init() { + m.data.SetName("vcs.ref.lines_delta") + m.data.SetDescription("The number of lines added/removed in a ref (branch) relative to the default branch (trunk).") + m.data.SetUnit("{line}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricVcsRefLinesDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsLineChangeTypeAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) + dp.Attributes().PutStr("vcs.line_change.type", vcsLineChangeTypeAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricVcsRefLinesDelta) 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 *metricVcsRefLinesDelta) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricVcsRefLinesDelta(cfg MetricConfig) metricVcsRefLinesDelta { + m := metricVcsRefLinesDelta{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricVcsRefRevisionsDelta struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -566,114 +647,6 @@ func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { return m } -type metricVcsRepositoryRefLinesAdded 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 vcs.repository.ref.lines_added metric with initial data. -func (m *metricVcsRepositoryRefLinesAdded) init() { - m.data.SetName("vcs.repository.ref.lines_added") - m.data.SetDescription("The number of lines added in a ref (branch) relative to the default branch (trunk).") - m.data.SetUnit("{line}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefLinesAdded) 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 *metricVcsRepositoryRefLinesAdded) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefLinesAdded(cfg MetricConfig) metricVcsRepositoryRefLinesAdded { - m := metricVcsRepositoryRefLinesAdded{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricVcsRepositoryRefLinesDeleted 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 vcs.repository.ref.lines_deleted metric with initial data. -func (m *metricVcsRepositoryRefLinesDeleted) init() { - m.data.SetName("vcs.repository.ref.lines_deleted") - m.data.SetDescription("The number of lines deleted in a ref (branch) relative to the default branch (trunk).") - m.data.SetUnit("{line}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefLinesDeleted) 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 *metricVcsRepositoryRefLinesDeleted) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryRefLinesDeleted(cfg MetricConfig) metricVcsRepositoryRefLinesDeleted { - m := metricVcsRepositoryRefLinesDeleted{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - // 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 { @@ -685,6 +658,7 @@ type MetricsBuilder struct { resourceAttributeIncludeFilter map[string]filter.Filter resourceAttributeExcludeFilter map[string]filter.Filter metricVcsRefCount metricVcsRefCount + metricVcsRefLinesDelta metricVcsRefLinesDelta metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta metricVcsRefTime metricVcsRefTime metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount @@ -693,8 +667,6 @@ type MetricsBuilder struct { metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryContributorCount metricVcsRepositoryContributorCount metricVcsRepositoryCount metricVcsRepositoryCount - metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesAdded - metricVcsRepositoryRefLinesDeleted metricVcsRepositoryRefLinesDeleted } // MetricBuilderOption applies changes to default metrics builder. @@ -722,6 +694,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricsBuffer: pmetric.NewMetrics(), buildInfo: settings.BuildInfo, metricVcsRefCount: newMetricVcsRefCount(mbc.Metrics.VcsRefCount), + metricVcsRefLinesDelta: newMetricVcsRefLinesDelta(mbc.Metrics.VcsRefLinesDelta), metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), metricVcsRefTime: newMetricVcsRefTime(mbc.Metrics.VcsRefTime), metricVcsRepositoryChangeCount: newMetricVcsRepositoryChangeCount(mbc.Metrics.VcsRepositoryChangeCount), @@ -730,8 +703,6 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricVcsRepositoryChangeTimeToMerge: newMetricVcsRepositoryChangeTimeToMerge(mbc.Metrics.VcsRepositoryChangeTimeToMerge), metricVcsRepositoryContributorCount: newMetricVcsRepositoryContributorCount(mbc.Metrics.VcsRepositoryContributorCount), metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), - metricVcsRepositoryRefLinesAdded: newMetricVcsRepositoryRefLinesAdded(mbc.Metrics.VcsRepositoryRefLinesAdded), - metricVcsRepositoryRefLinesDeleted: newMetricVcsRepositoryRefLinesDeleted(mbc.Metrics.VcsRepositoryRefLinesDeleted), resourceAttributeIncludeFilter: make(map[string]filter.Filter), resourceAttributeExcludeFilter: make(map[string]filter.Filter), } @@ -818,6 +789,7 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricVcsRefCount.emit(ils.Metrics()) + mb.metricVcsRefLinesDelta.emit(ils.Metrics()) mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) mb.metricVcsRefTime.emit(ils.Metrics()) mb.metricVcsRepositoryChangeCount.emit(ils.Metrics()) @@ -826,8 +798,6 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsRepositoryContributorCount.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) - mb.metricVcsRepositoryRefLinesAdded.emit(ils.Metrics()) - mb.metricVcsRepositoryRefLinesDeleted.emit(ils.Metrics()) for _, op := range options { op.apply(rm) @@ -864,6 +834,11 @@ func (mb *MetricsBuilder) RecordVcsRefCountDataPoint(ts pcommon.Timestamp, val i mb.metricVcsRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } +// RecordVcsRefLinesDeltaDataPoint adds a data point to vcs.ref.lines_delta metric. +func (mb *MetricsBuilder) RecordVcsRefLinesDeltaDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType, vcsLineChangeTypeAttributeValue AttributeVcsLineChangeType) { + mb.metricVcsRefLinesDelta.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String(), vcsLineChangeTypeAttributeValue.String()) +} + // RecordVcsRefRevisionsDeltaDataPoint adds a data point to vcs.ref.revisions_delta metric. func (mb *MetricsBuilder) RecordVcsRefRevisionsDeltaDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType, vcsRevisionDeltaDirectionAttributeValue AttributeVcsRevisionDeltaDirection) { mb.metricVcsRefRevisionsDelta.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String(), vcsRevisionDeltaDirectionAttributeValue.String()) @@ -904,16 +879,6 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp mb.metricVcsRepositoryCount.recordDataPoint(mb.startTime, ts, val) } -// RecordVcsRepositoryRefLinesAddedDataPoint adds a data point to vcs.repository.ref.lines_added metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesAddedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefLinesAdded.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - -// RecordVcsRepositoryRefLinesDeletedDataPoint adds a data point to vcs.repository.ref.lines_deleted metric. -func (mb *MetricsBuilder) RecordVcsRepositoryRefLinesDeletedDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { - mb.metricVcsRepositoryRefLinesDeleted.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) -} - // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, // and metrics builder should update its startTime and reset it's internal state accordingly. func (mb *MetricsBuilder) Reset(options ...MetricBuilderOption) { diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 2ed480c81c86..4324b1380e97 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -72,6 +72,10 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) + defaultMetricsCount++ + allMetricsCount++ + mb.RecordVcsRefLinesDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsLineChangeTypeAdded) + defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) @@ -103,14 +107,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRepositoryCountDataPoint(ts, 1) - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) - rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") rb.SetVcsVendorName("vcs.vendor.name-val") @@ -157,6 +153,33 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) assert.EqualValues(t, "branch", attrVal.Str()) + case "vcs.ref.lines_delta": + assert.False(t, validatedMetrics["vcs.ref.lines_delta"], "Found a duplicate in the metrics slice: vcs.ref.lines_delta") + validatedMetrics["vcs.ref.lines_delta"] = 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 lines added/removed in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) + assert.Equal(t, "{line}", 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("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.repository.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.line_change.type") + assert.True(t, ok) + assert.EqualValues(t, "added", attrVal.Str()) case "vcs.ref.revisions_delta": assert.False(t, validatedMetrics["vcs.ref.revisions_delta"], "Found a duplicate in the metrics slice: vcs.ref.revisions_delta") validatedMetrics["vcs.ref.revisions_delta"] = true @@ -322,54 +345,6 @@ 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 "vcs.repository.ref.lines_added": - assert.False(t, validatedMetrics["vcs.repository.ref.lines_added"], "Found a duplicate in the metrics slice: vcs.repository.ref.lines_added") - validatedMetrics["vcs.repository.ref.lines_added"] = 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 lines added in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) - assert.Equal(t, "{line}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.repository.ref.lines_deleted": - assert.False(t, validatedMetrics["vcs.repository.ref.lines_deleted"], "Found a duplicate in the metrics slice: vcs.repository.ref.lines_deleted") - validatedMetrics["vcs.repository.ref.lines_deleted"] = 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 lines deleted in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) - assert.Equal(t, "{line}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) } } }) diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index a804b6d3fdee..b74dc64bbaa9 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -3,6 +3,8 @@ all_set: metrics: vcs.ref.count: enabled: true + vcs.ref.lines_delta: + enabled: true vcs.ref.revisions_delta: enabled: true vcs.ref.time: @@ -19,10 +21,6 @@ all_set: enabled: true vcs.repository.count: enabled: true - vcs.repository.ref.lines_added: - enabled: true - vcs.repository.ref.lines_deleted: - enabled: true resource_attributes: organization.name: enabled: true @@ -32,6 +30,8 @@ none_set: metrics: vcs.ref.count: enabled: false + vcs.ref.lines_delta: + enabled: false vcs.ref.revisions_delta: enabled: false vcs.ref.time: @@ -48,10 +48,6 @@ none_set: enabled: false vcs.repository.count: enabled: false - vcs.repository.ref.lines_added: - enabled: false - vcs.repository.ref.lines_deleted: - enabled: false resource_attributes: organization.name: enabled: false diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 306741f77f17..a57a0e976d3d 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -154,8 +154,8 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { } ghs.mb.RecordVcsRefTimeDataPoint(now, age, url, branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefLinesAddedDataPoint(now, int64(additions), url, branch.Repository.Name, branch.Name, refType) - ghs.mb.RecordVcsRepositoryRefLinesDeletedDataPoint(now, int64(deletions), url, branch.Repository.Name, branch.Name, refType) + ghs.mb.RecordVcsRefLinesDeltaDataPoint(now, int64(additions), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsLineChangeTypeAdded) + ghs.mb.RecordVcsRefLinesDeltaDataPoint(now, int64(deletions), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsLineChangeTypeRemoved) } // Get the contributor count for each of the repositories diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index e72aea6e9427..097a2316e61e 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -28,6 +28,49 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.ref.count unit: '{ref}' + - description: The number of lines added/removed in a ref (branch) relative to the default branch (trunk). + gauge: + dataPoints: + - asInt: "10" + attributes: + - key: vcs.line_change.type + value: + stringValue: added + - key: vcs.ref.head.name + value: + stringValue: main + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "9" + attributes: + - key: vcs.line_change.type + value: + stringValue: removed + - key: vcs.ref.head.name + value: + stringValue: main + - key: vcs.ref.head.type + value: + stringValue: branch + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.ref.lines_delta + unit: '{line}' - description: The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). gauge: dataPoints: @@ -167,48 +210,6 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.count unit: '{repository}' - - description: The number of lines added in a ref (branch) relative to the default branch (trunk). - gauge: - dataPoints: - - asInt: "10" - attributes: - - key: vcs.ref.head.name - value: - stringValue: main - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: "" - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.lines_added - unit: '{line}' - - description: The number of lines deleted in a ref (branch) relative to the default branch (trunk). - gauge: - dataPoints: - - asInt: "9" - attributes: - - key: vcs.ref.head.name - value: - stringValue: main - - key: vcs.ref.head.type - value: - stringValue: branch - - key: vcs.repository.name - value: - stringValue: "" - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.ref.lines_deleted - unit: '{line}' scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver version: latest diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 8fe6c65a57ab..83a54965c91e 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -48,6 +48,12 @@ attributes: enum: - ahead - behind + vcs.line_change.type: + description: The type of line change being measured on a ref (branch). + type: string + enum: + - added + - removed metrics: vcs.repository.count: @@ -78,20 +84,13 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.revision_delta.direction] - vcs.repository.ref.lines_added: - enabled: true - description: The number of lines added in a ref (branch) relative to the default branch (trunk). - unit: "{line}" - gauge: - value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] - vcs.repository.ref.lines_deleted: + vcs.ref.lines_delta: enabled: true - description: The number of lines deleted in a ref (branch) relative to the default branch (trunk). + description: The number of lines added/removed in a ref (branch) relative to the default branch (trunk). unit: "{line}" gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.line_change.type] vcs.repository.contributor.count: enabled: false description: The number of unique contributors to a repository. From 98d509bd8b54645822690197279bdadb4eeb8b5c Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Thu, 5 Dec 2024 22:52:41 -0500 Subject: [PATCH 08/18] [receiver/github] update contributor count metric name --- receiver/githubreceiver/documentation.md | 2 +- .../internal/metadata/generated_config.go | 8 +- .../metadata/generated_config_test.go | 4 +- .../internal/metadata/generated_metrics.go | 120 +++++++++--------- .../metadata/generated_metrics_test.go | 42 +++--- .../internal/metadata/testdata/config.yaml | 8 +- .../scraper/githubscraper/github_scraper.go | 2 +- receiver/githubreceiver/metadata.yaml | 2 +- 8 files changed, 94 insertions(+), 94 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 58d23847bf5c..52d37419a144 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -163,7 +163,7 @@ metrics: enabled: true ``` -### vcs.repository.contributor.count +### vcs.contributor.count The number of unique contributors to a repository. diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index 6bfc34d680dc..84dc51b38161 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -28,6 +28,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { + VcsContributorCount MetricConfig `mapstructure:"vcs.contributor.count"` VcsRefCount MetricConfig `mapstructure:"vcs.ref.count"` VcsRefLinesDelta MetricConfig `mapstructure:"vcs.ref.lines_delta"` VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` @@ -36,12 +37,14 @@ type MetricsConfig struct { VcsRepositoryChangeTimeOpen MetricConfig `mapstructure:"vcs.repository.change.time_open"` VcsRepositoryChangeTimeToApproval MetricConfig `mapstructure:"vcs.repository.change.time_to_approval"` VcsRepositoryChangeTimeToMerge MetricConfig `mapstructure:"vcs.repository.change.time_to_merge"` - VcsRepositoryContributorCount MetricConfig `mapstructure:"vcs.repository.contributor.count"` VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` } func DefaultMetricsConfig() MetricsConfig { return MetricsConfig{ + VcsContributorCount: MetricConfig{ + Enabled: false, + }, VcsRefCount: MetricConfig{ Enabled: true, }, @@ -66,9 +69,6 @@ func DefaultMetricsConfig() MetricsConfig { VcsRepositoryChangeTimeToMerge: MetricConfig{ Enabled: true, }, - VcsRepositoryContributorCount: MetricConfig{ - Enabled: false, - }, VcsRepositoryCount: MetricConfig{ Enabled: true, }, diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index b8f9d0e5e3b4..866cc93c3e1a 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -25,6 +25,7 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsContributorCount: MetricConfig{Enabled: true}, VcsRefCount: MetricConfig{Enabled: true}, VcsRefLinesDelta: MetricConfig{Enabled: true}, VcsRefRevisionsDelta: MetricConfig{Enabled: true}, @@ -33,7 +34,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: true}, - VcsRepositoryContributorCount: MetricConfig{Enabled: true}, VcsRepositoryCount: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ @@ -46,6 +46,7 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + VcsContributorCount: MetricConfig{Enabled: false}, VcsRefCount: MetricConfig{Enabled: false}, VcsRefLinesDelta: MetricConfig{Enabled: false}, VcsRefRevisionsDelta: MetricConfig{Enabled: false}, @@ -54,7 +55,6 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: false}, - VcsRepositoryContributorCount: MetricConfig{Enabled: false}, VcsRepositoryCount: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 045f42a11f93..f099e745dcb1 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -117,6 +117,58 @@ var MapAttributeVcsRevisionDeltaDirection = map[string]AttributeVcsRevisionDelta "behind": AttributeVcsRevisionDeltaDirectionBehind, } +type metricVcsContributorCount 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 vcs.contributor.count metric with initial data. +func (m *metricVcsContributorCount) init() { + m.data.SetName("vcs.contributor.count") + m.data.SetDescription("The number of unique contributors to a repository.") + m.data.SetUnit("{contributor}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricVcsContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricVcsContributorCount) 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 *metricVcsContributorCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricVcsContributorCount(cfg MetricConfig) metricVcsContributorCount { + m := metricVcsContributorCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricVcsRefCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -546,58 +598,6 @@ func newMetricVcsRepositoryChangeTimeToMerge(cfg MetricConfig) metricVcsReposito return m } -type metricVcsRepositoryContributorCount 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 vcs.repository.contributor.count metric with initial data. -func (m *metricVcsRepositoryContributorCount) init() { - m.data.SetName("vcs.repository.contributor.count") - m.data.SetDescription("The number of unique contributors to a repository.") - m.data.SetUnit("{contributor}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryContributorCount) 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 *metricVcsRepositoryContributorCount) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricVcsRepositoryContributorCount(cfg MetricConfig) metricVcsRepositoryContributorCount { - m := metricVcsRepositoryContributorCount{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - type metricVcsRepositoryCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -657,6 +657,7 @@ type MetricsBuilder struct { buildInfo component.BuildInfo // contains version information. resourceAttributeIncludeFilter map[string]filter.Filter resourceAttributeExcludeFilter map[string]filter.Filter + metricVcsContributorCount metricVcsContributorCount metricVcsRefCount metricVcsRefCount metricVcsRefLinesDelta metricVcsRefLinesDelta metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta @@ -665,7 +666,6 @@ type MetricsBuilder struct { metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge - metricVcsRepositoryContributorCount metricVcsRepositoryContributorCount metricVcsRepositoryCount metricVcsRepositoryCount } @@ -693,6 +693,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt startTime: pcommon.NewTimestampFromTime(time.Now()), metricsBuffer: pmetric.NewMetrics(), buildInfo: settings.BuildInfo, + metricVcsContributorCount: newMetricVcsContributorCount(mbc.Metrics.VcsContributorCount), metricVcsRefCount: newMetricVcsRefCount(mbc.Metrics.VcsRefCount), metricVcsRefLinesDelta: newMetricVcsRefLinesDelta(mbc.Metrics.VcsRefLinesDelta), metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), @@ -701,7 +702,6 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricVcsRepositoryChangeTimeOpen: newMetricVcsRepositoryChangeTimeOpen(mbc.Metrics.VcsRepositoryChangeTimeOpen), metricVcsRepositoryChangeTimeToApproval: newMetricVcsRepositoryChangeTimeToApproval(mbc.Metrics.VcsRepositoryChangeTimeToApproval), metricVcsRepositoryChangeTimeToMerge: newMetricVcsRepositoryChangeTimeToMerge(mbc.Metrics.VcsRepositoryChangeTimeToMerge), - metricVcsRepositoryContributorCount: newMetricVcsRepositoryContributorCount(mbc.Metrics.VcsRepositoryContributorCount), metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), resourceAttributeIncludeFilter: make(map[string]filter.Filter), resourceAttributeExcludeFilter: make(map[string]filter.Filter), @@ -788,6 +788,7 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) + mb.metricVcsContributorCount.emit(ils.Metrics()) mb.metricVcsRefCount.emit(ils.Metrics()) mb.metricVcsRefLinesDelta.emit(ils.Metrics()) mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) @@ -796,7 +797,6 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { mb.metricVcsRepositoryChangeTimeOpen.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToApproval.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) - mb.metricVcsRepositoryContributorCount.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) for _, op := range options { @@ -829,6 +829,11 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics return metrics } +// RecordVcsContributorCountDataPoint adds a data point to vcs.contributor.count metric. +func (mb *MetricsBuilder) RecordVcsContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { + mb.metricVcsContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue) +} + // RecordVcsRefCountDataPoint adds a data point to vcs.ref.count metric. func (mb *MetricsBuilder) RecordVcsRefCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue AttributeVcsRefHeadType) { mb.metricVcsRefCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) @@ -869,11 +874,6 @@ func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcomm mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) } -// RecordVcsRepositoryContributorCountDataPoint adds a data point to vcs.repository.contributor.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { - mb.metricVcsRepositoryContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue) -} - // RecordVcsRepositoryCountDataPoint adds a data point to vcs.repository.count metric. func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp, val int64) { mb.metricVcsRepositoryCount.recordDataPoint(mb.startTime, ts, val) diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 4324b1380e97..2cabd74a14b8 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -68,6 +68,9 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount := 0 allMetricsCount := 0 + allMetricsCount++ + mb.RecordVcsContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") + defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) @@ -100,9 +103,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") - allMetricsCount++ - mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") - defaultMetricsCount++ allMetricsCount++ mb.RecordVcsRepositoryCountDataPoint(ts, 1) @@ -132,6 +132,24 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { + case "vcs.contributor.count": + assert.False(t, validatedMetrics["vcs.contributor.count"], "Found a duplicate in the metrics slice: vcs.contributor.count") + validatedMetrics["vcs.contributor.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 unique contributors to a repository.", ms.At(i).Description()) + assert.Equal(t, "{contributor}", 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("vcs.repository.url.full") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.repository.name") + assert.True(t, ok) + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) case "vcs.ref.count": assert.False(t, validatedMetrics["vcs.ref.count"], "Found a duplicate in the metrics slice: vcs.ref.count") validatedMetrics["vcs.ref.count"] = true @@ -315,24 +333,6 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - case "vcs.repository.contributor.count": - assert.False(t, validatedMetrics["vcs.repository.contributor.count"], "Found a duplicate in the metrics slice: vcs.repository.contributor.count") - validatedMetrics["vcs.repository.contributor.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 unique contributors to a repository.", ms.At(i).Description()) - assert.Equal(t, "{contributor}", 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("vcs.repository.url.full") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.repository.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) case "vcs.repository.count": assert.False(t, validatedMetrics["vcs.repository.count"], "Found a duplicate in the metrics slice: vcs.repository.count") validatedMetrics["vcs.repository.count"] = true diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index b74dc64bbaa9..aaa532da13e6 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -1,6 +1,8 @@ default: all_set: metrics: + vcs.contributor.count: + enabled: true vcs.ref.count: enabled: true vcs.ref.lines_delta: @@ -17,8 +19,6 @@ all_set: enabled: true vcs.repository.change.time_to_merge: enabled: true - vcs.repository.contributor.count: - enabled: true vcs.repository.count: enabled: true resource_attributes: @@ -28,6 +28,8 @@ all_set: enabled: true none_set: metrics: + vcs.contributor.count: + enabled: false vcs.ref.count: enabled: false vcs.ref.lines_delta: @@ -44,8 +46,6 @@ none_set: enabled: false vcs.repository.change.time_to_merge: enabled: false - vcs.repository.contributor.count: - enabled: false vcs.repository.count: enabled: false resource_attributes: diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index a57a0e976d3d..2885aa511c5c 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -163,7 +163,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { if err != nil { ghs.logger.Sugar().Errorf("error getting contributor count: %v", zap.Error(err)) } - ghs.mb.RecordVcsRepositoryContributorCountDataPoint(now, int64(contribs), url, name) + ghs.mb.RecordVcsContributorCountDataPoint(now, int64(contribs), url, name) // Get change (pull request) data prs, err := ghs.getPullRequests(ctx, genClient, name) diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 83a54965c91e..0420550ab8b2 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -91,7 +91,7 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.line_change.type] - vcs.repository.contributor.count: + vcs.contributor.count: enabled: false description: The number of unique contributors to a repository. unit: "{contributor}" From 41387d0bfb709aa18155bd8e917c8ca783d4d704 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 12:04:27 -0500 Subject: [PATCH 09/18] [receiver/github] add change.state and update time_open to duration --- receiver/githubreceiver/documentation.md | 5 +- .../internal/metadata/generated_config.go | 4 +- .../metadata/generated_config_test.go | 14 +-- .../internal/metadata/generated_metrics.go | 87 ++++++++----------- .../metadata/generated_metrics_test.go | 25 +++--- .../metadata/generated_resource_test.go | 10 +-- .../internal/metadata/testdata/config.yaml | 4 +- .../scraper/githubscraper/genqlient.graphql | 1 + .../scraper/githubscraper/github_scraper.go | 2 +- .../testdata/scraper/expected_happy_path.yaml | 7 +- receiver/githubreceiver/metadata.yaml | 6 +- 11 files changed, 80 insertions(+), 85 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index 52d37419a144..ca9dd69ed66e 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -97,9 +97,9 @@ The number of changes (pull requests) in a repository, categorized by their stat | vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | | vcs.repository.name | The name of the VCS repository. | Any Str | -### vcs.repository.change.time_open +### vcs.repository.change.duration -The amount of time a change (pull request) has been open. +The time duration a change (pull request/merge request/changelist) has been in an open state. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -112,6 +112,7 @@ The amount of time a change (pull request) has been open. | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | ### vcs.repository.change.time_to_approval diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index 84dc51b38161..d0565399c22b 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -34,7 +34,7 @@ type MetricsConfig struct { VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` VcsRefTime MetricConfig `mapstructure:"vcs.ref.time"` VcsRepositoryChangeCount MetricConfig `mapstructure:"vcs.repository.change.count"` - VcsRepositoryChangeTimeOpen MetricConfig `mapstructure:"vcs.repository.change.time_open"` + VcsRepositoryChangeDuration MetricConfig `mapstructure:"vcs.repository.change.duration"` VcsRepositoryChangeTimeToApproval MetricConfig `mapstructure:"vcs.repository.change.time_to_approval"` VcsRepositoryChangeTimeToMerge MetricConfig `mapstructure:"vcs.repository.change.time_to_merge"` VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` @@ -60,7 +60,7 @@ func DefaultMetricsConfig() MetricsConfig { VcsRepositoryChangeCount: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeOpen: MetricConfig{ + VcsRepositoryChangeDuration: MetricConfig{ Enabled: true, }, VcsRepositoryChangeTimeToApproval: MetricConfig{ diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 866cc93c3e1a..57f45aaa0c80 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -31,7 +31,7 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRefRevisionsDelta: MetricConfig{Enabled: true}, VcsRefTime: MetricConfig{Enabled: true}, VcsRepositoryChangeCount: MetricConfig{Enabled: true}, - VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: true}, + VcsRepositoryChangeDuration: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: true}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: true}, VcsRepositoryCount: MetricConfig{Enabled: true}, @@ -52,7 +52,7 @@ func TestMetricsBuilderConfig(t *testing.T) { VcsRefRevisionsDelta: MetricConfig{Enabled: false}, VcsRefTime: MetricConfig{Enabled: false}, VcsRepositoryChangeCount: MetricConfig{Enabled: false}, - VcsRepositoryChangeTimeOpen: MetricConfig{Enabled: false}, + VcsRepositoryChangeDuration: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: false}, VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: false}, VcsRepositoryCount: MetricConfig{Enabled: false}, @@ -67,8 +67,9 @@ func TestMetricsBuilderConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadMetricsBuilderConfig(t, tt.name) - diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})) - require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) + if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" { + t.Errorf("Config mismatch (-expected +actual):\n%s", diff) + } }) } } @@ -110,8 +111,9 @@ func TestResourceAttributesConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadResourceAttributesConfig(t, tt.name) - diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})) - require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) + if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" { + t.Errorf("Config mismatch (-expected +actual):\n%s", diff) + } }) } } diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index f099e745dcb1..11231991d4f8 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -439,22 +439,22 @@ func newMetricVcsRepositoryChangeCount(cfg MetricConfig) metricVcsRepositoryChan return m } -type metricVcsRepositoryChangeTimeOpen struct { +type metricVcsRepositoryChangeDuration 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 vcs.repository.change.time_open metric with initial data. -func (m *metricVcsRepositoryChangeTimeOpen) init() { - m.data.SetName("vcs.repository.change.time_open") - m.data.SetDescription("The amount of time a change (pull request) has been open.") +// init fills vcs.repository.change.duration metric with initial data. +func (m *metricVcsRepositoryChangeDuration) init() { + m.data.SetName("vcs.repository.change.duration") + m.data.SetDescription("The time duration a change (pull request/merge request/changelist) has been in an open state.") m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { +func (m *metricVcsRepositoryChangeDuration) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue string) { if !m.config.Enabled { return } @@ -465,17 +465,18 @@ func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timest dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeTimeOpen) updateCapacity() { +func (m *metricVcsRepositoryChangeDuration) 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 *metricVcsRepositoryChangeTimeOpen) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsRepositoryChangeDuration) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -483,8 +484,8 @@ func (m *metricVcsRepositoryChangeTimeOpen) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryChangeTimeOpen(cfg MetricConfig) metricVcsRepositoryChangeTimeOpen { - m := metricVcsRepositoryChangeTimeOpen{config: cfg} +func newMetricVcsRepositoryChangeDuration(cfg MetricConfig) metricVcsRepositoryChangeDuration { + m := metricVcsRepositoryChangeDuration{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -663,31 +664,23 @@ type MetricsBuilder struct { metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta metricVcsRefTime metricVcsRefTime metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount - metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeOpen + metricVcsRepositoryChangeDuration metricVcsRepositoryChangeDuration metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryCount metricVcsRepositoryCount } -// MetricBuilderOption applies changes to default metrics builder. -type MetricBuilderOption interface { - apply(*MetricsBuilder) -} - -type metricBuilderOptionFunc func(mb *MetricsBuilder) - -func (mbof metricBuilderOptionFunc) apply(mb *MetricsBuilder) { - mbof(mb) -} +// metricBuilderOption applies changes to default metrics builder. +type metricBuilderOption func(*MetricsBuilder) // WithStartTime sets startTime on the metrics builder. -func WithStartTime(startTime pcommon.Timestamp) MetricBuilderOption { - return metricBuilderOptionFunc(func(mb *MetricsBuilder) { +func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { + return func(mb *MetricsBuilder) { mb.startTime = startTime - }) + } } -func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...MetricBuilderOption) *MetricsBuilder { +func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...metricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ config: mbc, startTime: pcommon.NewTimestampFromTime(time.Now()), @@ -699,7 +692,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), metricVcsRefTime: newMetricVcsRefTime(mbc.Metrics.VcsRefTime), metricVcsRepositoryChangeCount: newMetricVcsRepositoryChangeCount(mbc.Metrics.VcsRepositoryChangeCount), - metricVcsRepositoryChangeTimeOpen: newMetricVcsRepositoryChangeTimeOpen(mbc.Metrics.VcsRepositoryChangeTimeOpen), + metricVcsRepositoryChangeDuration: newMetricVcsRepositoryChangeDuration(mbc.Metrics.VcsRepositoryChangeDuration), metricVcsRepositoryChangeTimeToApproval: newMetricVcsRepositoryChangeTimeToApproval(mbc.Metrics.VcsRepositoryChangeTimeToApproval), metricVcsRepositoryChangeTimeToMerge: newMetricVcsRepositoryChangeTimeToMerge(mbc.Metrics.VcsRepositoryChangeTimeToMerge), metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), @@ -720,7 +713,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt } for _, op := range options { - op.apply(mb) + op(mb) } return mb } @@ -738,28 +731,20 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } // ResourceMetricsOption applies changes to provided resource metrics. -type ResourceMetricsOption interface { - apply(pmetric.ResourceMetrics) -} - -type resourceMetricsOptionFunc func(pmetric.ResourceMetrics) - -func (rmof resourceMetricsOptionFunc) apply(rm pmetric.ResourceMetrics) { - rmof(rm) -} +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithResource sets the provided resource on the emitted ResourceMetrics. // It's recommended to use ResourceBuilder to create the resource. func WithResource(res pcommon.Resource) ResourceMetricsOption { - return resourceMetricsOptionFunc(func(rm pmetric.ResourceMetrics) { + return func(rm pmetric.ResourceMetrics) { res.CopyTo(rm.Resource()) - }) + } } // WithStartTimeOverride overrides start time for all the resource metrics data points. // This option should be only used if different start time has to be set on metrics coming from different resources. func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { - return resourceMetricsOptionFunc(func(rm pmetric.ResourceMetrics) { + return func(rm pmetric.ResourceMetrics) { var dps pmetric.NumberDataPointSlice metrics := rm.ScopeMetrics().At(0).Metrics() for i := 0; i < metrics.Len(); i++ { @@ -773,7 +758,7 @@ func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { dps.At(j).SetStartTimestamp(start) } } - }) + } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for @@ -781,7 +766,7 @@ func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { // needs to emit metrics from several resources. Otherwise calling this function is not required, // just `Emit` function can be called instead. // Resource attributes should be provided as ResourceMetricsOption arguments. -func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) ils := rm.ScopeMetrics().AppendEmpty() @@ -794,13 +779,13 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) mb.metricVcsRefTime.emit(ils.Metrics()) mb.metricVcsRepositoryChangeCount.emit(ils.Metrics()) - mb.metricVcsRepositoryChangeTimeOpen.emit(ils.Metrics()) + mb.metricVcsRepositoryChangeDuration.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToApproval.emit(ils.Metrics()) mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) - for _, op := range options { - op.apply(rm) + for _, op := range rmo { + op(rm) } for attr, filter := range mb.resourceAttributeIncludeFilter { if val, ok := rm.Resource().Attributes().Get(attr); ok && !filter.Matches(val.AsString()) { @@ -822,8 +807,8 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user config, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics { - mb.EmitForResource(options...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := mb.metricsBuffer mb.metricsBuffer = pmetric.NewMetrics() return metrics @@ -859,9 +844,9 @@ func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Tim mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) } -// RecordVcsRepositoryChangeTimeOpenDataPoint adds a data point to vcs.repository.change.time_open metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeOpenDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeOpen.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) +// RecordVcsRepositoryChangeDurationDataPoint adds a data point to vcs.repository.change.duration metric. +func (mb *MetricsBuilder) RecordVcsRepositoryChangeDurationDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState) { + mb.metricVcsRepositoryChangeDuration.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsChangeStateAttributeValue.String()) } // RecordVcsRepositoryChangeTimeToApprovalDataPoint adds a data point to vcs.repository.change.time_to_approval metric. @@ -881,9 +866,9 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, // and metrics builder should update its startTime and reset it's internal state accordingly. -func (mb *MetricsBuilder) Reset(options ...MetricBuilderOption) { +func (mb *MetricsBuilder) Reset(options ...metricBuilderOption) { mb.startTime = pcommon.NewTimestampFromTime(time.Now()) for _, op := range options { - op.apply(mb) + op(mb) } } diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 2cabd74a14b8..5657c5bcfe41 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -52,14 +52,14 @@ func TestMetricsBuilder(t *testing.T) { expectEmpty: true, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { start := pcommon.Timestamp(1_000_000_000) ts := pcommon.Timestamp(1_000_001_000) observedZapCore, observedLogs := observer.New(zap.WarnLevel) settings := receivertest.NewNopSettings() settings.Logger = zap.New(observedZapCore) - mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, tt.name), settings, WithStartTime(start)) + mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) expectedWarnings := 0 @@ -93,7 +93,7 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") + mb.RecordVcsRepositoryChangeDurationDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsChangeStateOpen) defaultMetricsCount++ allMetricsCount++ @@ -113,7 +113,7 @@ func TestMetricsBuilder(t *testing.T) { res := rb.Emit() metrics := mb.Emit(WithResource(res)) - if tt.expectEmpty { + if test.expectEmpty { assert.Equal(t, 0, metrics.ResourceMetrics().Len()) return } @@ -123,10 +123,10 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, res, rm.Resource()) assert.Equal(t, 1, rm.ScopeMetrics().Len()) ms := rm.ScopeMetrics().At(0).Metrics() - if tt.metricsSet == testDataSetDefault { + if test.metricsSet == testDataSetDefault { assert.Equal(t, defaultMetricsCount, ms.Len()) } - if tt.metricsSet == testDataSetAll { + if test.metricsSet == testDataSetAll { assert.Equal(t, allMetricsCount, ms.Len()) } validatedMetrics := make(map[string]bool) @@ -270,12 +270,12 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - case "vcs.repository.change.time_open": - assert.False(t, validatedMetrics["vcs.repository.change.time_open"], "Found a duplicate in the metrics slice: vcs.repository.change.time_open") - validatedMetrics["vcs.repository.change.time_open"] = true + case "vcs.repository.change.duration": + assert.False(t, validatedMetrics["vcs.repository.change.duration"], "Found a duplicate in the metrics slice: vcs.repository.change.duration") + validatedMetrics["vcs.repository.change.duration"] = 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 change (pull request) has been open.", ms.At(i).Description()) + assert.Equal(t, "The time duration a change (pull request/merge request/changelist) has been in an open state.", 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()) @@ -291,6 +291,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.change.state") + assert.True(t, ok) + assert.EqualValues(t, "open", attrVal.Str()) case "vcs.repository.change.time_to_approval": assert.False(t, validatedMetrics["vcs.repository.change.time_to_approval"], "Found a duplicate in the metrics slice: vcs.repository.change.time_to_approval") validatedMetrics["vcs.repository.change.time_to_approval"] = true diff --git a/receiver/githubreceiver/internal/metadata/generated_resource_test.go b/receiver/githubreceiver/internal/metadata/generated_resource_test.go index a52461583d4f..6ce546c16439 100644 --- a/receiver/githubreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_resource_test.go @@ -9,9 +9,9 @@ import ( ) func TestResourceBuilder(t *testing.T) { - for _, tt := range []string{"default", "all_set", "none_set"} { - t.Run(tt, func(t *testing.T) { - cfg := loadResourceAttributesConfig(t, tt) + for _, test := range []string{"default", "all_set", "none_set"} { + t.Run(test, func(t *testing.T) { + cfg := loadResourceAttributesConfig(t, test) rb := NewResourceBuilder(cfg) rb.SetOrganizationName("organization.name-val") rb.SetVcsVendorName("vcs.vendor.name-val") @@ -19,7 +19,7 @@ func TestResourceBuilder(t *testing.T) { res := rb.Emit() assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource - switch tt { + switch test { case "default": assert.Equal(t, 2, res.Attributes().Len()) case "all_set": @@ -28,7 +28,7 @@ func TestResourceBuilder(t *testing.T) { assert.Equal(t, 0, res.Attributes().Len()) return default: - assert.Failf(t, "unexpected test case: %s", tt) + assert.Failf(t, "unexpected test case: %s", test) } val, ok := res.Attributes().Get("organization.name") diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index aaa532da13e6..3bbd11cf5130 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -13,7 +13,7 @@ all_set: enabled: true vcs.repository.change.count: enabled: true - vcs.repository.change.time_open: + vcs.repository.change.duration: enabled: true vcs.repository.change.time_to_approval: enabled: true @@ -40,7 +40,7 @@ none_set: enabled: false vcs.repository.change.count: enabled: false - vcs.repository.change.time_open: + vcs.repository.change.duration: enabled: false vcs.repository.change.time_to_approval: enabled: false diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql index 1d89fdad565d..7fd04b129c98 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql +++ b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.graphql @@ -131,6 +131,7 @@ query getPullRequestData( } } headRefName + # last: 1 returns the very first review reviews(states: APPROVED, last: 1) { totalCount nodes { diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 2885aa511c5c..cca97b9b3263 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -186,7 +186,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { age := getAge(pr.CreatedAt, now.AsTime()) - ghs.mb.RecordVcsRepositoryChangeTimeOpenDataPoint(now, age, url, name, pr.HeadRefName) + ghs.mb.RecordVcsRepositoryChangeDurationDataPoint(now, age, url, name, pr.HeadRefName, metadata.AttributeVcsChangeStateOpen) if pr.Reviews.TotalCount > 0 { age := getAge(pr.CreatedAt, pr.Reviews.Nodes[0].CreatedAt) diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 097a2316e61e..1bcf3ccd746d 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -166,11 +166,14 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.repository.change.count unit: '{change}' - - description: The amount of time a change (pull request) has been open. + - description: The time duration a change (pull request/merge request/changelist) has been in an open state. gauge: dataPoints: - asInt: "9223372036" attributes: + - key: vcs.change.state + value: + stringValue: open - key: vcs.ref.head.name value: stringValue: "" @@ -182,7 +185,7 @@ resourceMetrics: stringValue: '{ false false }' startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.change.time_open + name: vcs.repository.change.duration unit: s - description: The amount of time it took a change (pull request) to go from open to merged. gauge: diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index a361b95c2698..7ddeb2b00dc7 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -99,13 +99,13 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name] - vcs.repository.change.time_open: + vcs.repository.change.duration: enabled: true - description: The amount of time a change (pull request) has been open. + description: The time duration a change (pull request/merge request/changelist) has been in an open state. unit: s gauge: value_type: int - attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.change.state] vcs.repository.change.time_to_merge: enabled: true description: The amount of time it took a change (pull request) to go from open to merged. From 6fe2684b590e5ee1972d54fd93dc28fd6323b16c Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 12:32:23 -0500 Subject: [PATCH 10/18] [chore] fix local generation --- .../metadata/generated_config_test.go | 10 ++-- .../internal/metadata/generated_metrics.go | 54 ++++++++++++------- .../metadata/generated_metrics_test.go | 12 ++--- .../metadata/generated_resource_test.go | 10 ++-- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 57f45aaa0c80..75b395e4f1bc 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -67,9 +67,8 @@ func TestMetricsBuilderConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadMetricsBuilderConfig(t, tt.name) - if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" { - t.Errorf("Config mismatch (-expected +actual):\n%s", diff) - } + diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})) + require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) }) } } @@ -111,9 +110,8 @@ func TestResourceAttributesConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadResourceAttributesConfig(t, tt.name) - if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" { - t.Errorf("Config mismatch (-expected +actual):\n%s", diff) - } + diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})) + require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) }) } } diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 11231991d4f8..3bef6160b2a0 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -670,17 +670,25 @@ type MetricsBuilder struct { metricVcsRepositoryCount metricVcsRepositoryCount } -// metricBuilderOption applies changes to default metrics builder. -type metricBuilderOption func(*MetricsBuilder) +// MetricBuilderOption applies changes to default metrics builder. +type MetricBuilderOption interface { + apply(*MetricsBuilder) +} + +type metricBuilderOptionFunc func(mb *MetricsBuilder) + +func (mbof metricBuilderOptionFunc) apply(mb *MetricsBuilder) { + mbof(mb) +} // WithStartTime sets startTime on the metrics builder. -func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { - return func(mb *MetricsBuilder) { +func WithStartTime(startTime pcommon.Timestamp) MetricBuilderOption { + return metricBuilderOptionFunc(func(mb *MetricsBuilder) { mb.startTime = startTime - } + }) } -func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...metricBuilderOption) *MetricsBuilder { +func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...MetricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ config: mbc, startTime: pcommon.NewTimestampFromTime(time.Now()), @@ -713,7 +721,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt } for _, op := range options { - op(mb) + op.apply(mb) } return mb } @@ -731,20 +739,28 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } // ResourceMetricsOption applies changes to provided resource metrics. -type ResourceMetricsOption func(pmetric.ResourceMetrics) +type ResourceMetricsOption interface { + apply(pmetric.ResourceMetrics) +} + +type resourceMetricsOptionFunc func(pmetric.ResourceMetrics) + +func (rmof resourceMetricsOptionFunc) apply(rm pmetric.ResourceMetrics) { + rmof(rm) +} // WithResource sets the provided resource on the emitted ResourceMetrics. // It's recommended to use ResourceBuilder to create the resource. func WithResource(res pcommon.Resource) ResourceMetricsOption { - return func(rm pmetric.ResourceMetrics) { + return resourceMetricsOptionFunc(func(rm pmetric.ResourceMetrics) { res.CopyTo(rm.Resource()) - } + }) } // WithStartTimeOverride overrides start time for all the resource metrics data points. // This option should be only used if different start time has to be set on metrics coming from different resources. func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { - return func(rm pmetric.ResourceMetrics) { + return resourceMetricsOptionFunc(func(rm pmetric.ResourceMetrics) { var dps pmetric.NumberDataPointSlice metrics := rm.ScopeMetrics().At(0).Metrics() for i := 0; i < metrics.Len(); i++ { @@ -758,7 +774,7 @@ func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { dps.At(j).SetStartTimestamp(start) } } - } + }) } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for @@ -766,7 +782,7 @@ func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { // needs to emit metrics from several resources. Otherwise calling this function is not required, // just `Emit` function can be called instead. // Resource attributes should be provided as ResourceMetricsOption arguments. -func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { +func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) ils := rm.ScopeMetrics().AppendEmpty() @@ -784,8 +800,8 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) - for _, op := range rmo { - op(rm) + for _, op := range options { + op.apply(rm) } for attr, filter := range mb.resourceAttributeIncludeFilter { if val, ok := rm.Resource().Attributes().Get(attr); ok && !filter.Matches(val.AsString()) { @@ -807,8 +823,8 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user config, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { - mb.EmitForResource(rmo...) +func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(options...) metrics := mb.metricsBuffer mb.metricsBuffer = pmetric.NewMetrics() return metrics @@ -866,9 +882,9 @@ func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, // and metrics builder should update its startTime and reset it's internal state accordingly. -func (mb *MetricsBuilder) Reset(options ...metricBuilderOption) { +func (mb *MetricsBuilder) Reset(options ...MetricBuilderOption) { mb.startTime = pcommon.NewTimestampFromTime(time.Now()) for _, op := range options { - op(mb) + op.apply(mb) } } diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 5657c5bcfe41..0d02c6dbb08b 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -52,14 +52,14 @@ func TestMetricsBuilder(t *testing.T) { expectEmpty: true, }, } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { start := pcommon.Timestamp(1_000_000_000) ts := pcommon.Timestamp(1_000_001_000) observedZapCore, observedLogs := observer.New(zap.WarnLevel) settings := receivertest.NewNopSettings() settings.Logger = zap.New(observedZapCore) - mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) + mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, tt.name), settings, WithStartTime(start)) expectedWarnings := 0 @@ -113,7 +113,7 @@ func TestMetricsBuilder(t *testing.T) { res := rb.Emit() metrics := mb.Emit(WithResource(res)) - if test.expectEmpty { + if tt.expectEmpty { assert.Equal(t, 0, metrics.ResourceMetrics().Len()) return } @@ -123,10 +123,10 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, res, rm.Resource()) assert.Equal(t, 1, rm.ScopeMetrics().Len()) ms := rm.ScopeMetrics().At(0).Metrics() - if test.metricsSet == testDataSetDefault { + if tt.metricsSet == testDataSetDefault { assert.Equal(t, defaultMetricsCount, ms.Len()) } - if test.metricsSet == testDataSetAll { + if tt.metricsSet == testDataSetAll { assert.Equal(t, allMetricsCount, ms.Len()) } validatedMetrics := make(map[string]bool) diff --git a/receiver/githubreceiver/internal/metadata/generated_resource_test.go b/receiver/githubreceiver/internal/metadata/generated_resource_test.go index 6ce546c16439..a52461583d4f 100644 --- a/receiver/githubreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_resource_test.go @@ -9,9 +9,9 @@ import ( ) func TestResourceBuilder(t *testing.T) { - for _, test := range []string{"default", "all_set", "none_set"} { - t.Run(test, func(t *testing.T) { - cfg := loadResourceAttributesConfig(t, test) + for _, tt := range []string{"default", "all_set", "none_set"} { + t.Run(tt, func(t *testing.T) { + cfg := loadResourceAttributesConfig(t, tt) rb := NewResourceBuilder(cfg) rb.SetOrganizationName("organization.name-val") rb.SetVcsVendorName("vcs.vendor.name-val") @@ -19,7 +19,7 @@ func TestResourceBuilder(t *testing.T) { res := rb.Emit() assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource - switch test { + switch tt { case "default": assert.Equal(t, 2, res.Attributes().Len()) case "all_set": @@ -28,7 +28,7 @@ func TestResourceBuilder(t *testing.T) { assert.Equal(t, 0, res.Attributes().Len()) return default: - assert.Failf(t, "unexpected test case: %s", test) + assert.Failf(t, "unexpected test case: %s", tt) } val, ok := res.Attributes().Get("organization.name") From 972890daaa8da9b6da38f9f9344e852e71ba2361 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 12:42:11 -0500 Subject: [PATCH 11/18] [receiver/github] remove repo from change state metrics and adjust attrs --- receiver/githubreceiver/documentation.md | 60 ++-- .../internal/metadata/generated_config.go | 42 +-- .../metadata/generated_config_test.go | 40 +-- .../internal/metadata/generated_metrics.go | 328 +++++++++--------- .../metadata/generated_metrics_test.go | 158 ++++----- .../internal/metadata/testdata/config.yaml | 32 +- .../scraper/githubscraper/github_scraper.go | 12 +- .../testdata/scraper/expected_happy_path.yaml | 140 ++++---- receiver/githubreceiver/metadata.yaml | 8 +- 9 files changed, 409 insertions(+), 411 deletions(-) diff --git a/receiver/githubreceiver/documentation.md b/receiver/githubreceiver/documentation.md index ca9dd69ed66e..160cb6a90c26 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -12,29 +12,29 @@ metrics: enabled: false ``` -### vcs.ref.count +### vcs.change.count -The number of refs of type branch in a repository. +The number of changes (pull requests) in a repository, categorized by their state (either open or merged). | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {ref} | Gauge | Int | +| {change} | Gauge | Int | #### Attributes | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | +| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | | vcs.repository.name | The name of the VCS repository. | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -### vcs.ref.lines_delta +### vcs.change.duration -The number of lines added/removed in a ref (branch) relative to the default branch (trunk). +The time duration a change (pull request/merge request/changelist) has been in an open state. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {line} | Gauge | Int | +| s | Gauge | Int | #### Attributes @@ -43,16 +43,15 @@ The number of lines added/removed in a ref (branch) relative to the default bran | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -| vcs.line_change.type | The type of line change being measured on a ref (branch). | Str: ``added``, ``removed`` | +| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | -### vcs.ref.revisions_delta +### vcs.change.time_to_approval -The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). +The amount of time it took a change (pull request) to go from open to approved. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {revision} | Gauge | Int | +| s | Gauge | Int | #### Attributes @@ -61,12 +60,10 @@ The number of revisions (commits) a ref (branch) is ahead/behind the branch from | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -| vcs.revision_delta.direction | The type of revision comparison. | Str: ``ahead``, ``behind`` | -### vcs.ref.time +### vcs.change.time_to_merge -Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. +The amount of time it took a change (pull request) to go from open to merged. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -79,31 +76,30 @@ Time a ref (branch) created from the default branch (trunk) has existed. The `vc | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -### vcs.repository.change.count +### vcs.ref.count -The number of changes (pull requests) in a repository, categorized by their state (either open or merged). +The number of refs of type branch in a repository. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {change} | Gauge | Int | +| {ref} | Gauge | Int | #### Attributes | Name | Description | Values | | ---- | ----------- | ------ | | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | -| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | | vcs.repository.name | The name of the VCS repository. | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | -### vcs.repository.change.duration +### vcs.ref.lines_delta -The time duration a change (pull request/merge request/changelist) has been in an open state. +The number of lines added/removed in a ref (branch) relative to the default branch (trunk). | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| s | Gauge | Int | +| {line} | Gauge | Int | #### Attributes @@ -112,15 +108,16 @@ The time duration a change (pull request/merge request/changelist) has been in a | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | -| vcs.change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.line_change.type | The type of line change being measured on a ref (branch). | Str: ``added``, ``removed`` | -### vcs.repository.change.time_to_approval +### vcs.ref.revisions_delta -The amount of time it took a change (pull request) to go from open to approved. +The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| s | Gauge | Int | +| {revision} | Gauge | Int | #### Attributes @@ -129,10 +126,12 @@ The amount of time it took a change (pull request) to go from open to approved. | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | +| vcs.revision_delta.direction | The type of revision comparison. | Str: ``ahead``, ``behind`` | -### vcs.repository.change.time_to_merge +### vcs.ref.time -The amount of time it took a change (pull request) to go from open to merged. +Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -145,6 +144,7 @@ The amount of time it took a change (pull request) to go from open to merged. | vcs.repository.url.full | The canonical URL of the repository providing the complete HTTPS address. | Any Str | | vcs.repository.name | The name of the VCS repository. | Any Str | | vcs.ref.head.name | The name of the VCS head reference (branch). | Any Str | +| vcs.ref.head.type | The type of the head reference (branch, tag). | Str: ``branch``, ``tag`` | ### vcs.repository.count diff --git a/receiver/githubreceiver/internal/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index d0565399c22b..2a44c29d06b2 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -28,45 +28,45 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { - VcsContributorCount MetricConfig `mapstructure:"vcs.contributor.count"` - VcsRefCount MetricConfig `mapstructure:"vcs.ref.count"` - VcsRefLinesDelta MetricConfig `mapstructure:"vcs.ref.lines_delta"` - VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` - VcsRefTime MetricConfig `mapstructure:"vcs.ref.time"` - VcsRepositoryChangeCount MetricConfig `mapstructure:"vcs.repository.change.count"` - VcsRepositoryChangeDuration MetricConfig `mapstructure:"vcs.repository.change.duration"` - VcsRepositoryChangeTimeToApproval MetricConfig `mapstructure:"vcs.repository.change.time_to_approval"` - VcsRepositoryChangeTimeToMerge MetricConfig `mapstructure:"vcs.repository.change.time_to_merge"` - VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` + VcsChangeCount MetricConfig `mapstructure:"vcs.change.count"` + VcsChangeDuration MetricConfig `mapstructure:"vcs.change.duration"` + VcsChangeTimeToApproval MetricConfig `mapstructure:"vcs.change.time_to_approval"` + VcsChangeTimeToMerge MetricConfig `mapstructure:"vcs.change.time_to_merge"` + VcsContributorCount MetricConfig `mapstructure:"vcs.contributor.count"` + VcsRefCount MetricConfig `mapstructure:"vcs.ref.count"` + VcsRefLinesDelta MetricConfig `mapstructure:"vcs.ref.lines_delta"` + VcsRefRevisionsDelta MetricConfig `mapstructure:"vcs.ref.revisions_delta"` + VcsRefTime MetricConfig `mapstructure:"vcs.ref.time"` + VcsRepositoryCount MetricConfig `mapstructure:"vcs.repository.count"` } func DefaultMetricsConfig() MetricsConfig { return MetricsConfig{ - VcsContributorCount: MetricConfig{ - Enabled: false, - }, - VcsRefCount: MetricConfig{ + VcsChangeCount: MetricConfig{ Enabled: true, }, - VcsRefLinesDelta: MetricConfig{ + VcsChangeDuration: MetricConfig{ Enabled: true, }, - VcsRefRevisionsDelta: MetricConfig{ + VcsChangeTimeToApproval: MetricConfig{ Enabled: true, }, - VcsRefTime: MetricConfig{ + VcsChangeTimeToMerge: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeCount: MetricConfig{ + VcsContributorCount: MetricConfig{ + Enabled: false, + }, + VcsRefCount: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeDuration: MetricConfig{ + VcsRefLinesDelta: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeToApproval: MetricConfig{ + VcsRefRevisionsDelta: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeToMerge: MetricConfig{ + VcsRefTime: MetricConfig{ Enabled: true, }, VcsRepositoryCount: MetricConfig{ diff --git a/receiver/githubreceiver/internal/metadata/generated_config_test.go b/receiver/githubreceiver/internal/metadata/generated_config_test.go index 75b395e4f1bc..ec0861b334e8 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -25,16 +25,16 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - VcsContributorCount: MetricConfig{Enabled: true}, - VcsRefCount: MetricConfig{Enabled: true}, - VcsRefLinesDelta: MetricConfig{Enabled: true}, - VcsRefRevisionsDelta: MetricConfig{Enabled: true}, - VcsRefTime: MetricConfig{Enabled: true}, - VcsRepositoryChangeCount: MetricConfig{Enabled: true}, - VcsRepositoryChangeDuration: MetricConfig{Enabled: true}, - VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: true}, - VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: true}, - VcsRepositoryCount: MetricConfig{Enabled: true}, + VcsChangeCount: MetricConfig{Enabled: true}, + VcsChangeDuration: MetricConfig{Enabled: true}, + VcsChangeTimeToApproval: MetricConfig{Enabled: true}, + VcsChangeTimeToMerge: MetricConfig{Enabled: true}, + VcsContributorCount: MetricConfig{Enabled: true}, + VcsRefCount: MetricConfig{Enabled: true}, + VcsRefLinesDelta: MetricConfig{Enabled: true}, + VcsRefRevisionsDelta: MetricConfig{Enabled: true}, + VcsRefTime: MetricConfig{Enabled: true}, + VcsRepositoryCount: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: true}, @@ -46,16 +46,16 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - VcsContributorCount: MetricConfig{Enabled: false}, - VcsRefCount: MetricConfig{Enabled: false}, - VcsRefLinesDelta: MetricConfig{Enabled: false}, - VcsRefRevisionsDelta: MetricConfig{Enabled: false}, - VcsRefTime: MetricConfig{Enabled: false}, - VcsRepositoryChangeCount: MetricConfig{Enabled: false}, - VcsRepositoryChangeDuration: MetricConfig{Enabled: false}, - VcsRepositoryChangeTimeToApproval: MetricConfig{Enabled: false}, - VcsRepositoryChangeTimeToMerge: MetricConfig{Enabled: false}, - VcsRepositoryCount: MetricConfig{Enabled: false}, + VcsChangeCount: MetricConfig{Enabled: false}, + VcsChangeDuration: MetricConfig{Enabled: false}, + VcsChangeTimeToApproval: MetricConfig{Enabled: false}, + VcsChangeTimeToMerge: MetricConfig{Enabled: false}, + VcsContributorCount: MetricConfig{Enabled: false}, + VcsRefCount: MetricConfig{Enabled: false}, + VcsRefLinesDelta: MetricConfig{Enabled: false}, + VcsRefRevisionsDelta: MetricConfig{Enabled: false}, + VcsRefTime: MetricConfig{Enabled: false}, + VcsRepositoryCount: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ OrganizationName: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics.go b/receiver/githubreceiver/internal/metadata/generated_metrics.go index 3bef6160b2a0..0f2537a3068f 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -117,22 +117,22 @@ var MapAttributeVcsRevisionDeltaDirection = map[string]AttributeVcsRevisionDelta "behind": AttributeVcsRevisionDeltaDirectionBehind, } -type metricVcsContributorCount struct { +type metricVcsChangeCount 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 vcs.contributor.count metric with initial data. -func (m *metricVcsContributorCount) init() { - m.data.SetName("vcs.contributor.count") - m.data.SetDescription("The number of unique contributors to a repository.") - m.data.SetUnit("{contributor}") +// init fills vcs.change.count metric with initial data. +func (m *metricVcsChangeCount) init() { + m.data.SetName("vcs.change.count") + m.data.SetDescription("The number of changes (pull requests) in a repository, categorized by their state (either open or merged).") + m.data.SetUnit("{change}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { +func (m *metricVcsChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -141,18 +141,19 @@ func (m *metricVcsContributorCount) recordDataPoint(start pcommon.Timestamp, ts dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsContributorCount) updateCapacity() { +func (m *metricVcsChangeCount) 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 *metricVcsContributorCount) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsChangeCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -160,8 +161,8 @@ func (m *metricVcsContributorCount) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsContributorCount(cfg MetricConfig) metricVcsContributorCount { - m := metricVcsContributorCount{config: cfg} +func newMetricVcsChangeCount(cfg MetricConfig) metricVcsChangeCount { + m := metricVcsChangeCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -169,22 +170,22 @@ func newMetricVcsContributorCount(cfg MetricConfig) metricVcsContributorCount { return m } -type metricVcsRefCount struct { +type metricVcsChangeDuration 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 vcs.ref.count metric with initial data. -func (m *metricVcsRefCount) init() { - m.data.SetName("vcs.ref.count") - m.data.SetDescription("The number of refs of type branch in a repository.") - m.data.SetUnit("{ref}") +// init fills vcs.change.duration metric with initial data. +func (m *metricVcsChangeDuration) init() { + m.data.SetName("vcs.change.duration") + m.data.SetDescription("The time duration a change (pull request/merge request/changelist) has been in an open state.") + m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { +func (m *metricVcsChangeDuration) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue string) { if !m.config.Enabled { return } @@ -194,18 +195,19 @@ func (m *metricVcsRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon. dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRefCount) updateCapacity() { +func (m *metricVcsChangeDuration) 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 *metricVcsRefCount) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsChangeDuration) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -213,8 +215,8 @@ func (m *metricVcsRefCount) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { - m := metricVcsRefCount{config: cfg} +func newMetricVcsChangeDuration(cfg MetricConfig) metricVcsChangeDuration { + m := metricVcsChangeDuration{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -222,22 +224,22 @@ func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { return m } -type metricVcsRefLinesDelta struct { +type metricVcsChangeTimeToApproval 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 vcs.ref.lines_delta metric with initial data. -func (m *metricVcsRefLinesDelta) init() { - m.data.SetName("vcs.ref.lines_delta") - m.data.SetDescription("The number of lines added/removed in a ref (branch) relative to the default branch (trunk).") - m.data.SetUnit("{line}") +// init fills vcs.change.time_to_approval metric with initial data. +func (m *metricVcsChangeTimeToApproval) init() { + m.data.SetName("vcs.change.time_to_approval") + m.data.SetDescription("The amount of time it took a change (pull request) to go from open to approved.") + m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRefLinesDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsLineChangeTypeAttributeValue string) { +func (m *metricVcsChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -248,19 +250,17 @@ func (m *metricVcsRefLinesDelta) recordDataPoint(start pcommon.Timestamp, ts pco dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) - dp.Attributes().PutStr("vcs.line_change.type", vcsLineChangeTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRefLinesDelta) updateCapacity() { +func (m *metricVcsChangeTimeToApproval) 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 *metricVcsRefLinesDelta) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsChangeTimeToApproval) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -268,8 +268,8 @@ func (m *metricVcsRefLinesDelta) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRefLinesDelta(cfg MetricConfig) metricVcsRefLinesDelta { - m := metricVcsRefLinesDelta{config: cfg} +func newMetricVcsChangeTimeToApproval(cfg MetricConfig) metricVcsChangeTimeToApproval { + m := metricVcsChangeTimeToApproval{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -277,22 +277,22 @@ func newMetricVcsRefLinesDelta(cfg MetricConfig) metricVcsRefLinesDelta { return m } -type metricVcsRefRevisionsDelta struct { +type metricVcsChangeTimeToMerge 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 vcs.ref.revisions_delta metric with initial data. -func (m *metricVcsRefRevisionsDelta) init() { - m.data.SetName("vcs.ref.revisions_delta") - m.data.SetDescription("The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).") - m.data.SetUnit("{revision}") +// init fills vcs.change.time_to_merge metric with initial data. +func (m *metricVcsChangeTimeToMerge) init() { + m.data.SetName("vcs.change.time_to_merge") + m.data.SetDescription("The amount of time it took a change (pull request) to go from open to merged.") + m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRefRevisionsDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsRevisionDeltaDirectionAttributeValue string) { +func (m *metricVcsChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -303,19 +303,17 @@ func (m *metricVcsRefRevisionsDelta) recordDataPoint(start pcommon.Timestamp, ts dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) - dp.Attributes().PutStr("vcs.revision_delta.direction", vcsRevisionDeltaDirectionAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRefRevisionsDelta) updateCapacity() { +func (m *metricVcsChangeTimeToMerge) 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 *metricVcsRefRevisionsDelta) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsChangeTimeToMerge) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -323,8 +321,8 @@ func (m *metricVcsRefRevisionsDelta) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta { - m := metricVcsRefRevisionsDelta{config: cfg} +func newMetricVcsChangeTimeToMerge(cfg MetricConfig) metricVcsChangeTimeToMerge { + m := metricVcsChangeTimeToMerge{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -332,22 +330,22 @@ func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta return m } -type metricVcsRefTime struct { +type metricVcsContributorCount 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 vcs.ref.time metric with initial data. -func (m *metricVcsRefTime) init() { - m.data.SetName("vcs.ref.time") - m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.") - m.data.SetUnit("s") +// init fills vcs.contributor.count metric with initial data. +func (m *metricVcsContributorCount) init() { + m.data.SetName("vcs.contributor.count") + m.data.SetDescription("The number of unique contributors to a repository.") + m.data.SetUnit("{contributor}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { +func (m *metricVcsContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -357,19 +355,17 @@ func (m *metricVcsRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.T dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRefTime) updateCapacity() { +func (m *metricVcsContributorCount) 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 *metricVcsRefTime) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsContributorCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -377,8 +373,8 @@ func (m *metricVcsRefTime) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRefTime(cfg MetricConfig) metricVcsRefTime { - m := metricVcsRefTime{config: cfg} +func newMetricVcsContributorCount(cfg MetricConfig) metricVcsContributorCount { + m := metricVcsContributorCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -386,22 +382,22 @@ func newMetricVcsRefTime(cfg MetricConfig) metricVcsRefTime { return m } -type metricVcsRepositoryChangeCount struct { +type metricVcsRefCount 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 vcs.repository.change.count metric with initial data. -func (m *metricVcsRepositoryChangeCount) init() { - m.data.SetName("vcs.repository.change.count") - m.data.SetDescription("The number of changes (pull requests) in a repository, categorized by their state (either open or merged).") - m.data.SetUnit("{change}") +// init fills vcs.ref.count metric with initial data. +func (m *metricVcsRefCount) init() { + m.data.SetName("vcs.ref.count") + m.data.SetDescription("The number of refs of type branch in a repository.") + m.data.SetUnit("{ref}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { +func (m *metricVcsRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -410,19 +406,19 @@ func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp dp.SetTimestamp(ts) dp.SetIntValue(val) dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) - dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeCount) updateCapacity() { +func (m *metricVcsRefCount) 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 *metricVcsRepositoryChangeCount) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsRefCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -430,8 +426,8 @@ func (m *metricVcsRepositoryChangeCount) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryChangeCount(cfg MetricConfig) metricVcsRepositoryChangeCount { - m := metricVcsRepositoryChangeCount{config: cfg} +func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { + m := metricVcsRefCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -439,22 +435,22 @@ func newMetricVcsRepositoryChangeCount(cfg MetricConfig) metricVcsRepositoryChan return m } -type metricVcsRepositoryChangeDuration struct { +type metricVcsRefLinesDelta 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 vcs.repository.change.duration metric with initial data. -func (m *metricVcsRepositoryChangeDuration) init() { - m.data.SetName("vcs.repository.change.duration") - m.data.SetDescription("The time duration a change (pull request/merge request/changelist) has been in an open state.") - m.data.SetUnit("s") +// init fills vcs.ref.lines_delta metric with initial data. +func (m *metricVcsRefLinesDelta) init() { + m.data.SetName("vcs.ref.lines_delta") + m.data.SetDescription("The number of lines added/removed in a ref (branch) relative to the default branch (trunk).") + m.data.SetUnit("{line}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeDuration) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue string) { +func (m *metricVcsRefLinesDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsLineChangeTypeAttributeValue string) { if !m.config.Enabled { return } @@ -465,18 +461,19 @@ func (m *metricVcsRepositoryChangeDuration) recordDataPoint(start pcommon.Timest dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) - dp.Attributes().PutStr("vcs.change.state", vcsChangeStateAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) + dp.Attributes().PutStr("vcs.line_change.type", vcsLineChangeTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeDuration) updateCapacity() { +func (m *metricVcsRefLinesDelta) 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 *metricVcsRepositoryChangeDuration) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsRefLinesDelta) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -484,8 +481,8 @@ func (m *metricVcsRepositoryChangeDuration) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryChangeDuration(cfg MetricConfig) metricVcsRepositoryChangeDuration { - m := metricVcsRepositoryChangeDuration{config: cfg} +func newMetricVcsRefLinesDelta(cfg MetricConfig) metricVcsRefLinesDelta { + m := metricVcsRefLinesDelta{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -493,22 +490,22 @@ func newMetricVcsRepositoryChangeDuration(cfg MetricConfig) metricVcsRepositoryC return m } -type metricVcsRepositoryChangeTimeToApproval struct { +type metricVcsRefRevisionsDelta 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 vcs.repository.change.time_to_approval metric with initial data. -func (m *metricVcsRepositoryChangeTimeToApproval) init() { - m.data.SetName("vcs.repository.change.time_to_approval") - m.data.SetDescription("The amount of time it took a change (pull request) to go from open to approved.") - m.data.SetUnit("s") +// init fills vcs.ref.revisions_delta metric with initial data. +func (m *metricVcsRefRevisionsDelta) init() { + m.data.SetName("vcs.ref.revisions_delta") + m.data.SetDescription("The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).") + m.data.SetUnit("{revision}") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { +func (m *metricVcsRefRevisionsDelta) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string, vcsRevisionDeltaDirectionAttributeValue string) { if !m.config.Enabled { return } @@ -519,17 +516,19 @@ func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon. dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) + dp.Attributes().PutStr("vcs.revision_delta.direction", vcsRevisionDeltaDirectionAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeTimeToApproval) updateCapacity() { +func (m *metricVcsRefRevisionsDelta) 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 *metricVcsRepositoryChangeTimeToApproval) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsRefRevisionsDelta) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -537,8 +536,8 @@ func (m *metricVcsRepositoryChangeTimeToApproval) emit(metrics pmetric.MetricSli } } -func newMetricVcsRepositoryChangeTimeToApproval(cfg MetricConfig) metricVcsRepositoryChangeTimeToApproval { - m := metricVcsRepositoryChangeTimeToApproval{config: cfg} +func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta { + m := metricVcsRefRevisionsDelta{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -546,22 +545,22 @@ func newMetricVcsRepositoryChangeTimeToApproval(cfg MetricConfig) metricVcsRepos return m } -type metricVcsRepositoryChangeTimeToMerge struct { +type metricVcsRefTime 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 vcs.repository.change.time_to_merge metric with initial data. -func (m *metricVcsRepositoryChangeTimeToMerge) init() { - m.data.SetName("vcs.repository.change.time_to_merge") - m.data.SetDescription("The amount of time it took a change (pull request) to go from open to merged.") +// init fills vcs.ref.time metric with initial data. +func (m *metricVcsRefTime) init() { + m.data.SetName("vcs.ref.time") + m.data.SetDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.") m.data.SetUnit("s") m.data.SetEmptyGauge() m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) } -func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { +func (m *metricVcsRefTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -572,17 +571,18 @@ func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Tim dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.type", vcsRefHeadTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeTimeToMerge) updateCapacity() { +func (m *metricVcsRefTime) 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 *metricVcsRepositoryChangeTimeToMerge) emit(metrics pmetric.MetricSlice) { +func (m *metricVcsRefTime) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -590,8 +590,8 @@ func (m *metricVcsRepositoryChangeTimeToMerge) emit(metrics pmetric.MetricSlice) } } -func newMetricVcsRepositoryChangeTimeToMerge(cfg MetricConfig) metricVcsRepositoryChangeTimeToMerge { - m := metricVcsRepositoryChangeTimeToMerge{config: cfg} +func newMetricVcsRefTime(cfg MetricConfig) metricVcsRefTime { + m := metricVcsRefTime{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -651,23 +651,23 @@ func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { // 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. - resourceAttributeIncludeFilter map[string]filter.Filter - resourceAttributeExcludeFilter map[string]filter.Filter - metricVcsContributorCount metricVcsContributorCount - metricVcsRefCount metricVcsRefCount - metricVcsRefLinesDelta metricVcsRefLinesDelta - metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta - metricVcsRefTime metricVcsRefTime - metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount - metricVcsRepositoryChangeDuration metricVcsRepositoryChangeDuration - metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval - metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge - metricVcsRepositoryCount metricVcsRepositoryCount + 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. + resourceAttributeIncludeFilter map[string]filter.Filter + resourceAttributeExcludeFilter map[string]filter.Filter + metricVcsChangeCount metricVcsChangeCount + metricVcsChangeDuration metricVcsChangeDuration + metricVcsChangeTimeToApproval metricVcsChangeTimeToApproval + metricVcsChangeTimeToMerge metricVcsChangeTimeToMerge + metricVcsContributorCount metricVcsContributorCount + metricVcsRefCount metricVcsRefCount + metricVcsRefLinesDelta metricVcsRefLinesDelta + metricVcsRefRevisionsDelta metricVcsRefRevisionsDelta + metricVcsRefTime metricVcsRefTime + metricVcsRepositoryCount metricVcsRepositoryCount } // MetricBuilderOption applies changes to default metrics builder. @@ -690,22 +690,22 @@ func WithStartTime(startTime pcommon.Timestamp) MetricBuilderOption { func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...MetricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ - config: mbc, - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: settings.BuildInfo, - metricVcsContributorCount: newMetricVcsContributorCount(mbc.Metrics.VcsContributorCount), - metricVcsRefCount: newMetricVcsRefCount(mbc.Metrics.VcsRefCount), - metricVcsRefLinesDelta: newMetricVcsRefLinesDelta(mbc.Metrics.VcsRefLinesDelta), - metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), - metricVcsRefTime: newMetricVcsRefTime(mbc.Metrics.VcsRefTime), - metricVcsRepositoryChangeCount: newMetricVcsRepositoryChangeCount(mbc.Metrics.VcsRepositoryChangeCount), - metricVcsRepositoryChangeDuration: newMetricVcsRepositoryChangeDuration(mbc.Metrics.VcsRepositoryChangeDuration), - metricVcsRepositoryChangeTimeToApproval: newMetricVcsRepositoryChangeTimeToApproval(mbc.Metrics.VcsRepositoryChangeTimeToApproval), - metricVcsRepositoryChangeTimeToMerge: newMetricVcsRepositoryChangeTimeToMerge(mbc.Metrics.VcsRepositoryChangeTimeToMerge), - metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), - resourceAttributeIncludeFilter: make(map[string]filter.Filter), - resourceAttributeExcludeFilter: make(map[string]filter.Filter), + config: mbc, + startTime: pcommon.NewTimestampFromTime(time.Now()), + metricsBuffer: pmetric.NewMetrics(), + buildInfo: settings.BuildInfo, + metricVcsChangeCount: newMetricVcsChangeCount(mbc.Metrics.VcsChangeCount), + metricVcsChangeDuration: newMetricVcsChangeDuration(mbc.Metrics.VcsChangeDuration), + metricVcsChangeTimeToApproval: newMetricVcsChangeTimeToApproval(mbc.Metrics.VcsChangeTimeToApproval), + metricVcsChangeTimeToMerge: newMetricVcsChangeTimeToMerge(mbc.Metrics.VcsChangeTimeToMerge), + metricVcsContributorCount: newMetricVcsContributorCount(mbc.Metrics.VcsContributorCount), + metricVcsRefCount: newMetricVcsRefCount(mbc.Metrics.VcsRefCount), + metricVcsRefLinesDelta: newMetricVcsRefLinesDelta(mbc.Metrics.VcsRefLinesDelta), + metricVcsRefRevisionsDelta: newMetricVcsRefRevisionsDelta(mbc.Metrics.VcsRefRevisionsDelta), + metricVcsRefTime: newMetricVcsRefTime(mbc.Metrics.VcsRefTime), + metricVcsRepositoryCount: newMetricVcsRepositoryCount(mbc.Metrics.VcsRepositoryCount), + resourceAttributeIncludeFilter: make(map[string]filter.Filter), + resourceAttributeExcludeFilter: make(map[string]filter.Filter), } if mbc.ResourceAttributes.OrganizationName.MetricsInclude != nil { mb.resourceAttributeIncludeFilter["organization.name"] = filter.CreateFilter(mbc.ResourceAttributes.OrganizationName.MetricsInclude) @@ -789,15 +789,15 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) + mb.metricVcsChangeCount.emit(ils.Metrics()) + mb.metricVcsChangeDuration.emit(ils.Metrics()) + mb.metricVcsChangeTimeToApproval.emit(ils.Metrics()) + mb.metricVcsChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsContributorCount.emit(ils.Metrics()) mb.metricVcsRefCount.emit(ils.Metrics()) mb.metricVcsRefLinesDelta.emit(ils.Metrics()) mb.metricVcsRefRevisionsDelta.emit(ils.Metrics()) mb.metricVcsRefTime.emit(ils.Metrics()) - mb.metricVcsRepositoryChangeCount.emit(ils.Metrics()) - mb.metricVcsRepositoryChangeDuration.emit(ils.Metrics()) - mb.metricVcsRepositoryChangeTimeToApproval.emit(ils.Metrics()) - mb.metricVcsRepositoryChangeTimeToMerge.emit(ils.Metrics()) mb.metricVcsRepositoryCount.emit(ils.Metrics()) for _, op := range options { @@ -830,6 +830,26 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics return metrics } +// RecordVcsChangeCountDataPoint adds a data point to vcs.change.count metric. +func (mb *MetricsBuilder) RecordVcsChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState, vcsRepositoryNameAttributeValue string) { + mb.metricVcsChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) +} + +// RecordVcsChangeDurationDataPoint adds a data point to vcs.change.duration metric. +func (mb *MetricsBuilder) RecordVcsChangeDurationDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState) { + mb.metricVcsChangeDuration.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsChangeStateAttributeValue.String()) +} + +// RecordVcsChangeTimeToApprovalDataPoint adds a data point to vcs.change.time_to_approval metric. +func (mb *MetricsBuilder) RecordVcsChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { + mb.metricVcsChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) +} + +// RecordVcsChangeTimeToMergeDataPoint adds a data point to vcs.change.time_to_merge metric. +func (mb *MetricsBuilder) RecordVcsChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { + mb.metricVcsChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) +} + // RecordVcsContributorCountDataPoint adds a data point to vcs.contributor.count metric. func (mb *MetricsBuilder) RecordVcsContributorCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { mb.metricVcsContributorCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue) @@ -855,26 +875,6 @@ func (mb *MetricsBuilder) RecordVcsRefTimeDataPoint(ts pcommon.Timestamp, val in mb.metricVcsRefTime.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsRefHeadTypeAttributeValue.String()) } -// RecordVcsRepositoryChangeCountDataPoint adds a data point to vcs.repository.change.count metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeCountDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState, vcsRepositoryNameAttributeValue string) { - mb.metricVcsRepositoryChangeCount.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsChangeStateAttributeValue.String(), vcsRepositoryNameAttributeValue) -} - -// RecordVcsRepositoryChangeDurationDataPoint adds a data point to vcs.repository.change.duration metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeDurationDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string, vcsChangeStateAttributeValue AttributeVcsChangeState) { - mb.metricVcsRepositoryChangeDuration.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue, vcsChangeStateAttributeValue.String()) -} - -// RecordVcsRepositoryChangeTimeToApprovalDataPoint adds a data point to vcs.repository.change.time_to_approval metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToApproval.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) -} - -// RecordVcsRepositoryChangeTimeToMergeDataPoint adds a data point to vcs.repository.change.time_to_merge metric. -func (mb *MetricsBuilder) RecordVcsRepositoryChangeTimeToMergeDataPoint(ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { - mb.metricVcsRepositoryChangeTimeToMerge.recordDataPoint(mb.startTime, ts, val, vcsRepositoryURLFullAttributeValue, vcsRepositoryNameAttributeValue, vcsRefHeadNameAttributeValue) -} - // RecordVcsRepositoryCountDataPoint adds a data point to vcs.repository.count metric. func (mb *MetricsBuilder) RecordVcsRepositoryCountDataPoint(ts pcommon.Timestamp, val int64) { mb.metricVcsRepositoryCount.recordDataPoint(mb.startTime, ts, val) diff --git a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go index 0d02c6dbb08b..34a1f3a1f72e 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -68,40 +68,40 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount := 0 allMetricsCount := 0 + defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") + mb.RecordVcsChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) + mb.RecordVcsChangeDurationDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsChangeStateOpen) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRefLinesDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsLineChangeTypeAdded) + mb.RecordVcsChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) + mb.RecordVcsChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") - defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) + mb.RecordVcsContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") + mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeDurationDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsChangeStateOpen) + mb.RecordVcsRefLinesDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsLineChangeTypeAdded) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") + mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") + mb.RecordVcsRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ @@ -132,13 +132,13 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { - case "vcs.contributor.count": - assert.False(t, validatedMetrics["vcs.contributor.count"], "Found a duplicate in the metrics slice: vcs.contributor.count") - validatedMetrics["vcs.contributor.count"] = true + case "vcs.change.count": + assert.False(t, validatedMetrics["vcs.change.count"], "Found a duplicate in the metrics slice: vcs.change.count") + validatedMetrics["vcs.change.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 unique contributors to a repository.", ms.At(i).Description()) - assert.Equal(t, "{contributor}", ms.At(i).Unit()) + assert.Equal(t, "The number of changes (pull requests) in a repository, categorized by their state (either open or merged).", ms.At(i).Description()) + assert.Equal(t, "{change}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -147,16 +147,19 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.change.state") + assert.True(t, ok) + assert.EqualValues(t, "open", attrVal.Str()) attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - case "vcs.ref.count": - assert.False(t, validatedMetrics["vcs.ref.count"], "Found a duplicate in the metrics slice: vcs.ref.count") - validatedMetrics["vcs.ref.count"] = true + case "vcs.change.duration": + assert.False(t, validatedMetrics["vcs.change.duration"], "Found a duplicate in the metrics slice: vcs.change.duration") + validatedMetrics["vcs.change.duration"] = 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 refs of type branch in a repository.", ms.At(i).Description()) - assert.Equal(t, "{ref}", ms.At(i).Unit()) + assert.Equal(t, "The time duration a change (pull request/merge request/changelist) has been in an open state.", 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()) @@ -168,16 +171,19 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.ref.lines_delta": - assert.False(t, validatedMetrics["vcs.ref.lines_delta"], "Found a duplicate in the metrics slice: vcs.ref.lines_delta") - validatedMetrics["vcs.ref.lines_delta"] = true + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.change.state") + assert.True(t, ok) + assert.EqualValues(t, "open", attrVal.Str()) + case "vcs.change.time_to_approval": + assert.False(t, validatedMetrics["vcs.change.time_to_approval"], "Found a duplicate in the metrics slice: vcs.change.time_to_approval") + validatedMetrics["vcs.change.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 lines added/removed in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) - assert.Equal(t, "{line}", ms.At(i).Unit()) + assert.Equal(t, "The amount of time it took a change (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()) @@ -192,19 +198,13 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.line_change.type") - assert.True(t, ok) - assert.EqualValues(t, "added", attrVal.Str()) - case "vcs.ref.revisions_delta": - assert.False(t, validatedMetrics["vcs.ref.revisions_delta"], "Found a duplicate in the metrics slice: vcs.ref.revisions_delta") - validatedMetrics["vcs.ref.revisions_delta"] = true + case "vcs.change.time_to_merge": + assert.False(t, validatedMetrics["vcs.change.time_to_merge"], "Found a duplicate in the metrics slice: vcs.change.time_to_merge") + validatedMetrics["vcs.change.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 number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).", ms.At(i).Description()) - assert.Equal(t, "{revision}", ms.At(i).Unit()) + assert.Equal(t, "The amount of time it took a change (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()) assert.Equal(t, ts, dp.Timestamp()) @@ -219,19 +219,13 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.revision_delta.direction") - assert.True(t, ok) - assert.EqualValues(t, "ahead", attrVal.Str()) - case "vcs.ref.time": - assert.False(t, validatedMetrics["vcs.ref.time"], "Found a duplicate in the metrics slice: vcs.ref.time") - validatedMetrics["vcs.ref.time"] = true + case "vcs.contributor.count": + assert.False(t, validatedMetrics["vcs.contributor.count"], "Found a duplicate in the metrics slice: vcs.contributor.count") + validatedMetrics["vcs.contributor.count"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) + assert.Equal(t, "The number of unique contributors to a repository.", ms.At(i).Description()) + assert.Equal(t, "{contributor}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -243,19 +237,13 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") - assert.True(t, ok) - assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") - assert.True(t, ok) - assert.EqualValues(t, "branch", attrVal.Str()) - case "vcs.repository.change.count": - assert.False(t, validatedMetrics["vcs.repository.change.count"], "Found a duplicate in the metrics slice: vcs.repository.change.count") - validatedMetrics["vcs.repository.change.count"] = true + case "vcs.ref.count": + assert.False(t, validatedMetrics["vcs.ref.count"], "Found a duplicate in the metrics slice: vcs.ref.count") + validatedMetrics["vcs.ref.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 changes (pull requests) in a repository, categorized by their state (either open or merged).", ms.At(i).Description()) - assert.Equal(t, "{change}", ms.At(i).Unit()) + assert.Equal(t, "The number of refs of type branch in a repository.", ms.At(i).Description()) + assert.Equal(t, "{ref}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -264,19 +252,19 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.url.full-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.change.state") - assert.True(t, ok) - assert.EqualValues(t, "open", attrVal.Str()) attrVal, ok = dp.Attributes().Get("vcs.repository.name") assert.True(t, ok) assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) - case "vcs.repository.change.duration": - assert.False(t, validatedMetrics["vcs.repository.change.duration"], "Found a duplicate in the metrics slice: vcs.repository.change.duration") - validatedMetrics["vcs.repository.change.duration"] = true + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) + case "vcs.ref.lines_delta": + assert.False(t, validatedMetrics["vcs.ref.lines_delta"], "Found a duplicate in the metrics slice: vcs.ref.lines_delta") + validatedMetrics["vcs.ref.lines_delta"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The time duration a change (pull request/merge request/changelist) has been in an open state.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) + assert.Equal(t, "The number of lines added/removed in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) + assert.Equal(t, "{line}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -291,16 +279,19 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("vcs.change.state") + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") assert.True(t, ok) - assert.EqualValues(t, "open", attrVal.Str()) - case "vcs.repository.change.time_to_approval": - assert.False(t, validatedMetrics["vcs.repository.change.time_to_approval"], "Found a duplicate in the metrics slice: vcs.repository.change.time_to_approval") - validatedMetrics["vcs.repository.change.time_to_approval"] = true + assert.EqualValues(t, "branch", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.line_change.type") + assert.True(t, ok) + assert.EqualValues(t, "added", attrVal.Str()) + case "vcs.ref.revisions_delta": + assert.False(t, validatedMetrics["vcs.ref.revisions_delta"], "Found a duplicate in the metrics slice: vcs.ref.revisions_delta") + validatedMetrics["vcs.ref.revisions_delta"] = 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 change (pull request) to go from open to approved.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) + assert.Equal(t, "The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default).", ms.At(i).Description()) + assert.Equal(t, "{revision}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -315,12 +306,18 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) - case "vcs.repository.change.time_to_merge": - assert.False(t, validatedMetrics["vcs.repository.change.time_to_merge"], "Found a duplicate in the metrics slice: vcs.repository.change.time_to_merge") - validatedMetrics["vcs.repository.change.time_to_merge"] = true + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.revision_delta.direction") + assert.True(t, ok) + assert.EqualValues(t, "ahead", attrVal.Str()) + case "vcs.ref.time": + assert.False(t, validatedMetrics["vcs.ref.time"], "Found a duplicate in the metrics slice: vcs.ref.time") + validatedMetrics["vcs.ref.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 change (pull request) to go from open to merged.", ms.At(i).Description()) + assert.Equal(t, "Time a ref (branch) created from the default branch (trunk) has existed. The `vcs.ref.head.type` attribute will always be `branch`.", 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()) @@ -336,6 +333,9 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("vcs.ref.head.name") assert.True(t, ok) assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("vcs.ref.head.type") + assert.True(t, ok) + assert.EqualValues(t, "branch", attrVal.Str()) case "vcs.repository.count": assert.False(t, validatedMetrics["vcs.repository.count"], "Found a duplicate in the metrics slice: vcs.repository.count") validatedMetrics["vcs.repository.count"] = true diff --git a/receiver/githubreceiver/internal/metadata/testdata/config.yaml b/receiver/githubreceiver/internal/metadata/testdata/config.yaml index 3bbd11cf5130..87fe68de5cf0 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -1,6 +1,14 @@ default: all_set: metrics: + vcs.change.count: + enabled: true + vcs.change.duration: + enabled: true + vcs.change.time_to_approval: + enabled: true + vcs.change.time_to_merge: + enabled: true vcs.contributor.count: enabled: true vcs.ref.count: @@ -11,14 +19,6 @@ all_set: enabled: true vcs.ref.time: enabled: true - vcs.repository.change.count: - enabled: true - vcs.repository.change.duration: - enabled: true - vcs.repository.change.time_to_approval: - enabled: true - vcs.repository.change.time_to_merge: - enabled: true vcs.repository.count: enabled: true resource_attributes: @@ -28,6 +28,14 @@ all_set: enabled: true none_set: metrics: + vcs.change.count: + enabled: false + vcs.change.duration: + enabled: false + vcs.change.time_to_approval: + enabled: false + vcs.change.time_to_merge: + enabled: false vcs.contributor.count: enabled: false vcs.ref.count: @@ -38,14 +46,6 @@ none_set: enabled: false vcs.ref.time: enabled: false - vcs.repository.change.count: - enabled: false - vcs.repository.change.duration: - enabled: false - vcs.repository.change.time_to_approval: - enabled: false - vcs.repository.change.time_to_merge: - enabled: false vcs.repository.count: enabled: false resource_attributes: diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index cca97b9b3263..568193e6853c 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -138,8 +138,6 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { // See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/githubreceiver/internal/scraper/githubscraper/README.md#github-limitations // for more information as to why `BehindBy` and `AheadBy` are // swapped. - // ghs.mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType) - // ghs.mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType) ghs.mb.RecordVcsRefRevisionsDeltaDataPoint(now, int64(branch.Compare.BehindBy), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsRevisionDeltaDirectionAhead) ghs.mb.RecordVcsRefRevisionsDeltaDataPoint(now, int64(branch.Compare.AheadBy), url, branch.Repository.Name, branch.Name, refType, metadata.AttributeVcsRevisionDeltaDirectionBehind) @@ -180,24 +178,24 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { age := getAge(pr.CreatedAt, pr.MergedAt) - ghs.mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(now, age, url, name, pr.HeadRefName) + ghs.mb.RecordVcsChangeTimeToMergeDataPoint(now, age, url, name, pr.HeadRefName) } else { open++ age := getAge(pr.CreatedAt, now.AsTime()) - ghs.mb.RecordVcsRepositoryChangeDurationDataPoint(now, age, url, name, pr.HeadRefName, metadata.AttributeVcsChangeStateOpen) + ghs.mb.RecordVcsChangeDurationDataPoint(now, age, url, name, pr.HeadRefName, metadata.AttributeVcsChangeStateOpen) if pr.Reviews.TotalCount > 0 { age := getAge(pr.CreatedAt, pr.Reviews.Nodes[0].CreatedAt) - ghs.mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(now, age, url, name, pr.HeadRefName) + ghs.mb.RecordVcsChangeTimeToApprovalDataPoint(now, age, url, name, pr.HeadRefName) } } } - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(open), url, metadata.AttributeVcsChangeStateOpen, name) - ghs.mb.RecordVcsRepositoryChangeCountDataPoint(now, int64(merged), url, metadata.AttributeVcsChangeStateMerged, name) + ghs.mb.RecordVcsChangeCountDataPoint(now, int64(open), url, metadata.AttributeVcsChangeStateOpen, name) + ghs.mb.RecordVcsChangeCountDataPoint(now, int64(merged), url, metadata.AttributeVcsChangeStateMerged, name) mux.Unlock() }() } diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 1bcf3ccd746d..5e38a6fe04f6 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -10,6 +10,76 @@ resourceMetrics: schemaUrl: https://opentelemetry.io/schemas/1.27.0 scopeMetrics: - metrics: + - description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). + gauge: + dataPoints: + - asInt: "1" + attributes: + - key: vcs.change.state + value: + stringValue: merged + - key: vcs.repository.name + value: + stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "1" + attributes: + - key: vcs.change.state + value: + stringValue: open + - key: vcs.repository.name + value: + stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.change.count + unit: '{change}' + - description: The time duration a change (pull request/merge request/changelist) has been in an open state. + gauge: + dataPoints: + - asInt: "9223372036" + attributes: + - key: vcs.change.state + value: + stringValue: open + - key: vcs.ref.head.name + value: + stringValue: "" + - key: vcs.repository.name + value: + stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.change.duration + unit: s + - description: The amount of time it took a change (pull request) to go from open to merged. + gauge: + dataPoints: + - asInt: "0" + attributes: + - key: vcs.ref.head.name + value: + stringValue: "" + - key: vcs.repository.name + value: + stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: '{ false false }' + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.change.time_to_merge + unit: s - description: The number of refs of type branch in a repository. gauge: dataPoints: @@ -135,76 +205,6 @@ resourceMetrics: timeUnixNano: "2000000" name: vcs.ref.time unit: s - - description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). - gauge: - dataPoints: - - asInt: "1" - attributes: - - key: vcs.change.state - value: - stringValue: merged - - key: vcs.repository.name - value: - stringValue: repo1 - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - - asInt: "1" - attributes: - - key: vcs.change.state - value: - stringValue: open - - key: vcs.repository.name - value: - stringValue: repo1 - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.change.count - unit: '{change}' - - description: The time duration a change (pull request/merge request/changelist) has been in an open state. - gauge: - dataPoints: - - asInt: "9223372036" - attributes: - - key: vcs.change.state - value: - stringValue: open - - key: vcs.ref.head.name - value: - stringValue: "" - - key: vcs.repository.name - value: - stringValue: repo1 - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.change.duration - unit: s - - description: The amount of time it took a change (pull request) to go from open to merged. - gauge: - dataPoints: - - asInt: "0" - attributes: - - key: vcs.ref.head.name - value: - stringValue: "" - - key: vcs.repository.name - value: - stringValue: repo1 - - key: vcs.repository.url.full - value: - stringValue: '{ false false }' - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: vcs.repository.change.time_to_merge - unit: s - description: The number of repositories in an organization. gauge: dataPoints: diff --git a/receiver/githubreceiver/metadata.yaml b/receiver/githubreceiver/metadata.yaml index 7ddeb2b00dc7..687b547fcb08 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -99,28 +99,28 @@ metrics: gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name] - vcs.repository.change.duration: + vcs.change.duration: enabled: true description: The time duration a change (pull request/merge request/changelist) has been in an open state. unit: s gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.change.state] - vcs.repository.change.time_to_merge: + vcs.change.time_to_merge: enabled: true description: The amount of time it took a change (pull request) to go from open to merged. unit: s gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] - vcs.repository.change.time_to_approval: + vcs.change.time_to_approval: enabled: true description: The amount of time it took a change (pull request) to go from open to approved. unit: s gauge: value_type: int attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] - vcs.repository.change.count: + vcs.change.count: description: The number of changes (pull requests) in a repository, categorized by their state (either open or merged). enabled: true gauge: From 6ec1e64c7c21a8de245044f8d635fc95c4b7d012 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 13:50:41 -0500 Subject: [PATCH 12/18] [chore] adjust type on genqlient uri --- .../githubscraper/generated_graphql.go | 5 ++--- .../scraper/githubscraper/genqlient.yaml | 2 +- .../scraper/githubscraper/github_scraper.go | 4 ++-- .../testdata/scraper/expected_happy_path.yaml | 20 +++++++++---------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go index de96d4ae168a..6965cbd66422 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go @@ -6,7 +6,6 @@ import ( "context" "encoding/json" "fmt" - "net/url" "time" "github.com/Khan/genqlient/graphql" @@ -751,7 +750,7 @@ type SearchNodeRepository struct { // The Ref associated with the repository's default branch. DefaultBranchRef SearchNodeDefaultBranchRef `json:"defaultBranchRef"` // The HTTP URL for this repository - Url url.URL `json:"url"` + Url string `json:"url"` } // GetTypename returns SearchNodeRepository.Typename, and is useful for accessing the field via an interface. @@ -769,7 +768,7 @@ func (v *SearchNodeRepository) GetDefaultBranchRef() SearchNodeDefaultBranchRef } // GetUrl returns SearchNodeRepository.Url, and is useful for accessing the field via an interface. -func (v *SearchNodeRepository) GetUrl() url.URL { return v.Url } +func (v *SearchNodeRepository) GetUrl() string { return v.Url } // SearchNodeUser includes the requested fields of the GraphQL type User. // The GraphQL type's documentation follows. diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml index 088eab8ef795..63726bd18a53 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml @@ -12,5 +12,5 @@ bindings: DateTime: type: time.Time URI: - type: net/url.URL + type: string diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 568193e6853c..307529361041 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -8,7 +8,7 @@ package githubscraper // import "github.com/open-telemetry/opentelemetry-collect import ( "context" "errors" - "fmt" + // "fmt" "net/http" "sync" "time" @@ -105,7 +105,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { for _, repo := range repos { repo := repo name := repo.Name - url := fmt.Sprint(repo.Url) + url := repo.Url trunk := repo.DefaultBranchRef.Name now := now diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml index 5e38a6fe04f6..5eca16f1a549 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml +++ b/receiver/githubreceiver/internal/scraper/githubscraper/testdata/scraper/expected_happy_path.yaml @@ -23,7 +23,7 @@ resourceMetrics: stringValue: repo1 - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - asInt: "1" @@ -36,7 +36,7 @@ resourceMetrics: stringValue: repo1 - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.change.count @@ -57,7 +57,7 @@ resourceMetrics: stringValue: repo1 - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.change.duration @@ -75,7 +75,7 @@ resourceMetrics: stringValue: repo1 - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.change.time_to_merge @@ -93,7 +93,7 @@ resourceMetrics: stringValue: repo1 - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.ref.count @@ -117,7 +117,7 @@ resourceMetrics: stringValue: "" - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - asInt: "9" @@ -136,7 +136,7 @@ resourceMetrics: stringValue: "" - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.ref.lines_delta @@ -157,7 +157,7 @@ resourceMetrics: stringValue: "" - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" - key: vcs.revision_delta.direction value: stringValue: ahead @@ -176,7 +176,7 @@ resourceMetrics: stringValue: "" - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" - key: vcs.revision_delta.direction value: stringValue: behind @@ -200,7 +200,7 @@ resourceMetrics: stringValue: "" - key: vcs.repository.url.full value: - stringValue: '{ false false }' + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" name: vcs.ref.time From 6debd2559b2762bae95a38ca1386e2ea8ba58689 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 14:13:54 -0500 Subject: [PATCH 13/18] [receiver/github] change scraper key from github to scraper --- receiver/githubreceiver/config_test.go | 4 ++-- receiver/githubreceiver/factory.go | 2 +- .../githubreceiver/internal/scraper/githubscraper/factory.go | 1 + receiver/githubreceiver/testdata/config.yaml | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/receiver/githubreceiver/config_test.go b/receiver/githubreceiver/config_test.go index 2ff23f5c7eaa..5c310c84fe97 100644 --- a/receiver/githubreceiver/config_test.go +++ b/receiver/githubreceiver/config_test.go @@ -41,7 +41,7 @@ func TestLoadConfig(t *testing.T) { defaultConfigGitHubReceiver := factory.CreateDefaultConfig() defaultConfigGitHubReceiver.(*Config).Scrapers = map[string]internal.Config{ - metadata.Type.String(): (&githubscraper.Factory{}).CreateDefaultConfig(), + githubscraper.TypeStr: (&githubscraper.Factory{}).CreateDefaultConfig(), } defaultConfigGitHubReceiver.(*Config).WebHook = WebHook{ @@ -67,7 +67,7 @@ func TestLoadConfig(t *testing.T) { InitialDelay: 1 * time.Second, }, Scrapers: map[string]internal.Config{ - metadata.Type.String(): (&githubscraper.Factory{}).CreateDefaultConfig(), + githubscraper.TypeStr: (&githubscraper.Factory{}).CreateDefaultConfig(), }, WebHook: WebHook{ ServerConfig: confighttp.ServerConfig{ diff --git a/receiver/githubreceiver/factory.go b/receiver/githubreceiver/factory.go index fa15220b890f..285b77a99f07 100644 --- a/receiver/githubreceiver/factory.go +++ b/receiver/githubreceiver/factory.go @@ -33,7 +33,7 @@ const ( var ( scraperFactories = map[string]internal.ScraperFactory{ - metadata.Type.String(): &githubscraper.Factory{}, + githubscraper.TypeStr: &githubscraper.Factory{}, } errConfigNotValid = errors.New("configuration is not valid for the github receiver") diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/factory.go b/receiver/githubreceiver/internal/scraper/githubscraper/factory.go index eb82e1c5c6f4..0100adef1bb6 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/factory.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/factory.go @@ -18,6 +18,7 @@ import ( // This file implements factory for the GitHub Scraper as part of the GitHub Receiver const ( + TypeStr = "scraper" defaultHTTPTimeout = 15 * time.Second ) diff --git a/receiver/githubreceiver/testdata/config.yaml b/receiver/githubreceiver/testdata/config.yaml index 6ab79edfcbd2..612b31b0213a 100644 --- a/receiver/githubreceiver/testdata/config.yaml +++ b/receiver/githubreceiver/testdata/config.yaml @@ -3,7 +3,7 @@ receivers: initial_delay: 1s collection_interval: 60s scrapers: - github: + scraper: webhook: endpoint: localhost:8080 read_timeout: "500ms" @@ -18,7 +18,7 @@ receivers: initial_delay: 1s collection_interval: 30s scrapers: - github: + scraper: webhook: endpoint: localhost:8080 read_timeout: "500ms" From 5e7134188a662a30fa3641fa0ccbfd30a7dabe31 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 14:16:06 -0500 Subject: [PATCH 14/18] [chore] update readme with new key --- receiver/githubreceiver/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/receiver/githubreceiver/README.md b/receiver/githubreceiver/README.md index 48c318f1d064..ecff5133e990 100644 --- a/receiver/githubreceiver/README.md +++ b/receiver/githubreceiver/README.md @@ -38,8 +38,8 @@ The collection interval is common to all scrapers and is set to 30 seconds by de github: collection_interval: #default = 30s recommended 300s scrapers: - : - : + scraper/config-1: + scraper/config-2: ... ``` @@ -55,7 +55,7 @@ receivers: initial_delay: 1s collection_interval: 60s scrapers: - github: + scraper: metrics: vcs.repository.contributor.count: enabled: true From 5a83e59be53e83cc0491fde4d1ae4b15036c6a31 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 15:28:45 -0500 Subject: [PATCH 15/18] [chore] add changelog --- .chloggen/gh-semconv-1.28plus.yaml | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .chloggen/gh-semconv-1.28plus.yaml diff --git a/.chloggen/gh-semconv-1.28plus.yaml b/.chloggen/gh-semconv-1.28plus.yaml new file mode 100644 index 000000000000..8964d7dc3b90 --- /dev/null +++ b/.chloggen/gh-semconv-1.28plus.yaml @@ -0,0 +1,47 @@ +# 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: githubreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Update metric names to match VCS Metric Semantic Conventions and scraper key name. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [] + +# (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: | + * Change the `github` scraper key to `scraper` + * Add `vcs.repository.url.full` attribute + * Change attribute `repository.name` to `vcs.repository.name` + * Change attribute `ref.name` to `vcs.ref.head.name` + * Change attribute `ref.type` to `vcs.ref.head.type` + * Change attribute `change.state` to `vcs.change.state` + * Add attribute `vcs.revision_delta.direction` with `ahead` and `behind` values + * Change metric `vcs.repository.ref.revisions_ahead` to `vcs.ref.revisions_delta` with `vcs.revision_delta.direction=ahead` + * Change metric `vcs.repository.ref.revisions_behind` to `vcs.ref.revisions_delta` with `vcs.revision_delta.direction=behind` + * Change metric `vcs.repository.ref.count` to `vcs.ref.count` + * Change metric `vcs.repository.ref.time` to `vcs.ref.time` + * Add attribute `vcs.line_change.type` with `added` and `removed` values + * Change metric `vcs.repository.ref.lines_added` to `vcs.ref.lines_delta` with `vcs.line_change.type=added` + * Change metric `vcs.repository.ref.lines_removed` to `vcs.ref.lines_delta` with `vcs.line_change.type=removed` + * Change metric `vcs.repository.contributor.count` to `vcs.contributor.count` + * Change metric `vcs.repository.change.time_open` to `vcs.change.duration` with `vcs.change.state=open` + * Change metric `vcs.repository.change.time_to_approval` to `vcs.change.time_to_approval` + * Change metric `vcs.repository.change.time_to_merge` to `vcs.change.time_to_merge` + * Change metric `vcs.repository.change.count` to `vcs.change.count` + + +# 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: [user] From 9cdfc6c58f73ef313b144a518ae8d6e7388924d0 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 15:35:44 -0500 Subject: [PATCH 16/18] [chore] checks --- receiver/githubreceiver/generated_package_test.go | 3 ++- receiver/githubreceiver/go.mod | 6 +++--- receiver/githubreceiver/go.sum | 12 ++++++------ .../internal/scraper/githubscraper/factory.go | 2 +- .../internal/scraper/githubscraper/github_scraper.go | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/receiver/githubreceiver/generated_package_test.go b/receiver/githubreceiver/generated_package_test.go index 23f7579ccba3..08b03a769078 100644 --- a/receiver/githubreceiver/generated_package_test.go +++ b/receiver/githubreceiver/generated_package_test.go @@ -3,8 +3,9 @@ package githubreceiver import ( - "go.uber.org/goleak" "testing" + + "go.uber.org/goleak" ) func TestMain(m *testing.M) { diff --git a/receiver/githubreceiver/go.mod b/receiver/githubreceiver/go.mod index e1c04a63c70c..8d9b926813b7 100644 --- a/receiver/githubreceiver/go.mod +++ b/receiver/githubreceiver/go.mod @@ -133,13 +133,13 @@ require ( go.opentelemetry.io/otel/trace v1.32.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/net v0.31.0 // indirect + golang.org/x/net v0.32.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect gonum.org/v1/gonum v0.15.1 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect - google.golang.org/grpc v1.68.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/grpc v1.68.1 // indirect google.golang.org/protobuf v1.35.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/receiver/githubreceiver/go.sum b/receiver/githubreceiver/go.sum index 60ff09ee8298..77054a1af344 100644 --- a/receiver/githubreceiver/go.sum +++ b/receiver/githubreceiver/go.sum @@ -295,8 +295,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -324,10 +324,10 @@ gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0= gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o= google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= -google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0= -google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0= +google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw= google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/factory.go b/receiver/githubreceiver/internal/scraper/githubscraper/factory.go index 0100adef1bb6..101a0ef64e31 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/factory.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/factory.go @@ -18,7 +18,7 @@ import ( // This file implements factory for the GitHub Scraper as part of the GitHub Receiver const ( - TypeStr = "scraper" + TypeStr = "scraper" defaultHTTPTimeout = 15 * time.Second ) diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 307529361041..a044b75ee82f 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -105,7 +105,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { for _, repo := range repos { repo := repo name := repo.Name - url := repo.Url + url := repo.Url trunk := repo.DefaultBranchRef.Name now := now From f0772db506ffbacb56c6c9a2b4c882ad3910aac0 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 16:00:39 -0500 Subject: [PATCH 17/18] [chore] add pr issue number to changelog --- .chloggen/gh-semconv-1.28plus.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/gh-semconv-1.28plus.yaml b/.chloggen/gh-semconv-1.28plus.yaml index 8964d7dc3b90..7f6e5f68b086 100644 --- a/.chloggen/gh-semconv-1.28plus.yaml +++ b/.chloggen/gh-semconv-1.28plus.yaml @@ -10,7 +10,7 @@ component: githubreceiver note: Update metric names to match VCS Metric Semantic Conventions and scraper key name. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [] +issues: [36714] # (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. From 83a55c03e28a47ddc72e3b3c5c02029d1cc86917 Mon Sep 17 00:00:00 2001 From: Adriel Perkins Date: Sat, 7 Dec 2024 16:06:46 -0500 Subject: [PATCH 18/18] [chore] remove commented out import --- .../internal/scraper/githubscraper/github_scraper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index a044b75ee82f..10b9ee8434f4 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -8,7 +8,6 @@ package githubscraper // import "github.com/open-telemetry/opentelemetry-collect import ( "context" "errors" - // "fmt" "net/http" "sync" "time"