Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/gitproviderreceiver] add repo branch and contrib count metrics #28885

Merged
merged 36 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
129665a
feat: add count metrics and update docs with test code
adrielp Oct 27, 2023
660a898
feat: add genqlient to gitprovider receiver, tools, and generate
adrielp Oct 27, 2023
dcefcc5
chore: add genqlient to makefile and run
adrielp Oct 28, 2023
009bd49
[receiver/gitproviderreceiver] add repo branch and contrib count metrics
adrielp Nov 3, 2023
8e180ac
chore: reset tools to main until feedback for tool install
adrielp Nov 3, 2023
0699f41
docs: update readme example
adrielp Nov 3, 2023
33d850a
test: add factor test for scraper and update format
adrielp Nov 3, 2023
4859a5a
chore: add changelog yaml
adrielp Nov 3, 2023
8eb6f7e
feat: add contrib count metric, address comments, and fix tests
adrielp Nov 8, 2023
07daa69
chore(ci): update generate command to include genqlient
adrielp Nov 8, 2023
1842d1e
chore: merge latest from main
adrielp Nov 8, 2023
1999577
chore: cleanup commented out section and add resource attributes
adrielp Nov 8, 2023
c0b4a8f
chore: merge latest from main and fix conflicts
adrielp Nov 8, 2023
1bc8e1b
chore: run updates and formatting
adrielp Nov 8, 2023
ff4137b
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 8, 2023
4cb5aeb
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 9, 2023
11d6606
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 10, 2023
67cf50e
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 10, 2023
f43ba58
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 10, 2023
d4b1f0a
chore: update createClients to use const for graph url
adrielp Nov 15, 2023
06cebb9
chore: remove checkOwnerTypeValid redundent functionality
adrielp Nov 15, 2023
1993384
refactor: cleanup redundent functions and returned values
adrielp Nov 15, 2023
418ad57
chore: use wait groups in go routine and fix login function
adrielp Nov 16, 2023
bc3b413
chore: convert chain to switch statement
adrielp Nov 16, 2023
bf160ff
Merge remote-tracking branch 'origin/main' into gitprovider-impl-2
adrielp Nov 16, 2023
f24a636
chore: run tidy after merge from main
adrielp Nov 16, 2023
7dfc7d3
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 16, 2023
c0456f1
chore: change logger debug formatting for search query
adrielp Nov 16, 2023
52c0c7b
chore: update generate command to leverage tools based on feedback and
adrielp Nov 16, 2023
b716fd6
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 16, 2023
492b921
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 16, 2023
d109466
chore: fmt tools.go as it's not picked up by workflow
adrielp Nov 16, 2023
1b1cee8
chore: update changelog per suggestion
adrielp Nov 22, 2023
b0d8d87
chore: revert formatting on mgo.mod in tools
adrielp Nov 22, 2023
3461be0
Merge branch 'main' into gitprovider-impl-2
adrielp Nov 22, 2023
946f3d7
chore: run make crosslink
adrielp Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions receiver/gitproviderreceiver/Makefile
adrielp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
include ../../Makefile.Common

GENQLIENT_DIRS = $(shell find . -type f -name 'genqlient.yaml' -exec dirname {} \;)

.PHONY: genqlient
genqlient:
for dir in $(GENQLIENT_DIRS); do \
cd $$dir && \
if [ -f genqlient.yaml ] && [ -f genqlient.graphql ] && [ -f schema.graphql ]; then \
echo "running genqlient in $$dir"; \
go run github.com/Khan/genqlient@latest; \
else \
echo "skipping genqlient in $$dir"; \
fi; \
done
49 changes: 28 additions & 21 deletions receiver/gitproviderreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@

The Git Provider receiver scrapes data from Git vendors.

As a starting point, this receiver can infer many of the same core git
metrics across vendors, while being able to receive additional data specific to
vendors.
As a starting point, this receiver can infer many of the same core git metrics across vendors, while being able to receive additional data specific to vendors.

The current default set of metrics common across all vendors can be found in
[documentation.md](./documentation.md).
The current default set of metrics common across all vendors can be found in [documentation.md](./documentation.md).

These default metrics can be used as leading indicators to the DORA metrics; helping
provide insight into modern-day engineering practices.
These default metrics can be used as leading indicators to the DORA metrics; helping provide insight into modern-day engineering practices.

## GitHub Metrics

The current metrics available via scraping from GitHub are:
* repository branch count
* repository branch time
* repository count
* repository branch count
* repository contributor count
* repository pull request time

- [x] Repository count
- [ ] Repository branch time
- [x] Repository branch count
- [x] Repository contributor count
- [ ] Repository pull request time
- [ ] Repository pull request merge time
- [ ] Repository pull request approval time
- [ ] Repository pull request deployment time

