Skip to content

Commit

Permalink
Cost Management Downstream v1.1.5 (#138)
Browse files Browse the repository at this point in the history
* v1.1.4 bundle (#129)

* switch to only golangci-lint for pre-commit and action (#134)

* [COST-2570] update data aggregation key and associated tests (#133)

* [COST-992] filter out empty volumename to prevent many to many issue (#135)

* fix dependabot alert for gogo/protobuff (#136)

* v1.1.5 bundle (#137)

* fix makefile and run make downstream

Co-authored-by: Michael Skarbek <mskarbek@redhat.com>
  • Loading branch information
cgoodfred and maskarb authored May 17, 2022
1 parent 77ec351 commit f8d1f7c
Show file tree
Hide file tree
Showing 29 changed files with 1,889 additions and 82 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.16
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
19 changes: 0 additions & 19 deletions .github/workflows/pre-commit.yaml

This file was deleted.

31 changes: 31 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
run:
timeout: 5m


linters-settings:
goimports:
# Put imports beginning with prefix after 3rd-party packages.
# It's a comma-separated list of prefixes.
local-prefixes: github.com/project-costmanagement/costmanagement-metrics-operator

linters:
disable-all: true
enable:
## enabled by default
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

- goimports

issues:
max-issues-per-linter: 0
max-same-issues: 0
fix: true
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
exclude: ^vendor/
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: go-vet
- id: go-imports
- id: go-mod-tidy
- id: go-mod-vendor
- repo: https://github.com/golangci/golangci-lint
rev: v1.40.1
hooks:
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ UPSTREAM_UPPERCASE = Koku
DOWNSTREAM_LOWERCASE = costmanagement
DOWNSTREAM_UPPERCASE = CostManagement
# Current Operator version
PREVIOUS_VERSION ?= 1.1.3
VERSION ?= 1.1.4
PREVIOUS_VERSION ?= 1.1.5
VERSION ?= 1.1.6
# Default bundle image tag
IMAGE_TAG_BASE ?= quay.io/project-koku/koku-metrics-operator
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
Expand Down Expand Up @@ -285,8 +285,8 @@ bundle-push:
docker push $(BUNDLE_IMG)

# Build a test-catalog
test-catalog:
opm index add --from-index quay.io/project-koku/kmc-test-catalog:v${PREVIOUS_VERSION} --bundles ${BUNDLE_IMG} --tag ${CATALOG_IMG} --container-tool docker
test-catalog: opm
$(OPM) index add --from-index quay.io/project-koku/kmc-test-catalog:v${PREVIOUS_VERSION} --bundles ${BUNDLE_IMG} --tag ${CATALOG_IMG} --container-tool docker

# Push the test-catalog
test-catalog-push:
Expand All @@ -296,8 +296,8 @@ test-catalog-push:
downstream:
rm -rf $(REMOVE_FILES)
# sed replace everything but the Makefile
- find . -type f -not -name "Makefile" -not -name "config" -not -path "./.git/*" -exec sed -i -- 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- find . -type f -not -name "Makefile" -not -name "config" -not -path "./.git/*" -exec sed -i -- 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
- LC_ALL=C find . -type f -not -name "Makefile" -not -name "config" -not -path "./.git/*" -exec sed -i -- 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- LC_ALL=C find . -type f -not -name "Makefile" -not -name "config" -not -path "./.git/*" -exec sed -i -- 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
go mod tidy
go mod vendor
# fix the cert
Expand Down
20 changes: 17 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"strings"

"github.com/mitchellh/mapstructure"
costmanagementmetricscfgv1beta1 "github.com/project-costmanagement/costmanagement-metrics-operator/api/v1beta1"
"github.com/project-costmanagement/costmanagement-metrics-operator/dirconfig"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"

costmanagementmetricscfgv1beta1 "github.com/project-costmanagement/costmanagement-metrics-operator/api/v1beta1"
"github.com/project-costmanagement/costmanagement-metrics-operator/dirconfig"
)

var (
Expand Down Expand Up @@ -79,10 +80,23 @@ func getResourceID(input string) string {
return splitString[len(splitString)-1]
}

func generateKey(metric model.Metric, keys []model.LabelName) string {
if len(keys) == 1 {
return string(metric[keys[0]])
}
result := []string{}
for _, key := range keys {
result = append(result, string(metric[key]))
}
sort.Strings(result)

return strings.Join(result, ",")
}

func (r *mappedResults) iterateMatrix(matrix model.Matrix, q query) {
results := *r
for _, stream := range matrix {
obj := string(stream.Metric[q.RowKey])
obj := generateKey(stream.Metric, q.RowKey)
if results[obj] == nil {
results[obj] = mappedValues{}
}
Expand Down
11 changes: 6 additions & 5 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"testing"
"time"

promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"

costmanagementmetricscfgv1beta1 "github.com/project-costmanagement/costmanagement-metrics-operator/api/v1beta1"
"github.com/project-costmanagement/costmanagement-metrics-operator/dirconfig"
"github.com/project-costmanagement/costmanagement-metrics-operator/strset"
"github.com/project-costmanagement/costmanagement-metrics-operator/testutils"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
)

var testLogger = testutils.TestLogger{}
Expand Down Expand Up @@ -416,7 +417,7 @@ func TestIterateMatrix(t *testing.T) {
Factor: maxFactor,
TransformedName: "node-allocatable-cpu-core-seconds",
},
RowKey: "node",
RowKey: []model.LabelName{"node"},
},
matrix: model.Matrix{
{
Expand Down Expand Up @@ -449,7 +450,7 @@ func TestIterateMatrix(t *testing.T) {
Name: "node-labels",
QueryString: "kube_node_labels",
MetricKeyRegex: regexFields{"node_labels": "label_*"},
RowKey: "node",
RowKey: []model.LabelName{"node"},
},
matrix: model.Matrix{
{
Expand Down Expand Up @@ -492,7 +493,7 @@ func TestIterateMatrix(t *testing.T) {
Factor: maxFactor,
TransformedName: "node-capacity-cpu-core-seconds",
},
RowKey: "node",
RowKey: []model.LabelName{"node"},
},
matrix: model.Matrix{
{
Expand Down
11 changes: 6 additions & 5 deletions collector/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
"testing"
"time"

costmanagementmetricscfgv1beta1 "github.com/project-costmanagement/costmanagement-metrics-operator/api/v1beta1"
"github.com/project-costmanagement/costmanagement-metrics-operator/testutils"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"

costmanagementmetricscfgv1beta1 "github.com/project-costmanagement/costmanagement-metrics-operator/api/v1beta1"
"github.com/project-costmanagement/costmanagement-metrics-operator/testutils"
)

var trueDef = true
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestGetQueryResultsSuccess(t *testing.T) {
Factor: maxFactor,
TransformedName: "usage-cpu-core-seconds",
},
RowKey: "id",
RowKey: []model.LabelName{"id"},
},
query{
Name: "capacity-cpu-cores",
Expand All @@ -94,13 +95,13 @@ func TestGetQueryResultsSuccess(t *testing.T) {
Factor: maxFactor,
TransformedName: "capacity-cpu-core-seconds",
},
RowKey: "id",
RowKey: []model.LabelName{"id"},
},
query{
Name: "labels",
QueryString: "query3",
MetricKeyRegex: regexFields{"labels": "label_*"},
RowKey: "id",
RowKey: []model.LabelName{"id"},
},
},
queriesResult: mappedMockPromResult{
Expand Down
Loading

0 comments on commit f8d1f7c

Please sign in to comment.