Documentation
¶
Overview ¶
Package analysis は1回の走行(収集グループ)について、種類をまたいだ集計を出す。
alp / slow log / pprof は「サーバーの中で何が遅いか」を教えてくれるが、 「ベンチの利用者が何をしていて、得点がいつ・どこで生まれたか」は教えてくれない。 ここでは httplog の生ログと dbquery の結果を時刻で揃え、次の3つを出す。
- 時系列: 一定幅の区間ごとのリクエスト数・エラー・応答時間と、SQL で取った系列(得点・母集団)
- ライフサイクル: エンティティ(利用者・ライドなど)が状態を順に進む様子。区間ごとの到達数と所要時間
- 内訳: SQL の結果表(配信者別の得点など)
回ごとの知識(どの SQL が得点か、どの状態を順に進むか)は analysis.yml と dbquery.yml に置き、 このパッケージには持たない。
Index ¶
- func LatestGroup(client *summary.Client) (string, error)
- func NormalizeUnixTime(x float64) float64
- func Pending(client *summary.Client, groupId string) (int, error)
- func RenderMarkdown(w io.Writer, rep *Report)
- type BreakdownDef
- type BreakdownResult
- type Bucket
- type Config
- type HTTPLogConfig
- type Handler
- type Input
- type LifecycleDef
- type LifecycleResult
- type Normalizer
- type Quantiles
- type Report
- type Request
- type SeriesDef
- type Step
- type StepResult
- type Timeline
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LatestGroup ¶ added in v0.2.1
LatestGroup は httplog がある最新の収集グループを返す。 収集中(pending)のものも含める。走行直後に latest を引いて1つ前の走行が出ると、取り違えに気づけない。
func NormalizeUnixTime ¶
NormalizeUnixTime は秒・ミリ秒・マイクロ秒の unix 時刻を秒に揃える。 SQL 側で単位を揃えなくてよいように、桁で判定する。
func RenderMarkdown ¶
RenderMarkdown は Report をエージェントの文脈にそのまま貼れる Markdown にする。
Types ¶
type BreakdownDef ¶
BreakdownDef は dbquery の結果表をそのまま出す。value 列があれば構成比を付ける。
type BreakdownResult ¶
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 ¶
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 (*Handler) RegisterHandlers ¶
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
// Warnings は材料を集める段階で見つかった問題(収集中・収集失敗のエントリなど)。
Warnings []string
}
Input は1回の収集から集めた材料。
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 Report ¶
type Report struct {
GroupId string
Origin time.Time
Bucket int
Warnings []string `json:",omitempty"`
Timeline Timeline
Lifecycles []LifecycleResult
Breakdowns []BreakdownResult
}
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行ぶん。
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 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"`
}