Skip to content

Commit

Permalink
Log at debug level, not info
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Dec 2, 2021
1 parent 89c8145 commit 4953e7d
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 28 deletions.
119 changes: 109 additions & 10 deletions irods/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type IRODSConnection struct {
serverVersion *types.IRODSVersion
generatedPasswordForPAM string // used for PAM auth
lastSuccessfulAccess time.Time
transferMetrics types.TransferMetrics
}

// NewIRODSConnection create a IRODSConnection
Expand Down Expand Up @@ -77,7 +78,7 @@ func (conn *IRODSConnection) Connect() error {
conn.connected = false

server := fmt.Sprintf("%s:%d", conn.Account.Host, conn.Account.Port)
logger.Infof("Connecting to %s", server)
logger.Debugf("Connecting to %s", server)

socket, err := net.Dial("tcp", server)
if err != nil {
Expand Down Expand Up @@ -141,7 +142,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er
}

// Send a startup message
logger.Info("Start up a connection with CS Negotiation")
logger.Debug("Start up a connection with CS Negotiation")

startup := message.NewIRODSMessageStartupPack(conn.Account, conn.ApplicationName, true)
startupMessage, err := startup.GetMessage()
Expand Down Expand Up @@ -176,7 +177,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er
return version.GetVersion(), nil
} else if negotiationMessage.Body.Type == message.RODS_MESSAGE_CS_NEG_TYPE {
// Server responds with its own negotiation policy
logger.Info("Start up CS Negotiation")
logger.Debug("Start up CS Negotiation")

negotiation := message.IRODSMessageCSNegotiation{}
err = negotiation.FromMessage(negotiationMessage)
Expand All @@ -189,7 +190,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er
return nil, fmt.Errorf("unable to parse server policy - %v", err)
}

logger.Infof("Client policy - %s, server policy - %s", clientPolicy, serverPolicy)
logger.Debugf("Client policy - %s, server policy - %s", clientPolicy, serverPolicy)

// Perform the negotiation
policyResult, status := types.PerformCSNegotiation(clientPolicy, serverPolicy)
Expand Down Expand Up @@ -229,7 +230,7 @@ func (conn *IRODSConnection) connectWithoutCSNegotiation() (*types.IRODSVersion,

// No client-server negotiation
// Send a startup message
logger.Info("Start up a connection without CS Negotiation")
logger.Debug("Start up a connection without CS Negotiation")

startup := message.NewIRODSMessageStartupPack(conn.Account, conn.ApplicationName, false)
version := message.IRODSMessageVersion{}
Expand All @@ -248,7 +249,7 @@ func (conn *IRODSConnection) sslStartup() error {
"function": "sslStartup",
})

logger.Info("Start up SSL")
logger.Debug("Start up SSL")

irodsSSLConfig := conn.Account.SSLConfiguration
if irodsSSLConfig == nil {
Expand Down Expand Up @@ -318,7 +319,7 @@ func (conn *IRODSConnection) loginNative(password string) error {
"function": "loginNative",
})

logger.Info("Logging in using native authentication method")
logger.Debug("Logging in using native authentication method")

// authenticate
authRequest := message.NewIRODSMessageAuthRequest()
Expand Down Expand Up @@ -349,7 +350,7 @@ func (conn *IRODSConnection) loginPAM() error {
"function": "loginPAM",
})

logger.Info("Logging in using pam authentication method")
logger.Debug("Logging in using pam authentication method")

// Check whether ssl has already started, if not, start ssl.
if _, ok := conn.socket.(*tls.Conn); !ok {
Expand Down Expand Up @@ -383,7 +384,7 @@ func (conn *IRODSConnection) showTicket() error {
"function": "showTicket",
})

logger.Info("Submitting a ticket to obtain access")
logger.Debug("Submitting a ticket to obtain access")

if len(conn.Account.Ticket) > 0 {
// show the ticket
Expand Down Expand Up @@ -413,7 +414,7 @@ func (conn *IRODSConnection) Disconnect() error {
"function": "Disconnect",
})

