summary

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package summary は pprotein の API を叩いて計測結果を取り出し、 テキスト(Markdown)や JSON に整形する。CLI から使う。

Index

Constants

This section is empty.

Variables

View Source
var CollectTypes = []string{"score", "httplog", "slowlog", "resource", "pprof", "memo"}

CollectTypes は summary が読む収集タイプ。表示する順に並べてある。

Functions

func GroupIDs

func GroupIDs(entries []Entry) []string

GroupIDs は新しい順の GroupId 一覧を返す。

Types

type Client

type Client struct {
	BaseURL string
	HTTP    *http.Client
}

Client は pprotein の HTTP API クライアント。

func NewClient

func NewClient(baseURL string) *Client

func (*Client) AllEntries

func (c *Client) AllEntries() ([]Entry, error)

AllEntries は全タイプのエントリをまとめて取る。 収集タイプが存在しない(古い pprotein)場合はそのタイプを黙って飛ばす。

func (*Client) Config

func (c *Client) Config(typ string) ([]byte, error)

Config は収集タイプの設定ファイル(alp.yml など)を返す。

func (*Client) Content

func (c *Client) Content(typ, id string) (string, error)

Content は処理済みの結果(alp の TSV、resource の要約テキストなど)を返す。

func (*Client) Entries

func (c *Client) Entries(typ string) ([]Entry, error)

Entries は指定した収集タイプのエントリ一覧を返す。

func (*Client) GetQuery added in v0.5.0

func (c *Client) GetQuery(path string, query url.Values) ([]byte, error)

GetQuery は path にクエリ文字列を付けて GET する(path に ? を含めると JoinPath でエスケープされるため)。

func (*Client) RawData

func (c *Client) RawData(typ, id string) ([]byte, error)

RawData は生のスナップショット(pprof のプロファイルなど)を返す。

func (*Client) Score

func (c *Client) Score(id string) (*score.Value, error)

Score は収集に紐づいたスコアを返す。無ければ nil。

func (*Client) StartCollect

func (c *Client) StartCollect() error

StartCollect は収集を開始する。

type Diff

type Diff struct {
	Before, After *Group
	Score         *ScoreDiff
	Endpoints     []EndpointDiff
	Queries       []QueryDiff
}

Diff は2つの Group の差分。

func Compare

func Compare(before, after *Group, topN int) *Diff

Compare は before -> after のエンドポイント / クエリ単位の増減を出す。 片方にしか無いものも「新規 / 消滅」として残す。

func (*Diff) Markdown

func (d *Diff) Markdown() string

type Endpoint

type Endpoint struct {
	Method string
	Uri    string
	Count  float64
	Sum    float64
	Avg    float64
	P99    float64
	Max    float64
}

Endpoint は alp の1行。列は alp の設定で変わるので、ヘッダ名で引く。

func ParseEndpoints

func ParseEndpoints(tsv string) []Endpoint

ParseEndpoints は alp の TSV を読む。SUM の大きい順に並べる。

func (Endpoint) Key

func (e Endpoint) Key() string

type EndpointDiff

type EndpointDiff struct {
	Label       string
	Key         string
	CountBefore float64
	CountAfter  float64
	SumBefore   float64
	SumAfter    float64
	AvgBefore   float64
	AvgAfter    float64
}

func (EndpointDiff) AvgDelta

func (d EndpointDiff) AvgDelta() float64

func (EndpointDiff) CountDelta

func (d EndpointDiff) CountDelta() float64

func (EndpointDiff) Impact

func (d EndpointDiff) Impact() float64

Impact は「リクエスト数を揃えたとき、合計でどれだけ時間が増減したか」。

ベンチが固定時間だと、速くしても空いた時間に次のリクエストが入るので SUM はほとんど動かない(代わりに件数が増える)。SUM の増減で並べると いちばん効いた施策が下に埋もれるので、1件あたりの増減に件数を掛けて順位を付ける。

func (EndpointDiff) SumDelta

func (d EndpointDiff) SumDelta() float64

type Entry

type Entry struct {
	Snapshot struct {
		Type       string
		ID         string
		Datetime   time.Time
		Repository *git.RepositoryInfo
		GroupId    string
		Label      string
		Duration   int
	}
	Status  string
	Message string
}

Entry は /api/<type> が返すエントリ。

type Func

type Func struct {
	Name    string
	Flat    float64
	FlatPct float64
	Cum     float64
	Unit    string
}

Func は pprof の1関数。

func ParseProfile

func ParseProfile(raw []byte) ([]Func, error)

ParseProfile は pprof のプロファイルから関数ごとの flat / cum を出す。

type Group

type Group struct {
	ID         string
	Datetime   time.Time
	Repository *git.RepositoryInfo
	Score      *score.Value

	HTTPLog  []LabeledEndpoints
	SlowLog  []LabeledQueries
	Profiles []LabeledFuncs
	Resource []LabeledText
	Memo     []LabeledText

	// Pending / Failed は収集がまだ終わっていない / 失敗したエントリ。
	Pending []string
	Failed  []string
}

Group は1回の収集(GroupId)の中身をまとめたもの。

func Load

func Load(c *Client, groupID string, topN int) (*Group, error)

Load は GroupId(空なら最新)の中身を集めて Group にする。

func (*Group) Markdown

func (g *Group) Markdown() string

Markdown は Group を Markdown にする。 そのままエージェントの文脈に貼れることを狙って、表と最小限の見出しだけで書く。

type LabeledEndpoints

type LabeledEndpoints struct {
	Label     string
	Endpoints []Endpoint
}

type LabeledFuncs

type LabeledFuncs struct {
	Label string
	Funcs []Func
}

type LabeledQueries

type LabeledQueries struct {
	Label   string
	Queries []Query
}

type LabeledText

type LabeledText struct {
	Label string
	Text  string
}

type Query

type Query struct {
	Query string
	Count float64
	Sum   float64
	Avg   float64
	Max   float64
	// RowsExamined は1回あたりの走査行数の平均。インデックスの当たり外れが出る。
	RowsExamined float64
}

Query は slp の1行。

func ParseQueries

func ParseQueries(tsv string) []Query

ParseQueries は slp の TSV を読む。合計クエリ時間の大きい順に並べる。

func (Query) Key

func (q Query) Key() string

type QueryDiff

type QueryDiff struct {
	Label       string
	Query       string
	CountBefore float64
	CountAfter  float64
	SumBefore   float64
	SumAfter    float64
	AvgBefore   float64
	AvgAfter    float64
}

func (QueryDiff) AvgDelta

func (d QueryDiff) AvgDelta() float64

func (QueryDiff) CountDelta

func (d QueryDiff) CountDelta() float64

func (QueryDiff) Impact

func (d QueryDiff) Impact() float64

func (QueryDiff) SumDelta

func (d QueryDiff) SumDelta() float64

type ScoreDiff

type ScoreDiff struct {
	Before, After int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL