-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/gitproviderreceiver] initial commit of git provider receive…
…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
1 parent
326d026
commit 2cb7308
Showing
32 changed files
with
2,587 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.