> Note: Some metrics may be disabled by default and have to be explicitly enabled.
> For example, the repository contributor count metric is one such metric. This is
> because this metric relies on the REST API which is subject to lower rate limits.

## Getting Started

Expand All @@ -50,25 +54,29 @@ gitprovider:
...
```

A more complete example using the GitHub scraper with an authenticator is as follows:
A more complete example using the GitHub & GitLab scrapers with authentication is as follows:

```yaml
extensions:
basicauth/github:
client_auth:
username: ${env:GH_USER}
password: ${env:GH_PAT}
bearertokenauth/github:
token: ${env:GH_PAT}

receivers:
gitprovider:
initial_delay: 1s
collection_interval: 60s
scrapers:
github:
metrics:
git.repository.contributor.count:
enabled: true
github_org: myfancyorg
search_query: "org:myfancyorg topic:o11yalltheway" #optional query override, defaults to "{org,user}:<github_org>"
endpoint: "https://selfmanagedenterpriseserver.com"
auth:
authenticator: basicauth/github
authenticator: bearertokenauth/github
service:
extensions: [basicauth/github]
extensions: [bearertokenauth/github]
pipelines:
metrics:
receivers: [..., gitprovider]
Expand All @@ -83,4 +91,3 @@ The available scrapers are:
| Scraper | Description |
|----------|-------------------------|
| [github] | Git Metrics from [GitHub](https://github.com/) |

50 changes: 50 additions & 0 deletions receiver/gitproviderreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"go.opentelemetry.io/collector/receiver/scraperhelper"

Expand Down Expand Up @@ -64,3 +65,52 @@ func TestLoadInvalidConfig_NoScrapers(t *testing.T) {

require.Contains(t, err.Error(), "must specify at least one scraper")
}

func TestLoadInvalidConfig_InvalidScraperKey(t *testing.T) {
factories, err := otelcoltest.NopFactories()
require.NoError(t, err)

factory := NewFactory()
factories.Receivers[metadata.Type] = factory
_, err = otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "config-invalidscraperkey.yaml"), factories)

require.Contains(t, err.Error(), "error reading configuration for \"gitprovider\": invalid scraper key: \"invalidscraperkey\"")
}

func TestConfig_Unmarshal(t *testing.T) {
type fields struct {
ScraperControllerSettings scraperhelper.ScraperControllerSettings
Scrapers map[string]internal.Config
MetricsBuilderConfig metadata.MetricsBuilderConfig
}

type args struct {
componentParser *confmap.Conf
}

tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "Empty Component Parser",
fields: fields{},
args: args{componentParser: nil},
wantErr: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cfg := &Config{
ScraperControllerSettings: test.fields.ScraperControllerSettings,
Scrapers: test.fields.Scrapers,
MetricsBuilderConfig: test.fields.MetricsBuilderConfig,
}
if err := cfg.Unmarshal(test.args.componentParser); (err != nil) != test.wantErr {
t.Errorf("Config.Unmarshal() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
42 changes: 11 additions & 31 deletions receiver/gitproviderreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ Number of branches that exist in the repository
| ---- | ----------- | ------ |
| repository.name | The full name of the Git repository | Any Str |

### git.repository.branch.time
### git.repository.count

Time the branch has existed
Number of repositories that exist in an organization

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Int |

#### Attributes
## Optional Metrics

| Name | Description | Values |
| ---- | ----------- | ------ |
| repository.name | The full name of the Git repository | Any Str |
| branch.name | The name of the branch in a given repository | Any Str |
The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration:

```yaml
metrics:
<metric_name>:
enabled: true
```

### git.repository.contributor.count

Expand All @@ -55,32 +58,9 @@ Total number of unique contributors to this repository
| ---- | ----------- | ------ |
| repository.name | The full name of the Git repository | Any Str |

### git.repository.count

Number of repositories that exist in an organization

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Int |

### git.repository.pull_request.time

Time the PR has been open

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Int |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| repository.name | The full name of the Git repository | Any Str |
| branch.name | The name of the branch in a given repository | Any Str |

## Resource Attributes

| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| git.vendor.name | | Any Str | true |
| git.vendor.name | The name of the Git vendor/provider (ie. GitHub / GitLab) | Any Str | true |
| organization.name | Git Organization or Project Name | Any Str | true |
6 changes: 4 additions & 2 deletions receiver/gitproviderreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitpro
go 1.20

require (
github.com/Khan/genqlient v0.6.0
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.88.1-0.20231026220224-6405e152a2d9
Expand All @@ -26,7 +27,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -62,6 +63,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.10 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.88.1-0.20231026220224-6405e152a2d9 // indirect
Expand Down Expand Up @@ -102,7 +104,7 @@ require (
golang.org/x/text v0.13.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
16 changes: 11 additions & 5 deletions receiver/gitproviderreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading