Skip to content

[NEW] Expose resource pool statistics through crypto11.Context #119

@eriklupander

Description

@eriklupander

Is your feature request related to a problem? Please describe.

I would like to produce metrics for the underlying resource pool. However, crypto11.Context does not export its pool field or its StatsJSON() or related methods.

Describe the solution you'd like

A naive approach is to diectly access the pool stats through StatsJSON(), i.e. adding:

func (c *Context) PoolStatsJSON() string {
    if c.pool != nil {
        return c.pool.StatsJSON()
    }
    return "" // or introduce error into the method signature.
}

Callees can then parse the returned JSON.

A more concise approach could be to construct a:

type PoolStats struct {
    Capacity int64
    Available int64
    // and so on for the metrics exposed by pool.ResourcePool through its accessor methods.
}

In the crypto11 package, a new ResourcePoolStats() method on crypto11.Context can be added:

func (c *Context) ResourcePoolStats() PoolStats {
     if c.pool == nil {
        return PoolStats{} // return empty
    }
    return PoolStats {
        Capacity: c.pool.Capacity(),
        Available: c.pool.Available(),
        // And so on...
    }
}

Note that I haven't explored any potential downsides to exposing pool statistics through crypto11.Context, for example if reading pool stats may cause (unnecessary) communication to happen with the underlying device.

Describe alternatives you've considered

No, not really. Since the stats are exposed on the pool.ResourcePool I believe it should be rather straightforward to expose them through crypto11.Context as well.

Additional context

I don't think exposing the full pool is necessary.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions