analysis

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package analysis は1回の走行(収集グループ)について、種類をまたいだ集計を出す。

alp / slow log / pprof は「サーバーの中で何が遅いか」を教えてくれるが、 「ベンチの利用者が何をしていて、得点がいつ・どこで生まれたか」は教えてくれない。 ここでは httplog の生ログと dbquery の結果を時刻で揃え、次の3つを出す。

  • 時系列: 一定幅の区間ごとのリクエスト数・エラー・応答時間と、SQL で取った系列(得点・母集団)
  • ライフサイクル: エンティティ(利用者・ライドなど)が状態を順に進む様子。区間ごとの到達数と所要時間
  • 内訳: SQL の結果表(配信者別の得点など)

回ごとの知識(どの SQL が得点か、どの状態を順に進むか)は analysis.yml と dbquery.yml に置き、 このパッケージには持たない。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeUnixTime

func NormalizeUnixTime(x float64) float64

NormalizeUnixTime は秒・ミリ秒・マイクロ秒の unix 時刻を秒に揃える。 SQL 側で単位を揃えなくてよいように、桁で判定する。

func RenderMarkdown

func RenderMarkdown(w io.Writer, rep *Report)

RenderMarkdown は Report をエージェントの文脈にそのまま貼れる Markdown にする。

Types

type BreakdownDef

type BreakdownDef struct {
	Name  string `yaml:"name"`
	Query string `yaml:"query"`
}

BreakdownDef は dbquery の結果表をそのまま出す。value 列があれば構成比を付ける。

type BreakdownResult

type BreakdownResult struct {
	Name    string
	Columns []string
	Rows    [][]string
	// Share は value 列があるときの構成比(Rows と同じ並び)。
	Share     []float64 `json:",omitempty"`
	TotalRows int
	Error     string `json:",omitempty"`
}

type Bucket

type Bucket struct {
	// Offset は区間の開始(Origin からの秒)。
	Offset   int
	Requests int
	S2xx     int
	S3xx     int
	S4xx     int
	S5xx     int
	// Canceled は 499(クライアントが待ちきれずに切った)。S4xx には入れない。
	Canceled  int
	P50       float64
	P99       float64
	Endpoints map[string]int     `json:",omitempty"`
	Series    map[string]float64 `json:",omitempty"`
}

type Config

type Config struct {
	// Bucket は時系列の区間幅(秒)。
	Bucket int `yaml:"bucket"`
	// Top は内訳・エンドポイント表に出す件数。
	Top int `yaml:"top"`

	HTTPLog HTTPLogConfig `yaml:"httplog"`

	Series     []SeriesDef    `yaml:"series"`
	Breakdowns []BreakdownDef `yaml:"breakdowns"`
	Lifecycles []LifecycleDef `yaml:"lifecycles"`
}

Config は analysis.yml。

func ParseConfig

func ParseConfig(raw []byte) (*Config, error)

type HTTPLogConfig

type HTTPLogConfig struct {
	// Label は使う httplog の Label。空なら同じ収集の httplog を全部まとめる。
	Label string `yaml:"label"`
	// TimeKey は時刻の LTSV キー。msec(nginx の $msec)か time($time_local)。
	// 既定は msec で、行に無ければ time を見る。
	TimeKey string `yaml:"time_key"`
	// EntityKey はライフサイクルの識別子に使う LTSV キー(セッション cookie など)。
	EntityKey string `yaml:"entity_key"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler は /api/analysis を提供する。 trend と同じく自分自身の API から材料を読むので、収集タイプの実装には手を入れない。

func NewHandler

func NewHandler(selfURL string, store storage.Storage) (*Handler, error)

func (*Handler) RegisterHandlers

func (h *Handler) RegisterHandlers(g *echo.Group)

type Input

type Input struct {
	GroupId string
	// Origin は時系列の 0 秒(unix 秒)。GroupId の時刻 = 収集開始 = initialize の直後。
	Origin   float64
	Requests []Request
	// SkippedLines は時刻が読めず捨てた LTSV の行数。
	SkippedLines int
	Queries      map[string]*dbquery.QueryResult
}

Input は1回の収集から集めた材料。

func Load

func Load(client *summary.Client, cfg *Config, groupId string) (*Input, error)

Load は収集グループの httplog(生ログ)と dbquery の結果を集める。

type LifecycleDef

type LifecycleDef struct {
	Name string `yaml:"name"`
	// Source は httplog(識別子 = httplog.entity_key、状態 = "METHOD 正規化済みURI")か、
	// query:<dbquery の name>(列 entity, state, t)。
	Source string `yaml:"source"`
	Steps  []Step `yaml:"steps"`
}

LifecycleDef はエンティティが順に進む状態の列。

type LifecycleResult

type LifecycleResult struct {
	Name string
	// Entities は最初の状態に到達したエンティティの数。
	Entities int
	Steps    []StepResult
	Error    string `json:",omitempty"`
}

type Normalizer

type Normalizer struct {
	// contains filtered or unexported fields
}

Normalizer は alp.yml の matching_groups で URI をまとめる。 alp と同じく、クエリ文字列を落としてから先頭から順に当て、最初に当たった正規表現を返す。

func NewNormalizer

func NewNormalizer(alpConfig []byte) (*Normalizer, error)

func (*Normalizer) Normalize

func (n *Normalizer) Normalize(uri string) string

type Quantiles

type Quantiles struct {
	P50 float64
	P90 float64
	P99 float64
	Max float64
}

type Report

type Report struct {
	GroupId  string
	Origin   time.Time
	Bucket   int
	Warnings []string `json:",omitempty"`

	Timeline   Timeline
	Lifecycles []LifecycleResult
	Breakdowns []BreakdownResult
}

func Analyze

func Analyze(cfg *Config, in *Input) *Report

Analyze は材料から Report を作る。

type Request

type Request struct {
	// T は unix 秒(小数あり)。
	T        float64
	Method   string
	Endpoint string // matching_groups でまとめた URI
	Status   int
	ReqTime  float64
	Entity   string
}

Request は LTSV 1行ぶん。

func ParseLTSV

func ParseLTSV(data []byte, n *Normalizer, timeKey, entityKey string) ([]Request, int)

ParseLTSV は nginx の LTSV ログを読む。時刻が読めない行は飛ばし、その件数を返す。

func (*Request) Key

func (r *Request) Key() string

Key はライフサイクルの状態に使う文字列。

type SeriesDef

type SeriesDef struct {
	Name  string `yaml:"name"`
	Query string `yaml:"query"`
	// Agg は区間内の集約方法。sum(既定)/ count / max / last。
	Agg string `yaml:"agg"`
	// Cumulative を true にすると区間ごとの値に加えて累積を出す(得点の積み上がりを見る)。
	Cumulative bool `yaml:"cumulative"`
}

SeriesDef は dbquery の結果から作る時系列。 クエリの列: t(unix 時刻。秒/ミリ秒/マイクロ秒は桁で判定)、value(省略時は件数)、 series(任意。あれば値ごとに別系列 "<name>:<series>" になる)。

type Step

type Step struct {
	Name string `yaml:"name"`
	// Match は状態に当てる正規表現。
	Match string `yaml:"match"`
	// contains filtered or unexported fields
}

type StepResult

type StepResult struct {
	Name string
	// Reached はこの状態まで順に到達したエンティティの数。
	Reached int
	// Rate は1つ前の状態に到達したうち、この状態まで進んだ割合。
	Rate float64
	// StoppedHere はこの状態を最後に先へ進まなかったエンティティの数(離脱・途中で走行終了の両方を含む)。
	StoppedHere int
	// PerEntity は到達したエンティティ1つあたり、この状態のイベントが何回あったか(順序を問わない)。
	PerEntity float64
	// FromPrev は1つ前の状態からの所要秒数。
	FromPrev *Quantiles `json:",omitempty"`
}

type Timeline

type Timeline struct {
	// Series は Buckets[].Series に入っている系列名(表示順)。
	Series []string
	// Endpoints は件数の多いエンドポイント(Buckets[].Endpoints のキー)。
	Endpoints []string
	Buckets   []Bucket
}

Jump to

Keyboard shortcuts

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