Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
098cde0
Sanitize metric type prefixes (#319)
sysedwinistrator Aug 30, 2024
47f0744
Update example in README.md (#358)
stuart23 Aug 30, 2024
a3a59f8
Update common Prometheus files (#357)
prombot Aug 30, 2024
6df0c9e
Bump github.com/onsi/gomega from 1.33.1 to 1.34.1 (#353)
dependabot[bot] Aug 30, 2024
a3570d6
Bump google.golang.org/api from 0.188.0 to 0.189.0 (#354)
dependabot[bot] Aug 30, 2024
25498e6
Update common Prometheus files (#363)
prombot Aug 31, 2024
bae9112
Bump github.com/prometheus/client_golang from 1.19.1 to 1.20.2 (#368)
dependabot[bot] Sep 3, 2024
9ce0b8a
Bump google.golang.org/api from 0.189.0 to 0.195.0 (#365)
dependabot[bot] Sep 3, 2024
d8b48ad
Add project ID to all logs from the collector (#362)
TylerLubeck Sep 5, 2024
05bcf94
Bump github.com/prometheus/common from 0.55.0 to 0.58.0 (#369)
dependabot[bot] Sep 5, 2024
25bf0a4
Update common Prometheus files
prombot Sep 5, 2024
185325b
Merge pull request #370 from prometheus-community/repo_sync
kgeckhart Oct 7, 2024
7be5c7d
Bump github.com/prometheus/common from 0.58.0 to 0.59.1 (#372)
dependabot[bot] Oct 7, 2024
3f130ff
Bump golang.org/x/net from 0.28.0 to 0.29.0 (#373)
dependabot[bot] Oct 7, 2024
166886a
Bump google.golang.org/api from 0.195.0 to 0.199.0 (#375)
dependabot[bot] Oct 7, 2024
157cf40
Replace comma-delimited string flags with repeatable flags (#355)
tommyzli Oct 7, 2024
04b47fd
chore!: adopt log/slog, drop go-kit/log (#378)
tjhop Nov 4, 2024
bbf1334
Update common Prometheus files (#377)
prombot Nov 4, 2024
c0954e0
Bump github.com/prometheus/common from 0.59.1 to 0.60.1 (#379)
dependabot[bot] Nov 4, 2024
a26582f
Bump google.golang.org/api from 0.199.0 to 0.204.0 (#380)
dependabot[bot] Nov 4, 2024
a00ba04
Update Go build (#384)
SuperQ Nov 4, 2024
8159320
Bump github.com/onsi/gomega from 1.34.1 to 1.35.1 (#383)
dependabot[bot] Nov 4, 2024
5cb3be0
Bump github.com/prometheus/exporter-toolkit from 0.11.0 to 0.13.1 (#381)
dependabot[bot] Nov 4, 2024
15981bb
Release 0.17.0 (#376)
kgeckhart Nov 4, 2024
118a5f3
Update common Prometheus files (#385)
prombot Nov 18, 2024
5f55f7b
Update common Prometheus files (#388)
prombot Nov 18, 2024
231987c
feat: support more specific prefixes in ?collect parameter (#387)
antoinedeschenes Dec 2, 2024
6a15a74
Fix monitoring metrics for individual collectors (#389)
ananya-mallik-ps Dec 12, 2024
eb90059
Update common Prometheus files (#391)
prombot Jan 15, 2025
2e14ad1
Bump github.com/prometheus/exporter-toolkit from 0.13.1 to 0.13.2 (#398)
dependabot[bot] Jan 15, 2025
cf13524
Bump golang.org/x/net from 0.32.0 to 0.34.0 (#402)
dependabot[bot] Jan 15, 2025
c171930
Bump google.golang.org/api from 0.204.0 to 0.217.0 (#403)
dependabot[bot] Jan 15, 2025
a98e977
Bump github.com/onsi/gomega from 1.35.1 to 1.36.2 (#399)
dependabot[bot] Jan 16, 2025
22448b1
Fixup linter warning (#406)
SuperQ Jan 16, 2025
b525506
Release 0.18.0 (#404)
kgeckhart Jan 16, 2025
3b1a6e9
Update common Prometheus files (#407)
prombot Jan 17, 2025
6b359b1
Update common Prometheus files (#410)
prombot Feb 9, 2025
deacb43
Cleanup golangci-lint config (#418)
SuperQ Mar 10, 2025
4a111f6
Update Go (#419)
SuperQ Mar 10, 2025
a607c62
Bump google.golang.org/api from 0.217.0 to 0.224.0 (#420)
dependabot[bot] Mar 10, 2025
e9d0a1c
Update common Prometheus files (#421)
prombot Mar 10, 2025
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ executors:
# This must match .promu.yml.
golang:
docker:
- image: cimg/go:1.22
- image: cimg/go:1.24
jobs:
test:
executor: golang
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/container_description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set docker hub repo name
run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV
- name: Push README to Dockerhub
Expand All @@ -40,7 +40,7 @@ jobs:
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set quay.io org name
run: echo "DOCKER_REPO=$(echo quay.io/${GITHUB_REPOSITORY_OWNER} | tr -d '-')" >> $GITHUB_ENV
- name: Set quay.io repo name
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: 1.22.x
go-version: 1.24.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
with:
args: --verbose
version: v1.59.1
version: v1.64.6
17 changes: 5 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
---
linters:
enable:
- sloglint

run:
deadline: 5m
skip-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
timeout: 5m

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude-functions:
# Used in HTTP handlers, any error is handled by the server itself.
- (net/http.ResponseWriter).Write
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
go:
# This must match .circle/config.yml.
version: 1.22
version: 1.24
repository:
path: github.com/prometheus-community/stackdriver_exporter
build:
Expand Down
2 changes: 1 addition & 1 deletion .yamllint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
extends: default
ignore: |
ui/react-app/node_modules
**/node_modules

rules:
braces:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
## master / unreleased

## 0.18.0 / 2025-01-16

- [FEATURE] Support more specific prefixes in ?collect parameter #387
- [FEATURE] Enabling monitoring metrics, aggregate deltas, and descriptor cache with ?collect #389

## 0.17.0 / 2024-11-04

Deprecation notice: The comma delimited flags `google.project-id` and `monitoring.metrics-type-prefixes` are being replaced by repeatable flags `google.project-ids` and `monitoring.metrics-prefixes`. The comma delimited flags will be supported for at least one more release.

- [CHANGE] Migrate logging to promslog #378
- [ENHANCEMENT] Sanitize metric type prefixes to prevent duplicate metrics #319
- [ENHANCEMENT] Add project ID to all logs from the collector #362
- [FEATURE] Add support for specifying comma-delimited string flags as repeatable flags #355

## 0.16.0 / 2024-07-15

* [FEATURE] Add ErrorLogger for promhttp #277
Expand Down
8 changes: 7 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v1.64.6
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down Expand Up @@ -275,3 +275,9 @@ $(1)_precheck:
exit 1; \
fi
endef

govulncheck: install-govulncheck
govulncheck ./...

install-govulncheck:
command -v govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w

| Flag | Required | Default | Description |
| ----------------------------------- | -------- |---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `google.project-id` | No | GCloud SDK auto-discovery | Comma seperated list of Google Project IDs |
| `google.project-ids` | No | GCloud SDK auto-discovery | Repeatable flag of Google Project IDs |
| `google.projects.filter` | No | | GCloud projects filter expression. See more [here](https://cloud.google.com/sdk/gcloud/reference/projects/list). |
| `monitoring.metrics-ingest-delay` | No | | Offsets metric collection by a delay appropriate for each metric type, e.g. because bigquery metrics are slow to appear |
| `monitoring.drop-delegated-projects` | No | No | Drop metrics from attached projects and fetch `project_id` only. |
| `monitoring.metrics-type-prefixes` | Yes | | Comma separated Google Stackdriver Monitoring Metric Type prefixes (see [example][metrics-prefix-example] and [available metrics][metrics-list]) |
| `monitoring.metrics-prefixes` | Yes | | Repeatable flag of Google Stackdriver Monitoring Metric Type prefixes (see [example][metrics-prefix-example] and [available metrics][metrics-list]) |
| `monitoring.metrics-interval` | No | `5m` | Metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API. Only the most recent data point is used |
| `monitoring.metrics-offset` | No | `0s` | Offset (into the past) for the metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API, to handle latency in published metrics |
| `monitoring.filters` | No | | Additonal filters to be sent on the Monitoring API call. Add multiple filters by providing this parameter multiple times. See [monitoring.filters](#using-filters) for more info. |
Expand Down Expand Up @@ -143,8 +143,9 @@ If we want to get all `CPU` (`compute.googleapis.com/instance/cpu`) and `Disk` (

```
stackdriver_exporter \
--google.project-id=my-test-project \
--monitoring.metrics-type-prefixes "compute.googleapis.com/instance/cpu,compute.googleapis.com/instance/disk"
--google.project-ids=my-test-project \
--monitoring.metrics-prefixes "compute.googleapis.com/instance/cpu"
--monitoring.metrics-prefixes "compute.googleapis.com/instance/disk"
```

### Using filters
Expand All @@ -163,17 +164,17 @@ Example: \
pubsub.googleapis.com/subscription/num_undelivered_messages (apply to only the specific subscription metric) \

The `filter_query` will be applied to a final metrics API query when querying for metric data. You can read more about the metric API filter options in GCPs documentation https://cloud.google.com/monitoring/api/v3/filters

The final query sent to the metrics API already includes filters for project and metric type. Each applicable `filter_query` will be appended to the query with an AND

Full example
```
stackdriver_exporter \
--google.project-id=my-test-project \
--monitoring.metrics-type-prefixes='pubsub.googleapis.com/subscription' \
--monitoring.metrics-type-prefixes='compute.googleapis.com/instance/cpu' \
--google.project-ids=my-test-project \
--monitoring.metrics-prefixes='pubsub.googleapis.com/subscription' \
--monitoring.metrics-prefixes='compute.googleapis.com/instance/cpu' \
--monitoring.filters='pubsub.googleapis.com/subscription:resource.labels.subscription_id=monitoring.regex.full_match("us-west4.*my-team-subs.*")' \
--monitoring.filters='compute.googleapis.com/instance/cpu:resource.labels.instance=monitoring.regex.full_match("us-west4.*my-team-subs.*")'
--monitoring.filters='compute.googleapis.com/instance/cpu:resource.labels.instance=monitoring.regex.full_match("us-west4.*my-team-subs.*")'
```

Using projects filter:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.0
0.18.0
76 changes: 76 additions & 0 deletions collectors/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,79 @@ func (d *descriptorCache) Store(prefix string, data []*monitoring.MetricDescript
defer d.lock.Unlock()
d.cache[prefix] = &entry
}

// collectorCache is a cache for MonitoringCollectors
type CollectorCache struct {
cache map[string]*collectorCacheEntry
lock sync.RWMutex
ttl time.Duration
}

// collectorCacheEntry is a cache entry for a MonitoringCollector
type collectorCacheEntry struct {
collector *MonitoringCollector
expiry time.Time
}

// NewCollectorCache returns a new CollectorCache with the given TTL
func NewCollectorCache(ttl time.Duration) *CollectorCache {
c := &CollectorCache{
cache: make(map[string]*collectorCacheEntry),
ttl: ttl,
}

go c.cleanup()
return c
}

// Get returns a MonitoringCollector if the key is found and not expired
// If key is found it resets the TTL for the collector
func (c *CollectorCache) Get(key string) (*MonitoringCollector, bool) {
c.lock.RLock()
defer c.lock.RUnlock()

entry, ok := c.cache[key]

if !ok {
return nil, false
}

if time.Now().After(entry.expiry) {
delete(c.cache, key)
return nil, false
}

entry.expiry = time.Now().Add(c.ttl)
return entry.collector, true
}

func (c *CollectorCache) Store(key string, collector *MonitoringCollector) {
entry := &collectorCacheEntry{
collector: collector,
expiry: time.Now().Add(c.ttl),
}

c.lock.Lock()
defer c.lock.Unlock()
c.cache[key] = entry
}

func (c *CollectorCache) cleanup() {
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
for range ticker.C {
c.removeExpired()
}
}

func (c *CollectorCache) removeExpired() {
c.lock.Lock()
defer c.lock.Unlock()

now := time.Now()
for key, entry := range c.cache {
if now.After(entry.expiry) {
delete(c.cache, key)
}
}
}
53 changes: 53 additions & 0 deletions collectors/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,56 @@ func TestDescriptorCache(t *testing.T) {
t.Error("cache entries should have expired")
}
}

func TestCollectorCache(t *testing.T) {
createCollector := func(id string) *MonitoringCollector {
return &MonitoringCollector{
projectID: id,
}
}

t.Run("basic cache Op", func(t *testing.T) {
ttl := 1 * time.Second
cache := NewCollectorCache(ttl)
collector := createCollector("test-project")
key := "test-key"

cache.Store(key, collector)

if _, found := cache.Get("test-key"); !found {
t.Error("Collector should be available in cache before TTL")
}

time.Sleep(2 * ttl)
if _, found := cache.Get("test-key"); found {
t.Error("Collector should have expired")
}
})

t.Run("multiple collectors", func(t *testing.T) {
ttl := 1 * time.Second
cache := NewCollectorCache(ttl)

collectors := map[string]*MonitoringCollector{
"test-key-1": createCollector("test-project-1"),
"test-key-2": createCollector("test-project-2"),
"test-key-3": createCollector("test-project-3"),
}

for k, v := range collectors {
cache.Store(k, v)
}

for k, original := range collectors {
cached, found := cache.Get(k)
if !found {
t.Errorf("Collector %s not found in cache", k)
continue
}

if cached.projectID != original.projectID {
t.Errorf("Wrong collector for key %s. Got projectId %s, want %s", k, cached.projectID, original.projectID)
}
}
})
}
Loading
Loading