Skip to content

CLOUDP-292850: Investigate diff approach for Metric Collection #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
109 changes: 109 additions & 0 deletions tools/spectral/ipa/metrics/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable:
- shadow

revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: true
severity: warning
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: errorf
- name: exported
- name: indent-error-flow
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: struct-tag
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
misspell:
locale: US
lll:
line-length: 150
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 7
funlen:
lines: 360
statements: 120
linters:
disable-all: true
enable:
- dogsled
- errcheck
- funlen
- gocritic
- gofmt
- goimports
- revive
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- rowserrcheck
- copyloopvar
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace
- thelper
- testifylint
- exhaustive
- makezero
- noctx
- tenv
- prealloc
- predeclared
- whitespace

Comment on lines +90 to +91
Copy link
Preview

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A duplicate 'whitespace' linter entry is present in the configuration. Removing the duplicate will help avoid potential redundancy or confusion.

Suggested change
- whitespace

Copilot uses AI. Check for mistakes.

# don't enable:
# - deadcode
# - varcheck
# - structcheck
# - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
# - gocyclo # we already have funlen lint
# - dupl # we have a lot of duplicate test cases
# - gochecknoinits # we need the init function for the provider
# - gochecknoglobals # we need some global variables
# - unparam # Forces to create global variables when one variable is repeated in different functions
# - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it
# - goconst
# - gocognit

run:
timeout: 10m
tests: true
modules-download-mode: readonly
63 changes: 63 additions & 0 deletions tools/spectral/ipa/metrics/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
project_name: foascli
version: 2
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- <<: &build_defaults
env:
- CGO_ENABLED=0
binary: bin/foascli
main: ./cmd/foascli.go
Copy link
Preview

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry point in the goreleaser config points to './cmd/foascli.go', which does not match the new metrics/main.go file. Please update the configuration to reference the correct main file for the metrics component.

Suggested change
main: ./cmd/foascli.go
main: metrics/main.go

Copilot uses AI. Check for mistakes.

ldflags:
- -s -w -X github.com/mongodb/openapi/tools/cli/internal/version.Version={{.Version}} -X github.com/mongodb/openapi/tools/cli/internal/version.GitCommit={{.FullCommit}}
id: linux
goos: [linux]
goarch: [amd64,arm64]
- <<: *build_defaults
id: macos
goos: [darwin]
goarch: [amd64,arm64]

gomod: # https://goreleaser.com/customization/verifiable_builds/
# Proxy a module from proxy.golang.org, making the builds verifiable.
# This will only be effective if running against a tag. Snapshots will ignore
# this setting.
# Notice: for this to work your `build.main` must be a package, not a `.go` file.
proxy: false
# Sets the `-mod` flag value.
#
# Since: v1.7
mod: mod

archives:
- id: linux_archives
name_template: mongodb-foas-cli_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}
builds: [linux]
wrap_in_directory: true
format: tar.gz
- id: macos
name_template: mongodb-foas-cli_{{ .Version }}_{{- if eq .Os "darwin" }}macos{{- else }}{{ .Os }}{{ end }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}
builds: [macos]
format: zip
wrap_in_directory: false

snapshot:
name_template: "{{ .Env.VERSION_GIT }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore:'
- '^build(deps):'

release:
prerelease: auto
name_template: "FOAS CLI v{{.Version}}"


26 changes: 26 additions & 0 deletions tools/spectral/ipa/metrics/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module metrics

go 1.23.1

require (
github.com/invopop/yaml v0.3.1
github.com/tufin/oasdiff v1.10.27
github.com/getkin/kin-openapi v0.128.0
)

require (
cloud.google.com/go v0.116.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/tidwall/gjson v1.17.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/wI2L/jsondiff v0.6.0 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
57 changes: 57 additions & 0 deletions tools/spectral/ipa/metrics/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/tufin/oasdiff v1.10.27 h1:oVz1yCwR0Owh/Oivb09Qb+Xgvd6mTUY051kXRuHFxo8=
github.com/tufin/oasdiff v1.10.27/go.mod h1:dH2d3Xkx6J5ZDgxcT6t8fgW198IC3Y1D1Mq/3kCfJOE=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/wI2L/jsondiff v0.6.0 h1:zrsH3FbfVa3JO9llxrcDy/XLkYPLgoMX6Mz3T2PP2AI=
github.com/wI2L/jsondiff v0.6.0/go.mod h1:D6aQ5gKgPF9g17j+E9N7aasmU1O+XvfmWm1y8UMmNpw=
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
63 changes: 63 additions & 0 deletions tools/spectral/ipa/metrics/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"log"
"metrics/utils"
"os"
"path/filepath"
)

func main() {
if err := utils.SplitOAS(); err != nil {
log.Fatal(err)
}
affectedTags, deletedTags := utils.DetectChanges()

tagsPath := "split_specs/tags"
sharedComponentPath := "split_specs/shared_components.yaml" // Input: shared schema file
mergedSpecPath := "output/merged_spec.yaml" // Temporary file to hold the merged spec
deletedMergedSpecPath := "output/merged_spec_deleted.yaml" // Temporary file to hold the merged spec

spectralRulesetPath := "../ipa-spectral.yaml" // Spectral ruleset file

// Create output directory if it doesn't exist
if err := os.MkdirAll("output", 0755); err != nil {
log.Fatalf("Failed to create output directory: %v", err)
}

//For all the changed tag files
for tag := range affectedTags {
tagDir := filepath.Join(tagsPath, tag)
tagFilePath := filepath.Join(tagDir, "spec.yaml")
// Step 1: Merge tag and shared component files
if err := utils.RebuildFullSpec(tagFilePath, sharedComponentPath, mergedSpecPath); err != nil {
log.Fatalf("Failed to merge specs: %v", err)
}
fmt.Printf("Merged spec written to: %s\n", mergedSpecPath)

// Step 2: Lint the merged spec with Spectral
if err := utils.LintSpecWithSpectral(mergedSpecPath, spectralRulesetPath); err != nil {
log.Fatalf("Failed to lint spec with Spectral: %v", err)
}
}

//Collect all the spec files which have deleted paths
var deletedTagsFiles []string
for tag := range deletedTags {
tagDir := filepath.Join(tagsPath, tag)
tagFilePath := filepath.Join(tagDir, "spec-deleted.yaml")
deletedTagsFiles = append(deletedTagsFiles, tagFilePath)
}

if err := utils.RebuildFullDeletedPathsSpec(deletedTagsFiles, sharedComponentPath, deletedMergedSpecPath); err != nil {
log.Fatalf("Failed to merge specs: %v", err)
}
fmt.Printf("Merged spec written to: %s\n", deletedMergedSpecPath)

//Lint the merged spec with Spectral
if err := utils.LintSpecWithSpectral(deletedMergedSpecPath, spectralRulesetPath); err != nil {
log.Fatalf("Failed to lint spec with Spectral: %v", err)
}

}
Loading
Loading