Logs Capability¶
LogsCapability is the contract base for log-search integrations. Bind
it with a Capability(kind='logs', handler=...) in the plugin's
manifest. Required methods are search and schema; histogram support
is optional via histogram() plus the supports_histogram hint on the
capability.
Surfaces: ui, api.
See Authoring Plugins for the manifest, capabilities, context, credential decryption, and error conventions shared by every plugin.
import typing
from imbi.common.plugins import (
LogHistogramBucket,
LogQuery,
LogResult,
LogsCapability,
PluginContext,
)
class LokiLogs(LogsCapability):
async def search(
self,
ctx: PluginContext,
credentials: dict[str, str],
query: LogQuery,
) -> LogResult:
...
async def schema(
self,
ctx: PluginContext,
credentials: dict[str, str],
) -> list[dict[str, typing.Any]]:
...
async def histogram(
self,
ctx: PluginContext,
credentials: dict[str, str],
query: LogQuery,
bucket_count: int = 60,
) -> list[LogHistogramBucket]:
...
Method contracts¶
search— return aLogResultwithentriesordered most-recent first. Honorquery.limitandquery.cursor. When more results are available, populatenext_cursorwith an opaque token the upstream system can decode on the next call. If a cursor has expired or become invalid, raiseCursorExpiredErrorrather than silently returning empty results.schema— return a list of field descriptors. The shape is intentionally loose so capabilities can surface vendor-specific metadata; at minimum include anameand a human-readablelabelfor each field exposed to filters.histogram— optional. Implement this method and set thesupports_histogramhint to enable the histogram panel in the host UI. Return oneLogHistogramBucketper time bucket spanning the query's time range. The base implementation returns an empty list; the host checks the hint before calling it.
Queries and filters¶
LogQuery.filters are (field, op, value) triples with five operators
(eq, ne, contains, starts_with, regex). LogQuery.levels
optionally restricts results to a set of canonical level names (e.g.
['ERROR', 'WARN']); an empty list means no level filter. Translate
both into the upstream provider's query language; raise a
domain-appropriate exception if a filter cannot be satisfied so the host
can surface a clear error.
Hints¶
supports_histogram— the capability implementshistogram().cacheable— the host may cache reads from this capability.
API reference¶
LogsCapability ¶
Bases: CapabilityHandler
histogram
async
¶
histogram(
ctx: PluginContext,
credentials: dict[str, str],
query: LogQuery,
bucket_count: int = 60,
) -> list[LogHistogramBucket]
Return time-bucketed event counts for the histogram view.
Capabilities that support histograms should override this method
and set the supports_histogram hint. The default returns an
empty list, which causes the API to signal that histograms are
unavailable for this source.
Source code in libraries/common/src/imbi/common/plugins/base.py
LogQuery ¶
Bases: BaseModel
LogFilter ¶
Bases: BaseModel
LogEntry ¶
Bases: BaseModel
LogResult ¶
Bases: BaseModel
LogHistogramBucket ¶
Bases: BaseModel
A single time bucket in a log histogram response.