Skip to content

Commit

Permalink
PMM-12673 Protobuf linters (#2612)
Browse files Browse the repository at this point in the history
* PMM-12673 Replace _INVALID suffix in enums with _UNSPECIFIED

* PMM-12673 Remove unused imports

* Refactor all protobuf enums

* PMM-12673 Fix

* PMM-12673 Fix qan tests

* PMM-12673 Add service suffix to all grpc service names

* PMM-12673 Fix QAN GetReport request/response naming

* PMM-12673 Fix

* PMM-12673 Fix

* PMM-12673 Fix tests

* PMM-12673 Fix tests

* PMM-12673 Fix test

* PMM-12673 Refactor user API requests and responses

* PMM-12673 Fix tests

* PMM-12673 Fix tests

* PMM-12673 Refactor requests/responses names

* PMM-12673 Refactoring

* PMM-12673 Fix

* PMM-12673 Fix

* PMM-12673 Fix

* PMM-12673 Refactoring

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Fix

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Restructure

* PMM-12673 Fix

* PMM-12673 Configure buf lint, setup CI action

* PMM-12673 Cleanup

* PMM-12673 Fix CI

* PMM-12673 Rename

* PMM-12673 Trigger API lint warning

* PMM-12673 Remove redundant go_package option

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Refactoring

* PMM-12673 Fix buf lint in CI

* PMM-12673 Fix

* PMM-12673 add debug data

* PMM-12673 Add debug data [skip ci]

* PMM-12673 Trigger CI

* PMM-12673 Debug

* PMM-12673 Remove debug data

* PMM-12673 Refactoring

* PMM-12673 Fix some linter warnings

* PMM-12673 Fix test

* Update docs/managed/update-process.md

* Update api/buf.yaml

Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com>

* PMM-12673 Fix API tests

* Fix import allias

* PMM-12673 Post-merge fix

---------

Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com>
  • Loading branch information
artemgavrilov and ademidoff authored Nov 23, 2023
1 parent a2c12ca commit 64fcdc3
Show file tree
Hide file tree
Showing 997 changed files with 52,456 additions and 49,997 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,25 @@ jobs:
- name: Run go-sumtype
run: bin/go-sumtype ./...

- name: Run linters
- name: Run API linter
env:
COMMAND: 'bin/buf lint -v api'
REDIRECT: "| bin/reviewdog -f=buf -reporter=github-pr-review -fail-on-error=true"
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.ROBOT_TOKEN || secrets.GITHUB_TOKEN }}
run: |
if out=$( ${{ env.COMMAND }} ); exit_code=$?; [ $exit_code -ne 0 ]; then
## buf uses exit code 100 for linter warnings
if [ $exit_code != 100 ] || ${{ github.event.pull_request == null }}; then
echo "$out"
exit $exit_code
else
echo "$out" ${{ env.REDIRECT }}
fi
else
echo "$out"
fi
- name: Run code linters
uses: reviewdog/action-golangci-lint@v2
with:
github_token: ${{ secrets.ROBOT_TOKEN || secrets.GITHUB_TOKEN }}
Expand Down
47 changes: 24 additions & 23 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gen-api: ## Generate PMM API

bin/buf generate -v api

for API in api/agentlocalpb api/serverpb api/inventorypb api/managementpb api/managementpb/alerting api/managementpb/backup api/managementpb/azure api/managementpb/role api/qanpb api/managementpb/agent api/managementpb/node api/managementpb/service api/platformpb api/userpb; do \
for API in api/agentlocal/v1 api/server/v1 api/inventory/v1 api/management/v1 api/management/v1/alerting api/management/v1/backup api/management/v1/azure api/management/v1/role api/qan/v1beta1 api/management/v1/agent api/management/v1/node api/management/v1/service api/platform/v1 api/user/v1; do \
set -x ; \
bin/swagger mixin $$API/json/header.json $$API/*.swagger.json --output=$$API/json/$$(basename $$API).json --keep-spec-order; \
bin/swagger flatten --with-flatten=expand --with-flatten=remove-unused $$API/json/$$(basename $$API).json --output=$$API/json/$$(basename $$API).json ; \
Expand All @@ -68,36 +68,36 @@ gen-api: ## Generate PMM API
--additional-initialism=ha ; \
done

# generate public API spec, omit agentlocalpb (always private),
# generate public API spec, omit agentlocal (always private),
# as well as a number of protos that are in beta (not v1 yet, they all go to a similar call below)
bin/swagger mixin --output=api/swagger/swagger.json \
api/swagger/header.json \
api/serverpb/json/serverpb.json \
api/userpb/json/userpb.json \
api/inventorypb/json/inventorypb.json \
api/managementpb/json/managementpb.json \
api/managementpb/backup/json/backup.json \
api/managementpb/alerting/json/alerting.json
api/server/v1/json/v1.json \
api/user/v1/json/v1.json \
api/inventory/v1/json/v1.json \
api/management/v1/json/v1.json \
api/management/v1/backup/json/backup.json \
api/management/v1/alerting/json/alerting.json
bin/swagger validate api/swagger/swagger.json

bin/swagger-order --output=api/swagger/swagger.json api/swagger/swagger.json

# generate API spec with all PMM Server APIs (omit agentlocalpb)
# generate API spec with all PMM Server APIs (omit agentlocal)
bin/swagger mixin --output=api/swagger/swagger-dev.json \
api/swagger/header-dev.json \
api/serverpb/json/serverpb.json \
api/userpb/json/userpb.json \
api/inventorypb/json/inventorypb.json \
api/managementpb/json/managementpb.json \
api/managementpb/alerting/json/alerting.json \
api/managementpb/backup/json/backup.json \
api/managementpb/azure/json/azure.json \
api/managementpb/role/json/role.json \
api/managementpb/agent/json/agent.json \
api/managementpb/node/json/node.json \
api/managementpb/service/json/service.json \
api/qanpb/json/qanpb.json \
api/platformpb/json/platformpb.json
api/server/v1/json/v1.json \
api/user/v1/json/v1.json \
api/inventory/v1/json/v1.json \
api/management/v1/json/v1.json \
api/management/v1/alerting/json/alerting.json \
api/management/v1/backup/json/backup.json \
api/management/v1/azure/json/azure.json \
api/management/v1/role/json/role.json \
api/management/v1/agent/json/agent.json \
api/management/v1/node/json/node.json \
api/management/v1/service/json/service.json \
api/qan/v1beta1/json/v1beta1.json \
api/platform/v1/json/v1.json
bin/swagger validate api/swagger/swagger-dev.json

bin/swagger-order --output=api/swagger/swagger-dev.json api/swagger/swagger-dev.json
Expand Down Expand Up @@ -127,7 +127,7 @@ clean: clean_swagger ## Remove generated files
find api -name '*.pb.gw.go' -print -delete
find api -name '*.validate.go' -print -delete

for API in api/agentlocalpb api/serverpb api/inventorypb api/managementpb api/managementpb/alerting api/managementpb/backup api/managementpb/role api/managementpb/agent api/managementpb/node api/managementpb/service api/qanpb api/platformpb ; do \
for API in api/agentlocal/v1 api/server/v1 api/inventory/v1 api/management/v1 api/management/v1/alerting api/management/v1/backup api/management/v1/role api/management/v1/agent api/management/v1/node api/management/v1/service api/qan/v1beta1 api/platform/v1 api/user/v1 ; do \
rm -fr $$API/json/client $$API/json/models $$API/json/$$(basename $$API).json ; \
done
rm -f api/swagger/swagger.json api/swagger/swagger-dev.json
Expand All @@ -139,6 +139,7 @@ api-test: ## Run API tests on dev env.
go test -count=1 -race -p 1 -v ./api-tests/... -pmm.server-insecure-tls

check: ## Run required checkers and linters
bin/buf lint -v api
LOG_LEVEL=error bin/golangci-lint run ; \
bin/go-sumtype ./... ; \
bin/go-consistent -pedantic ./...
Expand Down
6 changes: 3 additions & 3 deletions admin/agentlocal/agentlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
httptransport "github.com/go-openapi/runtime/client"
"github.com/sirupsen/logrus"

"github.com/percona/pmm/api/agentlocalpb/json/client"
agentlocal "github.com/percona/pmm/api/agentlocalpb/json/client/agent_local"
"github.com/percona/pmm/api/agentlocal/v1/json/client"
agentlocal "github.com/percona/pmm/api/agentlocal/v1/json/client/agent_local_service"
)

// SetTransport configures transport for accessing local pmm-agent API.
Expand Down Expand Up @@ -98,7 +98,7 @@ func GetRawStatus(ctx context.Context, requestNetworkInfo NetworkInfo) (*agentlo
Context: ctx,
}

res, err := client.Default.AgentLocal.Status(params)
res, err := client.Default.AgentLocalService.Status(params)
if err != nil {
if res == nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions admin/commands/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (

"github.com/percona/pmm/admin/agentlocal"
"github.com/percona/pmm/admin/helpers"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/nodes"
"github.com/percona/pmm/api/inventorypb/json/client/services"
managementClient "github.com/percona/pmm/api/managementpb/json/client"
"github.com/percona/pmm/api/managementpb/json/client/annotation"
"github.com/percona/pmm/api/inventory/v1/json/client"
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
annotation "github.com/percona/pmm/api/management/v1/json/client/annotation_service"
)

var annotationResultT = ParseTemplate(`
Expand Down Expand Up @@ -83,7 +83,7 @@ func (cmd *AnnotationCommand) getCurrentNode() (*nodes.GetNodeOKBody, error) {
Context: Ctx,
}

result, err := client.Default.Nodes.GetNode(params)
result, err := client.Default.NodesService.GetNode(params)
if err != nil {
return nil, errors.Wrap(err, "default get node")
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (cmd *AnnotationCommand) getCurrentNodeAllServices() ([]string, error) {
Context: Ctx,
}

result, err := client.Default.Services.ListServices(params)
result, err := client.Default.ServicesService.ListServices(params)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func (cmd *AnnotationCommand) RunCmd() (Result, error) {
return nil, err
}

_, err = managementClient.Default.Annotation.AddAnnotation(&annotation.AddAnnotationParams{
_, err = managementClient.Default.AnnotationService.AddAnnotation(&annotation.AddAnnotationParams{
Body: annotation.AddAnnotationBody{
Text: cmd.Text,
Tags: cmd.Tags,
Expand Down
12 changes: 6 additions & 6 deletions admin/commands/base/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

"github.com/percona/pmm/admin/agentlocal"
"github.com/percona/pmm/admin/cli/flags"
inventorypb "github.com/percona/pmm/api/inventorypb/json/client"
managementpb "github.com/percona/pmm/api/managementpb/json/client"
serverpb "github.com/percona/pmm/api/serverpb/json/client"
inventoryClient "github.com/percona/pmm/api/inventory/v1/json/client"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
serverClient "github.com/percona/pmm/api/server/v1/json/client"
"github.com/percona/pmm/utils/tlsconfig"
)

Expand Down Expand Up @@ -121,7 +121,7 @@ func SetupClients(ctx context.Context, globalFlags *flags.GlobalFlags) {
httpTransport.TLSClientConfig.InsecureSkipVerify = globalFlags.SkipTLSCertificateCheck
}

inventorypb.Default.SetTransport(transport)
managementpb.Default.SetTransport(transport)
serverpb.Default.SetTransport(transport)
inventoryClient.Default.SetTransport(transport)
managementClient.Default.SetTransport(transport)
serverClient.Default.SetTransport(transport)
}
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_external_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"strings"

"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentExternalExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -82,7 +82,7 @@ func (cmd *AddAgentExternalExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddExternalExporter(params)
resp, err := client.Default.AgentsService.AddExternalExporter(params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentMongodbExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -105,7 +105,7 @@ func (cmd *AddAgentMongodbExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddMongoDBExporter(params)
resp, err := client.Default.AgentsService.AddMongoDBExporter(params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_mysqld_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"strconv"

"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentMysqldExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -148,7 +148,7 @@ func (cmd *AddAgentMysqldExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddMySQLdExporter(params)
resp, err := client.Default.AgentsService.AddMySQLdExporter(params)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/inventory/add_agent_mysqld_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/AlekSi/pointer"
"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/json/client/agents"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

func TestAddAgentMysqldExporter(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_node_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentNodeExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -65,7 +65,7 @@ func (cmd *AddAgentNodeExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddNodeExporter(params)
resp, err := client.Default.AgentsService.AddNodeExporter(params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_pmm_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addPMMAgentResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -54,7 +54,7 @@ func (cmd *AddPMMAgentCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddPMMAgent(params)
resp, err := client.Default.AgentsService.AddPMMAgent(params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentPostgresExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -116,7 +116,7 @@ func (cmd *AddAgentPostgresExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddPostgresExporter(params)
resp, err := client.Default.AgentsService.AddPostgresExporter(params)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/AlekSi/pointer"
"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/json/client/agents"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

func TestAddAgentPostgresExporter(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/inventory/add_agent_proxysql_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentProxysqlExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -83,7 +83,7 @@ func (cmd *AddAgentProxysqlExporterCommand) RunCmd() (commands.Result, error) {
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddProxySQLExporter(params)
resp, err := client.Default.AgentsService.AddProxySQLExporter(params)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentQANMongoDBProfilerAgentResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -97,7 +97,7 @@ func (cmd *AddAgentQANMongoDBProfilerAgentCommand) RunCmd() (commands.Result, er
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddQANMongoDBProfilerAgent(params)
resp, err := client.Default.AgentsService.AddQANMongoDBProfilerAgent(params)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)

var addAgentQANMySQLPerfSchemaAgentResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -121,7 +121,7 @@ func (cmd *AddAgentQANMySQLPerfSchemaAgentCommand) RunCmd() (commands.Result, er
Context: commands.Ctx,
}

resp, err := client.Default.Agents.AddQANMySQLPerfSchemaAgent(params)
resp, err := client.Default.AgentsService.AddQANMySQLPerfSchemaAgent(params)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 64fcdc3

Please sign in to comment.