Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

PMM-5194 Tunnels #643

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ required = [

[[constraint]]
name = "github.com/percona/pmm"
branch = "PMM-2.0"
# branch = "PMM-2.0"
branch = "PMM-5194-tunnels"

[[constraint]]
name = "github.com/percona-platform/saas"
Expand Down
6 changes: 6 additions & 0 deletions models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ var databaseSchema = [][]string{
PRIMARY KEY (id)
)`,
},

25: {
`ALTER TABLE agents ADD COLUMN mongo_db_tls_options JSONB`,
},

26: {
`ALTER TABLE ia_rules ALTER COLUMN channel_ids DROP NOT NULL`,
},
Expand Down Expand Up @@ -507,6 +509,10 @@ func SetupDB(sqlDB *sql.DB, params *SetupDBParams) (*reform.DB, error) {
queries = append(queries, fmt.Sprintf(`INSERT INTO schema_migrations (id) VALUES (%d)`, version))
for _, q := range queries {
q = strings.TrimSpace(q)
if q == "" {
return fmt.Errorf("empty query in version %d: missed migration number?", version)
}

if _, err = tx.Exec(q); err != nil {
return errors.Wrapf(err, "failed to execute statement:\n%s", q)
}
Expand Down
71 changes: 71 additions & 0 deletions models/tunnel_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package models

import (
"time"

"gopkg.in/reform.v1"
)

//go:generate reform

type TunnelType string

Choose a reason for hiding this comment

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

🚫 [golangci-lint] reported by reviewdog 🐶
exported type TunnelType should have comment or be unexported (golint)


const (
ConnectTunnelType TunnelType = "connect"

Choose a reason for hiding this comment

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

🚫 [golangci-lint] reported by reviewdog 🐶
exported const ConnectTunnelType should have comment (or a comment on this block) or be unexported (golint)

ListenTunnelType TunnelType = "listen"

Choose a reason for hiding this comment

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

🚫 [golangci-lint] reported by reviewdog 🐶
const ListenTunnelType is unused (unused)

)

//reform:tunnels

Choose a reason for hiding this comment

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

🚫 [golangci-lint] reported by reviewdog 🐶
comment on exported type Tunnel should be of the form "Tunnel ..." (with optional leading article) (golint)

type Tunnel struct {
TunnelID string `reform:"tunnel_id,pk"`
TunnelType TunnelType `reform:"tunnel_type"`
PMMAgentID string `reform:"pmm_agent_id"`
ConnectPort uint16 `reform:"connect_port"`
ListenPort uint16 `reform:"listen_port"`
CreatedAt time.Time `reform:"created_at"`
UpdatedAt time.Time `reform:"updated_at"`
}

// BeforeInsert implements reform.BeforeInserter interface.
func (s *Tunnel) BeforeInsert() error {
now := Now()
s.CreatedAt = now
s.UpdatedAt = now
return nil
}

// BeforeUpdate implements reform.BeforeUpdater interface.
func (s *Tunnel) BeforeUpdate() error {
s.UpdatedAt = Now()
return nil
}

// AfterFind implements reform.AfterFinder interface.
func (s *Tunnel) AfterFind() error {
s.CreatedAt = s.CreatedAt.UTC()
s.UpdatedAt = s.UpdatedAt.UTC()
return nil
}

// check interfaces
var (
_ reform.BeforeInserter = (*Tunnel)(nil)
_ reform.BeforeUpdater = (*Tunnel)(nil)
_ reform.AfterFinder = (*Tunnel)(nil)
)
161 changes: 161 additions & 0 deletions models/tunnel_model_reform.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion services/agents/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type ServerResponse struct {

// Channel encapsulates two-way communication channel between pmm-managed and pmm-agent.
//
// pmm-agent establishes a single gRPC connection with pmm-managed
// and then starts a single gRPC bidirectional stream, which is represented by this type.
//
// All exported methods are thread-safe.
//nolint:maligned
type Channel struct {
Expand All @@ -70,7 +73,7 @@ type Channel struct {
closeErr error
}

// New creates new two-way communication channel with given stream.
// New creates new two-way communication channel with given gRPC bidirectional stream.
//
// Stream should not be used by the caller after channel is created.
func New(stream agentpb.Agent_ConnectServer, m *SharedChannelMetrics) *Channel {
Expand Down
2 changes: 0 additions & 2 deletions services/agents/channel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func (scm *SharedChannelMetrics) Describe(ch chan<- *prom.Desc) {
func (scm *SharedChannelMetrics) Collect(ch chan<- prom.Metric) {
scm.mRecv.Collect(ch)
scm.mSend.Collect(ch)

// TODO metrics for channel's len(requests) and cap(requests)
}

// check interfaces
Expand Down
17 changes: 17 additions & 0 deletions services/agents/channel/tunnel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package channel
Loading