Import/Export metrics

This commit is contained in:
Michal Horejsek
2020-07-31 12:08:40 +02:00
parent 7e5e3d3dd4
commit 4f0af0fb02
5 changed files with 118 additions and 5 deletions

View File

@ -120,7 +120,7 @@ func (ie *ImportExport) GetLocalImporter(address, path string) (*transfer.Transf
if err != nil {
return nil, err
}
return transfer.New(ie.panicHandler, ie.config.GetTransferDir(), source, target)
return transfer.New(ie.panicHandler, newImportMetricsManager(ie), ie.config.GetTransferDir(), source, target)
}
// GetRemoteImporter returns transferrer from remote IMAP to ProtonMail account.
@ -133,7 +133,7 @@ func (ie *ImportExport) GetRemoteImporter(address, username, password, host, por
if err != nil {
return nil, err
}
return transfer.New(ie.panicHandler, ie.config.GetTransferDir(), source, target)
return transfer.New(ie.panicHandler, newImportMetricsManager(ie), ie.config.GetTransferDir(), source, target)
}
// GetEMLExporter returns transferrer from ProtonMail account to local EML structure.
@ -143,7 +143,7 @@ func (ie *ImportExport) GetEMLExporter(address, path string) (*transfer.Transfer
return nil, err
}
target := transfer.NewEMLProvider(path)
return transfer.New(ie.panicHandler, ie.config.GetTransferDir(), source, target)
return transfer.New(ie.panicHandler, newExportMetricsManager(ie), ie.config.GetTransferDir(), source, target)
}
// GetMBOXExporter returns transferrer from ProtonMail account to local MBOX structure.
@ -153,7 +153,7 @@ func (ie *ImportExport) GetMBOXExporter(address, path string) (*transfer.Transfe
return nil, err
}
target := transfer.NewMBOXProvider(path)
return transfer.New(ie.panicHandler, ie.config.GetTransferDir(), source, target)
return transfer.New(ie.panicHandler, newExportMetricsManager(ie), ie.config.GetTransferDir(), source, target)
}
func (ie *ImportExport) getPMAPIProvider(address string) (*transfer.PMAPIProvider, error) {

View File

@ -0,0 +1,64 @@
// Copyright (c) 2020 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
package importexport
import (
"strconv"
"github.com/ProtonMail/proton-bridge/internal/metrics"
)
type metricsManager struct {
ie *ImportExport
category metrics.Category
}
func newImportMetricsManager(ie *ImportExport) *metricsManager {
return &metricsManager{
ie: ie,
category: metrics.Import,
}
}
func newExportMetricsManager(ie *ImportExport) *metricsManager {
return &metricsManager{
ie: ie,
category: metrics.Export,
}
}
func (m *metricsManager) Load(numberOfMailboxes int) {
label := strconv.Itoa(numberOfMailboxes)
m.ie.SendMetric(metrics.New(m.category, metrics.TransferLoad, metrics.Label(label)))
}
func (m *metricsManager) Start() {
m.ie.SendMetric(metrics.New(m.category, metrics.TransferStart, metrics.NoLabel))
}
func (m *metricsManager) Complete() {
m.ie.SendMetric(metrics.New(m.category, metrics.TransferComplete, metrics.NoLabel))
}
func (m *metricsManager) Cancel() {
m.ie.SendMetric(metrics.New(m.category, metrics.TransferCancel, metrics.NoLabel))
}
func (m *metricsManager) Fail() {
m.ie.SendMetric(metrics.New(m.category, metrics.TransferFail, metrics.NoLabel))
}