Skip to content

Commit

Permalink
[chore] update metric types to match semantic conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
adrielp committed May 3, 2024
1 parent b7317df commit 8c24669
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
10 changes: 5 additions & 5 deletions receiver/gitproviderreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Number of commits a branch is ahead of the default branch.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {branch} | Gauge | Int |
| {commit} | Gauge | Int |
#### Attributes
Expand All @@ -33,7 +33,7 @@ Number of commits a branch is behing the default branch.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {branch} | Gauge | Int |
| {commit} | Gauge | Int |
#### Attributes
Expand Down Expand Up @@ -62,7 +62,7 @@ Count of lines added to code in a branch
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {branch} | Gauge | Int |
| {line} | Gauge | Int |
#### Attributes
Expand All @@ -77,7 +77,7 @@ Count of lines deleted from code in a branch
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {branch} | Gauge | Int |
| {line} | Gauge | Int |
#### Attributes
Expand All @@ -92,7 +92,7 @@ Time the branch has existed.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {branch} | Gauge | Int |
| s | Gauge | Int |
#### Attributes
Expand Down

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.

Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ func (ghs *githubScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
// Iterate through the branches populating the Branch focused
// metrics
for _, branch := range branches {
// Check if the branch is the default branch or if it is not behind the default branch
// Check if the branch is the default branch or if it is not
// behind the default branch behindby means if the current
// branch doesn't have any changes, then we'll continue on . we
// won't be able to get any information that would allow us to
// actually caculate the branch time with any measure of
// accuracy. at best we could proceed and only check the
// aheadby commits, at which might, or might not give us some
// type of range. this is wasteful at best.
if branch.Name == branch.Repository.DefaultBranchRef.Name || branch.Compare.BehindBy == 0 {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ func (ghs *githubScraper) getCommitInfo(
return 0, 0, 0, err
}

// TODO
// let's make sure there's actually commits here stupid graphql nesting and types
if len(c.Edges) == 0 {
break
}
Expand Down Expand Up @@ -274,15 +276,27 @@ func (ghs *githubScraper) getCommitData(
}

if len(data.Repository.Refs.Nodes) == 0 {
// TODO
// this means no branch or no commits? this node is the ref node whic
// is a branch not a commit. but commits willbe on it. this check would
// only occur if the branch got deleted between the time the original
// get branches query was made, and the time this query was made.
return nil, errors.New("no commits returned")
}

tar := data.Repository.Refs.Nodes[0].GetTarget()

// i hate graphql types
if ct, ok := tar.(*CommitNodeTargetCommit); ok {
return &ct.History, nil
}

// TODO
// this error message isn't accurate
// i think this is the data requested for commits on a branch does not exist
// well, it is actually a target that isn't a commit
// this would be if the graphql query sent back something
// target does not commit node target interface
return nil, errors.New("target is not a commit")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
name: git.repository.branch.commit.aheadby_count
unit: '{branch}'
unit: '{commit}'
- description: Number of commits a branch is behing the default branch.
gauge:
dataPoints:
Expand All @@ -39,7 +39,7 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
name: git.repository.branch.commit.behindby_count
unit: '{branch}'
unit: '{commit}'
- description: Number of branches in a repository
gauge:
dataPoints:
Expand All @@ -66,7 +66,7 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
name: git.repository.branch.line.addition_count
unit: '{branch}'
unit: '{line}'
- description: Count of lines deleted from code in a branch
gauge:
dataPoints:
Expand All @@ -81,7 +81,7 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
name: git.repository.branch.line.deletion_count
unit: '{branch}'
unit: '{line}'
- description: Time the branch has existed.
gauge:
dataPoints:
Expand All @@ -96,7 +96,7 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
name: git.repository.branch.time
unit: '{branch}'
unit: s
- description: Number of repositories in an organization
gauge:
dataPoints:
Expand Down
16 changes: 8 additions & 8 deletions receiver/gitproviderreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,56 +42,56 @@ metrics:
git.repository.count:
enabled: true
description: Number of repositories in an organization
unit: "{repository}"
unit: '{repository}'
gauge:
value_type: int
attributes: []
git.repository.branch.count:
enabled: true
description: Number of branches in a repository
unit: "{branch}"
unit: '{branch}'
gauge:
value_type: int
attributes: [repository.name]
git.repository.branch.time:
enabled: true
description: Time the branch has existed.
unit: "{branch}"
unit: s
gauge:
value_type: int
attributes: [repository.name, branch.name]
git.repository.branch.commit.aheadby_count:
enabled: true
description: Number of commits a branch is ahead of the default branch.
unit: "{branch}"
unit: '{commit}'
gauge:
value_type: int
attributes: [repository.name, branch.name]
git.repository.branch.commit.behindby_count:
enabled: true
description: Number of commits a branch is behing the default branch.
unit: "{branch}"
unit: '{commit}'
gauge:
value_type: int
attributes: [repository.name, branch.name]
git.repository.branch.line.addition_count:
enabled: true
description: Count of lines added to code in a branch
unit: '{branch}'
unit: '{line}'
gauge:
value_type: int
attributes: [repository.name, branch.name]
git.repository.branch.line.deletion_count:
enabled: true
description: Count of lines deleted from code in a branch
unit: '{branch}'
unit: '{line}'
gauge:
value_type: int
attributes: [repository.name, branch.name]
git.repository.contributor.count:
enabled: false
description: Total number of unique contributors to a repository
unit: "{contributor}"
unit: '{contributor}'
gauge:
value_type: int
attributes: [repository.name]
Expand Down

0 comments on commit 8c24669

Please sign in to comment.