Skip to content

Commit

Permalink
[receiver/gitproviderreceiver] initial commit of git provider receive…
Browse files Browse the repository at this point in the history
…r skeleton (#23225)

**Description:**
Add initial commit of receiver component including the github sub
scraper. This receiver is in development and what is included here is
only a skeleton.
**Link to tracking Issue:**  

#22028

**Testing:**

- basic tests were added but as this is in development, it's only a
skeleton.

**Documentation:**

- basic set of documentation was added as part of the skeleton

---------

Co-authored-by: Andrzej Stencel <[email protected]>
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
3 people authored Aug 3, 2023
1 parent 326d026 commit 2cb7308
Show file tree
Hide file tree
Showing 32 changed files with 2,587 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .chloggen/gitmetricsreceiver-skeleton.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: gitproviderreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add the skeleton for the new gitproviderreceiver in development with accompanying github scraper."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [22028]

# (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:
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ receiver/filereceiver/ @open-telemetry/collect
receiver/filestatsreceiver/ @open-telemetry/collector-contrib-approvers @atoulme
receiver/flinkmetricsreceiver/ @open-telemetry/collector-contrib-approvers @jonathanwamsley @djaglowski
receiver/fluentforwardreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax
receiver/gitproviderreceiver/ @open-telemetry/collector-contrib-approvers @adrielp @astencel-sumo
receiver/googlecloudpubsubreceiver/ @open-telemetry/collector-contrib-approvers @alexvanboxel
receiver/googlecloudspannerreceiver/ @open-telemetry/collector-contrib-approvers @architjugran @varunraiko @kiranmayib
receiver/haproxyreceiver/ @open-telemetry/collector-contrib-approvers @atoulme @MovieStoreGuy
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ body:
- receiver/filestats
- receiver/flinkmetrics
- receiver/fluentforward
- receiver/gitprovider
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ body:
- receiver/filestats
- receiver/flinkmetrics
- receiver/fluentforward
- receiver/gitprovider
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ body:
- receiver/filestats
- receiver/flinkmetrics
- receiver/fluentforward
- receiver/gitprovider
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
Expand Down
10 changes: 5 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/gitproviderreceiver"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/googlecloudpubsubreceiver"
schedule:
Expand Down Expand Up @@ -1097,8 +1102,3 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/sqlserverreceiver"
schedule:
interval: "weekly"
day: "wednesday"
1 change: 1 addition & 0 deletions cmd/mdatagen/statusdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var distros = map[string]string{
"redhat": "https://github.com/os-observability/redhat-opentelemetry-collector",
"splunk": "https://github.com/signalfx/splunk-otel-collector",
"sumo": "https://github.com/SumoLogic/sumologic-otel-collector",
"liatrio": "https://github.com/liatrio/liatrio-otel-collector",
}

type Codeowners struct {
Expand Down
1 change: 1 addition & 0 deletions receiver/gitproviderreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
86 changes: 86 additions & 0 deletions receiver/gitproviderreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Git Provider Receiver

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: metrics |
| Distributions | [liatrio] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fgitprovider%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fgitprovider) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fgitprovider%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fgitprovider) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@adrielp](https://www.github.com/adrielp), [@astencel-sumo](https://www.github.com/astencel-sumo) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[liatrio]: https://github.com/liatrio/liatrio-otel-collector
<!-- end autogenerated section -->

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.

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.

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


## Getting Started

The collection interval is common to all scrapers and is set to 30 seconds by default.

> Note: Generally speaking, if the vendor allows for anonymous API calls, then you
> won't have to configure any authentication, but you may only see public repositories
> and organizations.
```yaml
gitprovider:
collection_interval: <duration> #default = 30s
scrapers:
<scraper1>:
<scraper2>:
...
```

A more complete example using the GitHub scraper with an authenticator is as follows:
```yaml
extensions:
basicauth/github:
client_auth:
username: ${env:GH_USER}
password: ${env:GH_PAT}

receivers:
gitprovider:
initial_delay: 1s
collection_interval: 60s
scrapers:
github:
github_org: myfancyorg
auth:
authenticator: basicauth/github
service:
extensions: [basicauth/github]
pipelines:
metrics:
receivers: [..., gitprovider]
processors: []
exporters: [...]
```
This receiver is developed upstream in the [liatrio-otel-collector distribution](https://github.com/liatrio/liatrio-otel-collector)
where a quick start exists with an [example config](https://github.com/liatrio/liatrio-otel-collector/blob/main/config/config.yaml)
The available scrapers are:
| Scraper | Description |
|----------|-------------------------|
| [github] | Git Metrics from [GitHub](https://github.com/) |
82 changes: 82 additions & 0 deletions receiver/gitproviderreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package gitproviderreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver"

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal/metadata"
)

const (
scrapersKey = "scrapers"
)

// Config that is exposed to this github receiver through the OTEL config.yaml
type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
Scrapers map[string]internal.Config `mapstructure:"scrapers"`
metadata.MetricsBuilderConfig `mapstructure:",squash"`
}

var _ component.Config = (*Config)(nil)
var _ confmap.Unmarshaler = (*Config)(nil)

// Validate the configuration passed through the OTEL config.yaml
func (cfg *Config) Validate() error {
if len(cfg.Scrapers) == 0 {
return errors.New("must specify at least one scraper")
}
return nil
}

// Unmarshal a config.Parser into the config struct.
func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error {
if componentParser == nil {
return nil
}

// load the non-dynamic config normally
err := componentParser.Unmarshal(cfg)
if err != nil {
return err
}

// dynamically load the individual collector configs based on the key name

cfg.Scrapers = map[string]internal.Config{}

scrapersSection, err := componentParser.Sub(scrapersKey)
if err != nil {
return err
}

for key := range scrapersSection.ToStringMap() {
factory, ok := getScraperFactory(key)
if !ok {
return fmt.Errorf("invalid scraper key: %q", key)
}

collectorCfg := factory.CreateDefaultConfig()
collectorSection, err := scrapersSection.Sub(key)
if err != nil {
return err
}

err = collectorSection.Unmarshal(collectorCfg, confmap.WithErrorUnused())
if err != nil {
return fmt.Errorf("error reading settings for scraper type %q: %w", key, err)
}

cfg.Scrapers[key] = collectorCfg
}

return nil
}
66 changes: 66 additions & 0 deletions receiver/gitproviderreceiver/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package gitproviderreceiver

import (
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal/scraper/githubscraper"
)

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

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

require.NoError(t, err)
require.NotNil(t, cfg)

assert.Equal(t, len(cfg.Receivers), 2)

r0 := cfg.Receivers[component.NewID(metadata.Type)]
defaultConfigGitHubScraper := factory.CreateDefaultConfig()
defaultConfigGitHubScraper.(*Config).Scrapers = map[string]internal.Config{
githubscraper.TypeStr: (&githubscraper.Factory{}).CreateDefaultConfig(),
}

assert.Equal(t, defaultConfigGitHubScraper, r0)

r1 := cfg.Receivers[component.NewIDWithName(metadata.Type, "customname")].(*Config)
expectedConfig := &Config{
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
CollectionInterval: 30 * time.Second,
InitialDelay: 1 * time.Second,
},
Scrapers: map[string]internal.Config{
githubscraper.TypeStr: (&githubscraper.Factory{}).CreateDefaultConfig(),
},
}

assert.Equal(t, expectedConfig, r1)
}

func TestLoadInvalidConfig_NoScrapers(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-noscrapers.yaml"), factories)

require.Contains(t, err.Error(), "must specify at least one scraper")
}
6 changes: 6 additions & 0 deletions receiver/gitproviderreceiver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

package gitproviderreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver"
Loading

0 comments on commit 2cb7308

Please sign in to comment.