logger.Info("Disconnecting the connection")
logger.Debug("Disconnecting the connection")

disconnect := message.NewIRODSMessageDisconnect()
disconnectMessage, err := disconnect.GetMessage()
Expand Down Expand Up @@ -461,6 +462,10 @@ func (conn *IRODSConnection) Send(buffer []byte, size int) error {
return fmt.Errorf("unable to send data - %v", err)
}

if size > 0 {
conn.IncreaseTransferMetricsBytesSent(uint64(size))
}

conn.lastSuccessfulAccess = time.Now()

return nil
Expand Down Expand Up @@ -490,6 +495,10 @@ func (conn *IRODSConnection) Recv(buffer []byte, size int) (int, error) {
return readLen, fmt.Errorf("unable to receive data - %v", err)
}

if readLen > 0 {
conn.IncreaseTransferMetricsBytesReceived(uint64(readLen))
}

conn.lastSuccessfulAccess = time.Now()

return readLen, nil
Expand Down Expand Up @@ -734,3 +743,93 @@ func (conn *IRODSConnection) RawBind(socket net.Conn) {
conn.connected = true
conn.socket = socket
}

/*
* Metrics related functions
*/

// GetTransferMetrics returns transfer metrics
func (conn *IRODSConnection) GetTransferMetrics() types.TransferMetrics {
// returns a copy of metrics
return conn.transferMetrics
}

// ClearTransferMetrics clears transfer metrics
func (conn *IRODSConnection) ClearTransferMetrics() {
conn.transferMetrics = types.TransferMetrics{}
}

// IncreaseTransferMetricsBytesSent increases bytes sent metrics
func (conn *IRODSConnection) IncreaseTransferMetricsBytesSent(n uint64) {
conn.transferMetrics.BytesSent += n
}

// IncreaseTransferMetricsBytesReceived increases bytes received metrics
func (conn *IRODSConnection) IncreaseTransferMetricsBytesReceived(n uint64) {
conn.transferMetrics.BytesReceived += n
}

// IncreaseDataObjectMetricsStat increases stat data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsStat(n uint64) {
conn.transferMetrics.DataObjectIO.Stat += n
}

// IncreaseDataObjectMetricsCreate increases create data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsCreate(n uint64) {
conn.transferMetrics.DataObjectIO.Create += n
}

// IncreaseDataObjectMetricsDelete increases delete data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsDelete(n uint64) {
conn.transferMetrics.DataObjectIO.Delete += n
}

// IncreaseDataObjectMetricsWrite increases write data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsWrite(n uint64) {
conn.transferMetrics.DataObjectIO.Write += n
}

// IncreaseDataObjectMetricsRead increases read data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsRead(n uint64) {
conn.transferMetrics.DataObjectIO.Read += n
}

// IncreaseDataObjectMetricsRename increases rename data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsRename(n uint64) {
conn.transferMetrics.DataObjectIO.Rename += n
}

// IncreaseDataObjectMetricsMeta increases meta data object metrics
func (conn *IRODSConnection) IncreaseDataObjectMetricsMeta(n uint64) {
conn.transferMetrics.DataObjectIO.Meta += n
}

// IncreaseCollectionMetricsStat increases stat collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsStat(n uint64) {
conn.transferMetrics.CollectionIO.Stat += n
}

// IncreaseCollectionMetricsList increases list collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsList(n uint64) {
conn.transferMetrics.CollectionIO.List += n
}

// IncreaseCollectionMetricsCreate increases create collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsCreate(n uint64) {
conn.transferMetrics.CollectionIO.Create += n
}

// IncreaseCollectionMetricsDelete increases delete collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsDelete(n uint64) {
conn.transferMetrics.CollectionIO.Delete += n
}

// IncreaseCollectionMetricsRename increases rename collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsRename(n uint64) {
conn.transferMetrics.CollectionIO.Rename += n
}

// IncreaseCollectionMetricsMeta increases meta collection metrics
func (conn *IRODSConnection) IncreaseCollectionMetricsMeta(n uint64) {
conn.transferMetrics.CollectionIO.Meta += n
}
26 changes: 26 additions & 0 deletions irods/fs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func GetCollection(conn *connection.IRODSConnection, path string) (*types.IRODSC
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsStat(1)

query := message.NewIRODSMessageQuery(common.MaxQueryRows, 0, 0, 0)
query.AddSelect(common.ICAT_COLUMN_COLL_ID, 1)
query.AddSelect(common.ICAT_COLUMN_COLL_NAME, 1)
Expand Down Expand Up @@ -139,6 +141,8 @@ func ListCollectionMeta(conn *connection.IRODSConnection, path string) ([]*types
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsStat(1)

metas := []*types.IRODSMeta{}

continueQuery := true
Expand Down Expand Up @@ -234,6 +238,8 @@ func ListCollectionAccess(conn *connection.IRODSConnection, path string) ([]*typ
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

accesses := []*types.IRODSAccess{}

continueQuery := true
Expand Down Expand Up @@ -326,6 +332,8 @@ func ListSubCollections(conn *connection.IRODSConnection, path string) ([]*types
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsList(1)

collections := []*types.IRODSCollection{}

continueQuery := true
Expand Down Expand Up @@ -435,6 +443,8 @@ func CreateCollection(conn *connection.IRODSConnection, path string, recurse boo
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsCreate(1)

request := message.NewIRODSMessageMkcolRequest(path, recurse)
response := message.IRODSMessageMkcolResponse{}
return conn.RequestAndCheck(request, &response)
Expand All @@ -446,6 +456,8 @@ func DeleteCollection(conn *connection.IRODSConnection, path string, recurse boo
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsDelete(1)

request := message.NewIRODSMessageRmcolRequest(path, recurse, force)
response := message.IRODSMessageRmcolResponse{}
err := conn.RequestAndCheck(request, &response)
Expand Down Expand Up @@ -486,6 +498,8 @@ func MoveCollection(conn *connection.IRODSConnection, srcPath string, destPath s
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsRename(1)

request := message.NewIRODSMessageMvcolRequest(srcPath, destPath)
response := message.IRODSMessageMvcolResponse{}
err := conn.RequestAndCheck(request, &response)
Expand All @@ -502,6 +516,8 @@ func AddCollectionMeta(conn *connection.IRODSConnection, path string, metadata *
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

request := message.NewIRODSMessageAddMetadataRequest(types.IRODSCollectionMetaItemType, path, metadata)
response := message.IRODSMessageModMetaResponse{}
return conn.RequestAndCheck(request, &response)
Expand All @@ -514,6 +530,8 @@ func DeleteCollectionMeta(conn *connection.IRODSConnection, path string, metadat
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

var request *message.IRODSMessageModMetaRequest

if metadata.AVUID != 0 {
Expand All @@ -538,6 +556,8 @@ func SearchCollectionsByMeta(conn *connection.IRODSConnection, metaName string,
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

collections := []*types.IRODSCollection{}

continueQuery := true
Expand Down Expand Up @@ -650,6 +670,8 @@ func SearchCollectionsByMetaWildcard(conn *connection.IRODSConnection, metaName
return nil, fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

collections := []*types.IRODSCollection{}

continueQuery := true
Expand Down Expand Up @@ -768,6 +790,8 @@ func ChangeAccessControlCollection(conn *connection.IRODSConnection, path string
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

request := message.NewIRODSMessageModAccessRequest(access.ChmodString(), userName, zoneName, path, recursive, adminFlag)
response := message.IRODSMessageModAccessResponse{}
err := conn.RequestAndCheck(request, &response)
Expand All @@ -783,6 +807,8 @@ func SetInheritAccessControl(conn *connection.IRODSConnection, path string, inhe
return fmt.Errorf("connection is nil or disconnected")
}

conn.IncreaseCollectionMetricsMeta(1)

inheritStr := "inherit"

if !inherit {
Expand Down
Loading

0 comments on commit 4953e7d

Please sign in to comment.