Skip to content

Commit

Permalink
Merge branch 'release/0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Dec 22, 2021
2 parents 4dc8a98 + cfca257 commit 2597d39
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 218 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@

Export your favorite GitHub repositories to Prometheus

Use it _as a service_: https://gh.skuzzle.de
* Use it _as a service_: See https://gh.skuzzle.de for instructions
* Deploy it _on-premise_: `docker pull ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.5`

## On-Premise deployment with docker
This application can easily be run as a docker container in whatever environment you like:

```
docker run -p 8080:8080 \
-e WEB_ALLOWANONYMOUSSCRAPE=true
ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.4
-e WEB_ALLOWANONYMOUSSCRAPE=true \
ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.5
```

With _anonymous scraping_ allowed, you can now easily view the scrape results directly in the browser by navigating to
`https://your.docker.host:8080/YOUR-GITHUB-USERNAME/YOUR-REPOSITORY`.

The scraped repository can just as easiy be added as static scrape target to your prometheus' scrape configs:
The scraped repository can just as easy be added as static scrape target to your prometheus' scrape configs:

```
scrape_configs:
- job_name: CHANGE_ME
scrape_interval: 2m
metrics_path: /YOUR-GITHUB-USERNAME/YOUR-REPOSITORY
metrics_path: /YOUR-GITHUB-USERNAME/YOUR-REPOSITORY1,YOUR-REPOSITORY2
static_configs:
- targets: ['your.docker.host:8080']
```

In case you want to enforce authenticated scrapes only, use this configuration instead:
```
docker run -p 8080:8080 \
ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.4
ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.5
```

And
Expand Down
9 changes: 4 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!-- This file is auto generated during release from readme/RELEASE_NOTES.md -->

