diff --git a/.chloggen/gh-semconv-1.28plus.yaml b/.chloggen/gh-semconv-1.28plus.yaml new file mode 100644 index 000000000000..7f6e5f68b086 --- /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: [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. +# 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] 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 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/documentation.md b/receiver/githubreceiver/documentation.md index a95f684a1fd7..160cb6a90c26 100644 --- a/receiver/githubreceiver/documentation.md +++ b/receiver/githubreceiver/documentation.md @@ -12,7 +12,7 @@ metrics: enabled: false ``` -### vcs.repository.change.count +### vcs.change.count The number of changes (pull requests) in a repository, categorized by their state (either open or merged). @@ -24,12 +24,13 @@ The number of changes (pull requests) in a repository, categorized by their stat | Name | Description | Values | | ---- | ----------- | ------ | -| change.state | The state of a change (pull request) | Str: ``open``, ``merged`` | -| repository.name | The name of a VCS repository | Any Str | +| 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.repository.change.time_open +### vcs.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 | | ---- | ----------- | ---------- | @@ -39,10 +40,12 @@ The amount of time a change (pull request) has been open. | Name | Description | Values | | ---- | ----------- | ------ | -| repository.name | The name of a VCS repository | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| 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 +### vcs.change.time_to_approval The amount of time it took a change (pull request) to go from open to approved. @@ -54,10 +57,11 @@ The amount of time it took a change (pull request) to go from open to approved. | Name | Description | Values | | ---- | ----------- | ------ | -| repository.name | The name of a VCS repository | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| 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.repository.change.time_to_merge +### vcs.change.time_to_merge The amount of time it took a change (pull request) to go from open to merged. @@ -69,18 +73,11 @@ The amount of time it took a change (pull request) to go from open to merged. | Name | Description | Values | | ---- | ----------- | ------ | -| repository.name | The name of a VCS repository | Any Str | -| ref.name | The name of a VCS branch | Any Str | +| 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.repository.count - -The number of repositories in an organization. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {repository} | Gauge | Int | - -### vcs.repository.ref.count +### vcs.ref.count The number of refs of type branch in a repository. @@ -92,28 +89,13 @@ The number of refs of type branch in a repository. | Name | Description | Values | | ---- | ----------- | ------ | -| 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 - -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 | -| ---- | ----------- | ------ | -| 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.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_deleted +### vcs.ref.lines_delta -The number of lines deleted in a ref (branch) relative to the default branch (trunk). +The number of lines added/removed in a ref (branch) relative to the default branch (trunk). | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -123,13 +105,15 @@ The number of lines deleted in a ref (branch) relative to the default branch (tr | Name | Description | Values | | ---- | ----------- | ------ | -| 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.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.repository.ref.revisions_ahead +### vcs.ref.revisions_delta -The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). +The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -139,41 +123,36 @@ The number of revisions (commits) a ref (branch) is ahead of the default branch | Name | Description | Values | | ---- | ----------- | ------ | -| 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.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.ref.revisions_behind +### vcs.ref.time -The number of revisions (commits) a ref (branch) is behind the default branch (trunk). +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 | | ---- | ----------- | ---------- | -| {revision} | Gauge | Int | +| s | Gauge | Int | #### Attributes | Name | Description | Values | | ---- | ----------- | ------ | -| 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.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 +### vcs.repository.count -Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`. +The number of repositories in an organization. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| s | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| 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`` | +| {repository} | Gauge | Int | ## Optional Metrics @@ -185,7 +164,7 @@ metrics: enabled: true ``` -### vcs.repository.contributor.count +### vcs.contributor.count The number of unique contributors to a repository. @@ -197,7 +176,8 @@ The number of unique contributors to a repository. | Name | Description | Values | | ---- | ----------- | ------ | -| repository.name | The name of a VCS repository | Any Str | +| 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 | ## Resource Attributes 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/go.mod b/receiver/githubreceiver/go.mod index f90c112a9a16..47fb7e5851a3 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 1c24e95a7d26..0fa8cf1b4329 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/metadata/generated_config.go b/receiver/githubreceiver/internal/metadata/generated_config.go index d16a2a6316c2..2a44c29d06b2 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config.go +++ b/receiver/githubreceiver/internal/metadata/generated_config.go @@ -28,56 +28,48 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for github metrics. type MetricsConfig struct { - 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"` - VcsRepositoryRefRevisionsAhead MetricConfig `mapstructure:"vcs.repository.ref.revisions_ahead"` - VcsRepositoryRefRevisionsBehind MetricConfig `mapstructure:"vcs.repository.ref.revisions_behind"` - VcsRepositoryRefTime MetricConfig `mapstructure:"vcs.repository.ref.time"` + 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{ - VcsRepositoryChangeCount: MetricConfig{ + VcsChangeCount: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeOpen: MetricConfig{ + VcsChangeDuration: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeToApproval: MetricConfig{ + VcsChangeTimeToApproval: MetricConfig{ Enabled: true, }, - VcsRepositoryChangeTimeToMerge: MetricConfig{ + VcsChangeTimeToMerge: MetricConfig{ Enabled: true, }, - VcsRepositoryContributorCount: MetricConfig{ + VcsContributorCount: MetricConfig{ Enabled: false, }, - VcsRepositoryCount: MetricConfig{ - Enabled: true, - }, - VcsRepositoryRefCount: MetricConfig{ + VcsRefCount: MetricConfig{ Enabled: true, }, - VcsRepositoryRefLinesAdded: MetricConfig{ + VcsRefLinesDelta: MetricConfig{ Enabled: true, }, - VcsRepositoryRefLinesDeleted: MetricConfig{ + VcsRefRevisionsDelta: MetricConfig{ Enabled: true, }, - VcsRepositoryRefRevisionsAhead: MetricConfig{ + VcsRefTime: MetricConfig{ Enabled: true, }, - VcsRepositoryRefRevisionsBehind: MetricConfig{ - Enabled: true, - }, - VcsRepositoryRefTime: MetricConfig{ + 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 4747288dcaea..ec0861b334e8 100644 --- a/receiver/githubreceiver/internal/metadata/generated_config_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_config_test.go @@ -25,18 +25,16 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - 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}, - VcsRepositoryRefRevisionsAhead: MetricConfig{Enabled: true}, - VcsRepositoryRefRevisionsBehind: MetricConfig{Enabled: true}, - VcsRepositoryRefTime: 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}, @@ -48,18 +46,16 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - 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}, - VcsRepositoryRefRevisionsAhead: MetricConfig{Enabled: false}, - VcsRepositoryRefRevisionsBehind: MetricConfig{Enabled: false}, - VcsRepositoryRefTime: 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 440151dea48f..0f2537a3068f 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics.go @@ -13,126 +13,126 @@ 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, } -// AttributeRefType specifies the a value ref.type attribute. -type AttributeRefType int +// AttributeVcsLineChangeType specifies the a value vcs.line_change.type attribute. +type AttributeVcsLineChangeType int const ( - _ AttributeRefType = iota - AttributeRefTypeBranch - AttributeRefTypeTag + _ AttributeVcsLineChangeType = iota + AttributeVcsLineChangeTypeAdded + AttributeVcsLineChangeTypeRemoved ) -// String returns the string representation of the AttributeRefType. -func (av AttributeRefType) String() string { +// String returns the string representation of the AttributeVcsLineChangeType. +func (av AttributeVcsLineChangeType) String() string { switch av { - case AttributeRefTypeBranch: - return "branch" - case AttributeRefTypeTag: - return "tag" + case AttributeVcsLineChangeTypeAdded: + return "added" + case AttributeVcsLineChangeTypeRemoved: + return "removed" } return "" } -// MapAttributeRefType is a helper map of string to AttributeRefType attribute value. -var MapAttributeRefType = map[string]AttributeRefType{ - "branch": AttributeRefTypeBranch, - "tag": AttributeRefTypeTag, +// MapAttributeVcsLineChangeType is a helper map of string to AttributeVcsLineChangeType attribute value. +var MapAttributeVcsLineChangeType = map[string]AttributeVcsLineChangeType{ + "added": AttributeVcsLineChangeTypeAdded, + "removed": AttributeVcsLineChangeTypeRemoved, } -type metricVcsRepositoryChangeCount 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. -} +// AttributeVcsRefHeadType specifies the a value vcs.ref.head.type attribute. +type AttributeVcsRefHeadType int -// 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}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} +const ( + _ AttributeVcsRefHeadType = iota + AttributeVcsRefHeadTypeBranch + AttributeVcsRefHeadTypeTag +) -func (m *metricVcsRepositoryChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, changeStateAttributeValue string, repositoryNameAttributeValue string) { - if !m.config.Enabled { - return +// String returns the string representation of the AttributeVcsRefHeadType. +func (av AttributeVcsRefHeadType) String() string { + switch av { + case AttributeVcsRefHeadTypeBranch: + return "branch" + case AttributeVcsRefHeadTypeTag: + return "tag" } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("change.state", changeStateAttributeValue) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + return "" } -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeCount) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() - } +// MapAttributeVcsRefHeadType is a helper map of string to AttributeVcsRefHeadType attribute value. +var MapAttributeVcsRefHeadType = map[string]AttributeVcsRefHeadType{ + "branch": AttributeVcsRefHeadTypeBranch, + "tag": AttributeVcsRefHeadTypeTag, } -// 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) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() +// 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 "" } -func newMetricVcsRepositoryChangeCount(cfg MetricConfig) metricVcsRepositoryChangeCount { - m := metricVcsRepositoryChangeCount{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m +// MapAttributeVcsRevisionDeltaDirection is a helper map of string to AttributeVcsRevisionDeltaDirection attribute value. +var MapAttributeVcsRevisionDeltaDirection = map[string]AttributeVcsRevisionDeltaDirection{ + "ahead": AttributeVcsRevisionDeltaDirectionAhead, + "behind": AttributeVcsRevisionDeltaDirectionBehind, } -type metricVcsRepositoryChangeTimeOpen 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.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.") - m.data.SetUnit("s") +// 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 *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsChangeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsChangeStateAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -140,19 +140,20 @@ func (m *metricVcsRepositoryChangeTimeOpen) recordDataPoint(start pcommon.Timest dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + 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 *metricVcsRepositoryChangeTimeOpen) 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 *metricVcsRepositoryChangeTimeOpen) 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 *metricVcsRepositoryChangeTimeOpen) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryChangeTimeOpen(cfg MetricConfig) metricVcsRepositoryChangeTimeOpen { - m := metricVcsRepositoryChangeTimeOpen{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 newMetricVcsRepositoryChangeTimeOpen(cfg MetricConfig) metricVcsRepositoryC return m } -type metricVcsRepositoryChangeTimeToApproval 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.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.") +// 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 *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue 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 } @@ -192,19 +193,21 @@ func (m *metricVcsRepositoryChangeTimeToApproval) recordDataPoint(start pcommon. dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + 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 *metricVcsRepositoryChangeTimeToApproval) 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 *metricVcsRepositoryChangeTimeToApproval) 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()) @@ -212,8 +215,8 @@ func (m *metricVcsRepositoryChangeTimeToApproval) emit(metrics pmetric.MetricSli } } -func newMetricVcsRepositoryChangeTimeToApproval(cfg MetricConfig) metricVcsRepositoryChangeTimeToApproval { - m := metricVcsRepositoryChangeTimeToApproval{config: cfg} +func newMetricVcsChangeDuration(cfg MetricConfig) metricVcsChangeDuration { + m := metricVcsChangeDuration{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -221,22 +224,22 @@ func newMetricVcsRepositoryChangeTimeToApproval(cfg MetricConfig) metricVcsRepos return m } -type metricVcsRepositoryChangeTimeToMerge 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.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.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 *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string) { +func (m *metricVcsChangeTimeToApproval) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -244,19 +247,20 @@ func (m *metricVcsRepositoryChangeTimeToMerge) recordDataPoint(start pcommon.Tim dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryChangeTimeToMerge) 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 *metricVcsRepositoryChangeTimeToMerge) 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()) @@ -264,8 +268,8 @@ func (m *metricVcsRepositoryChangeTimeToMerge) emit(metrics pmetric.MetricSlice) } } -func newMetricVcsRepositoryChangeTimeToMerge(cfg MetricConfig) metricVcsRepositoryChangeTimeToMerge { - m := metricVcsRepositoryChangeTimeToMerge{config: cfg} +func newMetricVcsChangeTimeToApproval(cfg MetricConfig) metricVcsChangeTimeToApproval { + m := metricVcsChangeTimeToApproval{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -273,22 +277,22 @@ func newMetricVcsRepositoryChangeTimeToMerge(cfg MetricConfig) metricVcsReposito return m } -type metricVcsRepositoryContributorCount 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.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}") +// 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 *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string) { +func (m *metricVcsChangeTimeToMerge) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadNameAttributeValue string) { if !m.config.Enabled { return } @@ -296,18 +300,20 @@ func (m *metricVcsRepositoryContributorCount) recordDataPoint(start pcommon.Time dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.repository.url.full", vcsRepositoryURLFullAttributeValue) + dp.Attributes().PutStr("vcs.repository.name", vcsRepositoryNameAttributeValue) + dp.Attributes().PutStr("vcs.ref.head.name", vcsRefHeadNameAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryContributorCount) 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 *metricVcsRepositoryContributorCount) 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()) @@ -315,8 +321,8 @@ func (m *metricVcsRepositoryContributorCount) emit(metrics pmetric.MetricSlice) } } -func newMetricVcsRepositoryContributorCount(cfg MetricConfig) metricVcsRepositoryContributorCount { - m := metricVcsRepositoryContributorCount{config: cfg} +func newMetricVcsChangeTimeToMerge(cfg MetricConfig) metricVcsChangeTimeToMerge { + m := metricVcsChangeTimeToMerge{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -324,21 +330,22 @@ func newMetricVcsRepositoryContributorCount(cfg MetricConfig) metricVcsRepositor return m } -type metricVcsRepositoryCount 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.repository.count metric with initial data. -func (m *metricVcsRepositoryCount) init() { - m.data.SetName("vcs.repository.count") - m.data.SetDescription("The number of repositories in an organization.") - m.data.SetUnit("{repository}") +// 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 *metricVcsRepositoryCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { +func (m *metricVcsContributorCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string) { if !m.config.Enabled { return } @@ -346,17 +353,19 @@ func (m *metricVcsRepositoryCount) recordDataPoint(start pcommon.Timestamp, ts p 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 *metricVcsRepositoryCount) 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 *metricVcsRepositoryCount) 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()) @@ -364,8 +373,8 @@ func (m *metricVcsRepositoryCount) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { - m := metricVcsRepositoryCount{config: cfg} +func newMetricVcsContributorCount(cfg MetricConfig) metricVcsContributorCount { + m := metricVcsContributorCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -373,74 +382,22 @@ func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { return m } -type metricVcsRepositoryRefCount 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.ref.count metric with initial data. -func (m *metricVcsRepositoryRefCount) init() { - m.data.SetName("vcs.repository.ref.count") +// 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 *metricVcsRepositoryRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refTypeAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) -} - -// 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. - 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, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue string) { +func (m *metricVcsRefCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, vcsRepositoryURLFullAttributeValue string, vcsRepositoryNameAttributeValue string, vcsRefHeadTypeAttributeValue string) { if !m.config.Enabled { return } @@ -448,20 +405,20 @@ func (m *metricVcsRepositoryRefLinesAdded) recordDataPoint(start pcommon.Timesta dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + 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 *metricVcsRepositoryRefLinesAdded) 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 *metricVcsRepositoryRefLinesAdded) 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()) @@ -469,8 +426,8 @@ func (m *metricVcsRepositoryRefLinesAdded) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryRefLinesAdded(cfg MetricConfig) metricVcsRepositoryRefLinesAdded { - m := metricVcsRepositoryRefLinesAdded{config: cfg} +func newMetricVcsRefCount(cfg MetricConfig) metricVcsRefCount { + m := metricVcsRefCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -478,22 +435,22 @@ func newMetricVcsRepositoryRefLinesAdded(cfg MetricConfig) metricVcsRepositoryRe return m } -type metricVcsRepositoryRefLinesDeleted 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.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).") +// 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 *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue 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 } @@ -501,20 +458,22 @@ func (m *metricVcsRepositoryRefLinesDeleted) recordDataPoint(start pcommon.Times dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + 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 *metricVcsRepositoryRefLinesDeleted) 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 *metricVcsRepositoryRefLinesDeleted) 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()) @@ -522,8 +481,8 @@ func (m *metricVcsRepositoryRefLinesDeleted) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryRefLinesDeleted(cfg MetricConfig) metricVcsRepositoryRefLinesDeleted { - m := metricVcsRepositoryRefLinesDeleted{config: cfg} +func newMetricVcsRefLinesDelta(cfg MetricConfig) metricVcsRefLinesDelta { + m := metricVcsRefLinesDelta{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -531,22 +490,22 @@ func newMetricVcsRepositoryRefLinesDeleted(cfg MetricConfig) metricVcsRepository return m } -type metricVcsRepositoryRefRevisionsAhead 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.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).") +// 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 *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue 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 } @@ -554,20 +513,22 @@ func (m *metricVcsRepositoryRefRevisionsAhead) recordDataPoint(start pcommon.Tim dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + 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 *metricVcsRepositoryRefRevisionsAhead) 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 *metricVcsRepositoryRefRevisionsAhead) 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()) @@ -575,8 +536,8 @@ func (m *metricVcsRepositoryRefRevisionsAhead) emit(metrics pmetric.MetricSlice) } } -func newMetricVcsRepositoryRefRevisionsAhead(cfg MetricConfig) metricVcsRepositoryRefRevisionsAhead { - m := metricVcsRepositoryRefRevisionsAhead{config: cfg} +func newMetricVcsRefRevisionsDelta(cfg MetricConfig) metricVcsRefRevisionsDelta { + m := metricVcsRefRevisionsDelta{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -584,22 +545,22 @@ func newMetricVcsRepositoryRefRevisionsAhead(cfg MetricConfig) metricVcsReposito return m } -type metricVcsRepositoryRefRevisionsBehind 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.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}") +// 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 *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, repositoryNameAttributeValue string, refNameAttributeValue string, refTypeAttributeValue 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 } @@ -607,20 +568,21 @@ func (m *metricVcsRepositoryRefRevisionsBehind) recordDataPoint(start pcommon.Ti dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) + 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() { +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 *metricVcsRepositoryRefRevisionsBehind) 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()) @@ -628,8 +590,8 @@ func (m *metricVcsRepositoryRefRevisionsBehind) emit(metrics pmetric.MetricSlice } } -func newMetricVcsRepositoryRefRevisionsBehind(cfg MetricConfig) metricVcsRepositoryRefRevisionsBehind { - m := metricVcsRepositoryRefRevisionsBehind{config: cfg} +func newMetricVcsRefTime(cfg MetricConfig) metricVcsRefTime { + m := metricVcsRefTime{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -637,22 +599,21 @@ func newMetricVcsRepositoryRefRevisionsBehind(cfg MetricConfig) metricVcsReposit return m } -type metricVcsRepositoryRefTime struct { +type metricVcsRepositoryCount 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 `ref.type` attribute will always be `branch`.") - m.data.SetUnit("s") +// init fills vcs.repository.count metric with initial data. +func (m *metricVcsRepositoryCount) init() { + m.data.SetName("vcs.repository.count") + m.data.SetDescription("The number of repositories in an organization.") + m.data.SetUnit("{repository}") m.data.SetEmptyGauge() - 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 *metricVcsRepositoryCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { if !m.config.Enabled { return } @@ -660,20 +621,17 @@ func (m *metricVcsRepositoryRefTime) recordDataPoint(start pcommon.Timestamp, ts dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) - dp.Attributes().PutStr("repository.name", repositoryNameAttributeValue) - dp.Attributes().PutStr("ref.name", refNameAttributeValue) - dp.Attributes().PutStr("ref.type", refTypeAttributeValue) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricVcsRepositoryRefTime) updateCapacity() { +func (m *metricVcsRepositoryCount) 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) { +func (m *metricVcsRepositoryCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -681,8 +639,8 @@ func (m *metricVcsRepositoryRefTime) emit(metrics pmetric.MetricSlice) { } } -func newMetricVcsRepositoryRefTime(cfg MetricConfig) metricVcsRepositoryRefTime { - m := metricVcsRepositoryRefTime{config: cfg} +func newMetricVcsRepositoryCount(cfg MetricConfig) metricVcsRepositoryCount { + m := metricVcsRepositoryCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -693,25 +651,23 @@ func newMetricVcsRepositoryRefTime(cfg MetricConfig) metricVcsRepositoryRefTime // 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 - metricVcsRepositoryChangeCount metricVcsRepositoryChangeCount - metricVcsRepositoryChangeTimeOpen metricVcsRepositoryChangeTimeOpen - metricVcsRepositoryChangeTimeToApproval metricVcsRepositoryChangeTimeToApproval - metricVcsRepositoryChangeTimeToMerge metricVcsRepositoryChangeTimeToMerge - metricVcsRepositoryContributorCount metricVcsRepositoryContributorCount - metricVcsRepositoryCount metricVcsRepositoryCount - metricVcsRepositoryRefCount metricVcsRepositoryRefCount - metricVcsRepositoryRefLinesAdded metricVcsRepositoryRefLinesAdded - metricVcsRepositoryRefLinesDeleted metricVcsRepositoryRefLinesDeleted - metricVcsRepositoryRefRevisionsAhead metricVcsRepositoryRefRevisionsAhead - metricVcsRepositoryRefRevisionsBehind metricVcsRepositoryRefRevisionsBehind - metricVcsRepositoryRefTime metricVcsRepositoryRefTime + 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. @@ -734,24 +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, - 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), - 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), + 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) @@ -835,18 +789,16 @@ 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.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.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.metricVcsRepositoryCount.emit(ils.Metrics()) - 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 { op.apply(rm) @@ -878,64 +830,54 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics return 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) -} - -// 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) +// 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) } -// 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) +// 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()) } -// 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) +// 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) } -// 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) +// 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) } -// 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) -} - -// 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()) +// 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) } -// 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()) +// 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()) } -// 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()) +// 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()) } -// 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()) +// 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()) } -// 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()) +// 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()) } -// 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()) +// 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) } // 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..34a1f3a1f72e 100644 --- a/receiver/githubreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/githubreceiver/internal/metadata/generated_metrics_test.go @@ -70,50 +70,42 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeCountDataPoint(ts, 1, AttributeChangeStateOpen, "repository.name-val") + mb.RecordVcsChangeCountDataPoint(ts, 1, "vcs.repository.url.full-val", AttributeVcsChangeStateOpen, "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeOpenDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsChangeDurationDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsChangeStateOpen) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToApprovalDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsChangeTimeToApprovalDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryChangeTimeToMergeDataPoint(ts, 1, "repository.name-val", "ref.name-val") + mb.RecordVcsChangeTimeToMergeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val") allMetricsCount++ - mb.RecordVcsRepositoryContributorCountDataPoint(ts, 1, "repository.name-val") + mb.RecordVcsContributorCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val") defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryCountDataPoint(ts, 1) - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefCountDataPoint(ts, 1, "repository.name-val", AttributeRefTypeBranch) - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordVcsRepositoryRefLinesAddedDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRefCountDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefLinesDeletedDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRefLinesDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsLineChangeTypeAdded) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsAheadDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRefRevisionsDeltaDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch, AttributeVcsRevisionDeltaDirectionAhead) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefRevisionsBehindDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRefTimeDataPoint(ts, 1, "vcs.repository.url.full-val", "vcs.repository.name-val", "vcs.ref.head.name-val", AttributeVcsRefHeadTypeBranch) defaultMetricsCount++ allMetricsCount++ - mb.RecordVcsRepositoryRefTimeDataPoint(ts, 1, "repository.name-val", "ref.name-val", AttributeRefTypeBranch) + mb.RecordVcsRepositoryCountDataPoint(ts, 1) rb := mb.NewResourceBuilder() rb.SetOrganizationName("organization.name-val") @@ -140,9 +132,9 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { - 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.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 changes (pull requests) in a repository, categorized by their state (either open or merged).", ms.At(i).Description()) @@ -152,33 +144,42 @@ 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("vcs.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()) - 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 + assert.EqualValues(t, "vcs.repository.name-val", attrVal.Str()) + 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 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()) 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("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, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "ref.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 + 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 amount of time it took a change (pull request) to go from open to approved.", ms.At(i).Description()) @@ -188,15 +189,18 @@ 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("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "ref.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 + assert.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + 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 amount of time it took a change (pull request) to go from open to merged.", ms.At(i).Description()) @@ -206,15 +210,18 @@ 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("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "ref.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.EqualValues(t, "vcs.ref.head.name-val", attrVal.Str()) + 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()) @@ -224,24 +231,15 @@ 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, "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 - 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 repositories in an organization.", ms.At(i).Description()) - assert.Equal(t, "{repository}", 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()) - 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.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 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()) @@ -251,117 +249,105 @@ 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, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + 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, "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 - 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("repository.name") - assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") - assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + 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_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 + 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 deleted in a ref (branch) relative to the default branch (trunk).", ms.At(i).Description()) + 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("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("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "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": - 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 + 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 number of revisions (commits) a ref (branch) is ahead of the default branch (trunk).", ms.At(i).Description()) + 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("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("vcs.repository.name") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "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": - 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 + 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 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()) + 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("repository.name") + attrVal, ok := dp.Attributes().Get("vcs.repository.url.full") assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") + 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, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.type") + 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 + 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 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, "s", ms.At(i).Unit()) + assert.Equal(t, "The number of repositories in an organization.", ms.At(i).Description()) + assert.Equal(t, "{repository}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) - attrVal, ok := dp.Attributes().Get("repository.name") - assert.True(t, ok) - assert.EqualValues(t, "repository.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.name") - assert.True(t, ok) - assert.EqualValues(t, "ref.name-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("ref.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 8dd9bc3c44a3..87fe68de5cf0 100644 --- a/receiver/githubreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/githubreceiver/internal/metadata/testdata/config.yaml @@ -1,29 +1,25 @@ default: all_set: metrics: - vcs.repository.change.count: + vcs.change.count: enabled: true - vcs.repository.change.time_open: + vcs.change.duration: enabled: true - vcs.repository.change.time_to_approval: + vcs.change.time_to_approval: enabled: true - vcs.repository.change.time_to_merge: + vcs.change.time_to_merge: enabled: true - vcs.repository.contributor.count: + vcs.contributor.count: enabled: true - vcs.repository.count: - enabled: true - vcs.repository.ref.count: + vcs.ref.count: enabled: true - vcs.repository.ref.lines_added: + vcs.ref.lines_delta: enabled: true - vcs.repository.ref.lines_deleted: + vcs.ref.revisions_delta: enabled: true - vcs.repository.ref.revisions_ahead: + vcs.ref.time: enabled: true - vcs.repository.ref.revisions_behind: - enabled: true - vcs.repository.ref.time: + vcs.repository.count: enabled: true resource_attributes: organization.name: @@ -32,29 +28,25 @@ all_set: enabled: true none_set: metrics: - vcs.repository.change.count: + vcs.change.count: enabled: false - vcs.repository.change.time_open: + vcs.change.duration: enabled: false - vcs.repository.change.time_to_approval: + vcs.change.time_to_approval: enabled: false - vcs.repository.change.time_to_merge: + vcs.change.time_to_merge: enabled: false - vcs.repository.contributor.count: + vcs.contributor.count: enabled: false - vcs.repository.count: - enabled: false - vcs.repository.ref.count: + vcs.ref.count: enabled: false - vcs.repository.ref.lines_added: + vcs.ref.lines_delta: enabled: false - vcs.repository.ref.lines_deleted: + vcs.ref.revisions_delta: enabled: false - vcs.repository.ref.revisions_ahead: + vcs.ref.time: enabled: false - vcs.repository.ref.revisions_behind: - enabled: false - vcs.repository.ref.time: + vcs.repository.count: enabled: false resource_attributes: organization.name: diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/factory.go b/receiver/githubreceiver/internal/scraper/githubscraper/factory.go index eb82e1c5c6f4..101a0ef64e31 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/internal/scraper/githubscraper/generated_graphql.go b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go index db5f5271fb75..6965cbd66422 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/generated_graphql.go @@ -749,6 +749,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 string `json:"url"` } // GetTypename returns SearchNodeRepository.Typename, and is useful for accessing the field via an interface. @@ -765,6 +767,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() string { return v.Url } + // SearchNodeUser includes the requested fields of the GraphQL type User. // The GraphQL type's documentation follows. // @@ -1463,6 +1468,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..7fd04b129c98 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 { @@ -130,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/genqlient.yaml b/receiver/githubreceiver/internal/scraper/githubscraper/genqlient.yaml index fc6183da61bf..63726bd18a53 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: string diff --git a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go index 70bf35f059fa..10b9ee8434f4 100644 --- a/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go +++ b/receiver/githubreceiver/internal/scraper/githubscraper/github_scraper.go @@ -104,6 +104,7 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { for _, repo := range repos { repo := repo name := repo.Name + url := repo.Url trunk := repo.DefaultBranchRef.Name now := now @@ -119,8 +120,8 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { // SetStartTimestamp call from having a nil pointer panic mux.Lock() - refType := metadata.AttributeRefTypeBranch - ghs.mb.RecordVcsRepositoryRefCountDataPoint(now, int64(count), name, refType) + refType := metadata.AttributeVcsRefHeadTypeBranch + ghs.mb.RecordVcsRefCountDataPoint(now, int64(count), url, name, refType) // Iterate through the refs (branches) populating the Branch focused // metrics @@ -136,8 +137,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.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 @@ -149,9 +150,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.RecordVcsRefTimeDataPoint(now, age, 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 @@ -159,7 +160,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.RecordVcsContributorCountDataPoint(now, int64(contribs), url, name) // Get change (pull request) data prs, err := ghs.getPullRequests(ctx, genClient, name) @@ -176,24 +177,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.RecordVcsChangeTimeToMergeDataPoint(now, age, url, name, pr.HeadRefName) } else { open++ age := getAge(pr.CreatedAt, now.AsTime()) - ghs.mb.RecordVcsRepositoryChangeTimeOpenDataPoint(now, age, name, pr.HeadRefName) + 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, name, pr.HeadRefName) + ghs.mb.RecordVcsChangeTimeToApprovalDataPoint(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.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 45cc52ce905d..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 @@ -15,169 +15,204 @@ resourceMetrics: dataPoints: - asInt: "1" attributes: - - key: change.state + - key: vcs.change.state value: stringValue: merged - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - asInt: "1" attributes: - - key: change.state + - key: vcs.change.state value: stringValue: open - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.change.count + name: vcs.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: ref.name + - key: vcs.change.state + value: + stringValue: open + - key: vcs.ref.head.name value: stringValue: "" - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.change.time_open + 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: ref.name + - key: vcs.ref.head.name value: stringValue: "" - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.change.time_to_merge + name: vcs.change.time_to_merge unit: s - - description: The number of repositories in an organization. - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - 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: ref.type + - key: vcs.ref.head.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name value: stringValue: repo1 + - key: vcs.repository.url.full + value: + stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.ref.count + name: vcs.ref.count unit: '{ref}' - - description: The number of lines added 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). gauge: dataPoints: - asInt: "10" attributes: - - key: ref.name + - key: vcs.line_change.type + value: + stringValue: added + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full value: stringValue: "" 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: ref.name + - key: vcs.line_change.type + value: + stringValue: removed + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full value: stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.ref.lines_deleted + name: vcs.ref.lines_delta unit: '{line}' - - description: The number of revisions (commits) a ref (branch) is ahead of the default branch (trunk). + - description: The number of revisions (commits) a ref (branch) is ahead/behind the branch from trunk (default). gauge: 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: repository.name + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full value: stringValue: "" + - key: vcs.revision_delta.direction + value: + stringValue: ahead 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: ref.name + - key: vcs.ref.head.name value: stringValue: main - - key: ref.type + - key: vcs.ref.head.type value: stringValue: branch - - key: repository.name + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full value: stringValue: "" + - key: vcs.revision_delta.direction + value: + stringValue: behind startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.ref.revisions_behind + name: vcs.ref.revisions_delta 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: repository.name + - key: vcs.repository.name + value: + stringValue: "" + - key: vcs.repository.url.full value: stringValue: "" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: vcs.repository.ref.time + name: vcs.ref.time unit: s + - description: The number of repositories in an organization. + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: vcs.repository.count + unit: '{repository}' 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 4a626b887216..687b547fcb08 100644 --- a/receiver/githubreceiver/metadata.yaml +++ b/receiver/githubreceiver/metadata.yaml @@ -22,24 +22,39 @@ resource_attributes: type: string attributes: - repository.name: - description: The name of a VCS repository + vcs.repository.url.full: + description: The canonical URL of the repository providing the complete HTTPS address. type: string - ref.name: - description: The name of a VCS branch + vcs.repository.name: + description: The name of the VCS repository. type: string - ref.type: - description: The type of ref (branch, tag). + vcs.ref.head.name: + description: The name of the VCS head reference (branch). + type: string + vcs.ref.head.type: + description: The type of the head reference (branch, tag). type: string enum: - branch - tag - change.state: + vcs.change.state: description: The state of a change (pull request) type: string enum: - open - merged + vcs.revision_delta.direction: + description: The type of revision comparison. + type: string + 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: @@ -49,83 +64,69 @@ 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: [repository.name, ref.type] - vcs.repository.ref.time: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.type] + vcs.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: [repository.name, ref.name, ref.type] - vcs.repository.ref.revisions_ahead: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type] + vcs.ref.revisions_delta: enabled: true - description: The number of revisions (commits) a ref (branch) is ahead of 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: [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] - 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] - vcs.repository.ref.lines_deleted: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.revision_delta.direction] + 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: [repository.name, ref.name, ref.type] - vcs.repository.contributor.count: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.ref.head.type, vcs.line_change.type] + vcs.contributor.count: enabled: false description: The number of unique contributors to a repository. unit: "{contributor}" gauge: value_type: int - attributes: [repository.name] - vcs.repository.change.time_open: + attributes: [vcs.repository.url.full, vcs.repository.name] + vcs.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: [repository.name, ref.name] - vcs.repository.change.time_to_merge: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name, vcs.change.state] + 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: [repository.name, ref.name] - vcs.repository.change.time_to_approval: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] + 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: [repository.name, ref.name] - vcs.repository.change.count: + attributes: [vcs.repository.url.full, vcs.repository.name, vcs.ref.head.name] + vcs.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, vcs.change.state, vcs.repository.name] tests: config: 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"