[![Coverage Status](https://coveralls.io/repos/github/skuzzle/gh-prom-exporter/badge.svg?branch=master)](https://coveralls.io/github/skuzzle/gh-prom-exporter?branch=master)
[![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS)
[![Coverage Status](https://coveralls.io/repos/github/skuzzle/gh-prom-exporter/badge.svg?branch=master)](https://coveralls.io/github/skuzzle/gh-prom-exporter?branch=master) [![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS)

* Configuration option to allow anonymous scraping
* Minimal documentation for on-premise setup
* Update to Spring-Boot 2.6.2
* [#1](https://github.com/skuzzle/gh-prom-exporter/issues/1) Allow to scrape multiple repository with single call

```
docker pull ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.4
docker pull ghcr.io/skuzzle/gh-prom-exporter/gh-prom-exporter:0.0.5
```
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>de.skuzzle</groupId>
<artifactId>skuzzle-parent</artifactId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>de.skuzzle.ghpromexporter</groupId>
<artifactId>gh-prom-exporter</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>

<name>gh-prom-exporter</name>
<description>Export GitHub repository metrics in prometheus format</description>
Expand All @@ -34,7 +34,7 @@
<docker.registry.name>ghcr.io</docker.registry.name>
<docker.image.name>${docker.registry.name}/${github.user}/${github.name}/${project.artifactId}</docker.image.name>

<spring-boot.version>2.6.1</spring-boot.version>
<spring-boot.version>2.6.2</spring-boot.version>
<spring-cloud.version>2021.0.0-RC1</spring-cloud.version>
<guava.version>31.0.1-jre</guava.version>
<github-api.version>1.135</github-api.version>
Expand Down
9 changes: 5 additions & 4 deletions readme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@

Export your favorite GitHub repositories to Prometheus

Use it _as a service_: https://gh.skuzzle.de
* Use it _as a service_: See https://gh.skuzzle.de for instructions
* Deploy it _on-premise_: `docker pull ${docker.image.name}:${project.version}`

## On-Premise deployment with docker
This application can easily be run as a docker container in whatever environment you like:

```
docker run -p 8080:8080 \
-e WEB_ALLOWANONYMOUSSCRAPE=true
-e WEB_ALLOWANONYMOUSSCRAPE=true \
${docker.image.name}:${project.version}
```

With _anonymous scraping_ allowed, you can now easily view the scrape results directly in the browser by navigating to
`https://your.docker.host:8080/YOUR-GITHUB-USERNAME/YOUR-REPOSITORY`.

The scraped repository can just as easiy be added as static scrape target to your prometheus' scrape configs:
The scraped repository can just as easy be added as static scrape target to your prometheus' scrape configs:

```
scrape_configs:
- job_name: CHANGE_ME
scrape_interval: 2m
metrics_path: /YOUR-GITHUB-USERNAME/YOUR-REPOSITORY
metrics_path: /YOUR-GITHUB-USERNAME/YOUR-REPOSITORY1,YOUR-REPOSITORY2
static_configs:
- targets: ['your.docker.host:8080']
```
Expand Down
7 changes: 3 additions & 4 deletions readme/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- This file is auto generated during release from readme/RELEASE_NOTES.md -->

[![Coverage Status](https://coveralls.io/repos/github/${github.user}/${github.name}/badge.svg?branch=${github.main-branch})](https://coveralls.io/github/${github.user}/${github.name}?branch=${github.main-branch})
[![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS)
[![Coverage Status](https://coveralls.io/repos/github/${github.user}/${github.name}/badge.svg?branch=${github.main-branch})](https://coveralls.io/github/${github.user}/${github.name}?branch=${github.main-branch}) [![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS)

* Configuration option to allow anonymous scraping
* Minimal documentation for on-premise setup
* Update to Spring-Boot 2.6.2
* [#1](https://github.com/skuzzle/gh-prom-exporter/issues/1) Allow to scrape multiple repository with single call

```
docker pull ${docker.image.name}:${project.version}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package de.skuzzle.ghpromexporter.scrape;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Summary;

public final class RepositoryMeters {

private static final String LABEL_REPOSITORY = "repository";
private static final String LABEL_OWNER = "owner";
private static final String NAMESPACE = "github";

private final CollectorRegistry registry;
private final Counter additions;
private final Counter deletions;
private final Counter stargazers;
private final Counter forks;
private final Counter open_issues;
private final Counter subscribers;
private final Counter watchers;
private final Counter size;
private final Summary scrapeDuration;

public static RepositoryMeters newRegistry() {
return new RepositoryMeters(new CollectorRegistry());
}

private RepositoryMeters(CollectorRegistry registry) {
this.registry = registry;
this.additions = Counter.build("additions", "Sum of additions over the last 52 weeks")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.deletions = Counter.build("deletions", "Negative sum of deletions over the last 52 weeks")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.stargazers = Counter.build("stargazers", "The repository's stargazer count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.forks = Counter.build("forks", "The repository's fork count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.open_issues = Counter.build("open_issues", "The repository's open issue count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.subscribers = Counter.build("subscribers", "The repository's subscriber count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.watchers = Counter.build("watchers", "The repository's watcher count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.size = Counter.build("size", "The repository's size in KB")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.scrapeDuration = Summary.build("scrape_duration", "Duration of a single scrape")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
}

public RepositoryMeters addRepositoryScrapeResults(ScrapeRepositoryRequest repository, RepositoryMetrics metrics) {
additions.labels(repository.owner(), repository.name()).inc(metrics.totalAdditions());
deletions.labels(repository.owner(), repository.name()).inc(metrics.totalDeletions());
stargazers.labels(repository.owner(), repository.name()).inc(metrics.stargazersCount());
forks.labels(repository.owner(), repository.name()).inc(metrics.forkCount());
open_issues.labels(repository.owner(), repository.name()).inc(metrics.openIssueCount());
subscribers.labels(repository.owner(), repository.name()).inc(metrics.subscriberCount());
watchers.labels(repository.owner(), repository.name()).inc(metrics.watchersCount());
size.labels(repository.owner(), repository.name()).inc(metrics.sizeInKb());
scrapeDuration.labels(repository.owner(), repository.name()).observe(metrics.scrapeDuration());
return this;
}

public CollectorRegistry registry() {
return this.registry;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package de.skuzzle.ghpromexporter.scrape;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Summary;

public record RepositoryMetrics(
long totalAdditions,
long totalDeletions,
Expand All @@ -13,61 +9,4 @@ public record RepositoryMetrics(
int subscriberCount,
int watchersCount,
int sizeInKb,
long scrapeDuration) {

public CollectorRegistry toRegistry(ScrapeRepositoryRequest repository) {
final Meters meters = new Meters();
meters.additions.labels(repository.owner(), repository.name())
.inc(totalAdditions());
meters.deletions.labels(repository.owner(), repository.name())
.inc(totalDeletions());
meters.stargazers.labels(repository.owner(), repository.name()).inc(stargazersCount());
meters.forks.labels(repository.owner(), repository.name()).inc(forkCount());
meters.open_issues.labels(repository.owner(), repository.name()).inc(openIssueCount());
meters.subscribers.labels(repository.owner(), repository.name()).inc(subscriberCount());
meters.watchers.labels(repository.owner(), repository.name()).inc(watchersCount());
meters.size.labels(repository.owner(), repository.name()).inc(sizeInKb());
meters.scrapeDuration.labels(repository.owner(), repository.name()).observe(scrapeDuration());
return meters.registry;
}

private static class Meters {
private static final String LABEL_REPOSITORY = "repository";
private static final String LABEL_OWNER = "owner";
private static final String NAMESPACE = "github";

private final CollectorRegistry registry;
private final Counter additions;
private final Counter deletions;
private final Counter stargazers;
private final Counter forks;
private final Counter open_issues;
private final Counter subscribers;
private final Counter watchers;
private final Counter size;
private final Summary scrapeDuration;

public Meters() {
this.registry = new CollectorRegistry();
this.additions = Counter.build("additions", "TBD")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.deletions = Counter.build("deletions", "TBD")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.stargazers = Counter.build("stargazers", "The repository's stargazer count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.forks = Counter.build("forks", "The repository's fork count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.open_issues = Counter.build("open_issues", "The repository's open issue count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.subscribers = Counter.build("subscribers", "The repository's subscriber count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.watchers = Counter.build("watchers", "The repository's watcher count")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.size = Counter.build("size", "The repository's size in KB")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
this.scrapeDuration = Summary.build("scrape_duration", "Duration of a single scrape")
.namespace(NAMESPACE).labelNames(LABEL_OWNER, LABEL_REPOSITORY).register(registry);
}

}
}
long scrapeDuration) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.skuzzle.ghpromexporter.web;

import java.util.Arrays;
import java.util.List;

import de.skuzzle.ghpromexporter.scrape.ScrapeRepositoryRequest;
import reactor.core.publisher.Flux;

final class MultipleRepositories {

private final String owner;
private final List<String> repositories;

private MultipleRepositories(String owner, List<String> repositories) {
this.owner = owner;
this.repositories = repositories;
}

public static MultipleRepositories parse(String owner, String repositoriesString) {
final String[] repositories = repositoriesString.split(",");
return new MultipleRepositories(owner, Arrays.asList(repositories));
}

Flux<ScrapeRepositoryRequest> requests() {
return Flux.fromStream(repositories.stream()
.map(repository -> ScrapeRepositoryRequest.of(owner, repository)));
}
}
Loading

0 comments on commit 2597d39

Please sign in to comment.