historical-pattern-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Historical Pattern Analysis

历史模式分析

Overview

概述

Analyze git history and memory to learn from past infrastructure changes. Identify patterns, recurring issues, and apply lessons learned to current work.
Announce at start: "I'm using the historical-pattern-analysis skill to learn from past changes."
分析Git历史记录和存储的信息,从过往的基础设施变更中学习经验。识别模式、重复出现的问题,并将总结的经验应用到当前工作中。
开始时需声明: "我正在使用historical-pattern-analysis技能,从过往变更中学习经验。"

When to Use

使用场景

  • Before making changes similar to past changes
  • When investigating recurring issues
  • To understand why infrastructure is configured a certain way
  • To identify change patterns and team practices
  • 在进行与过往类似的变更之前
  • 调查重复出现的问题时
  • 想要了解基础设施为何采用某种配置方式时
  • 识别变更模式和团队实践时

Process

流程

Step 1: Define Search Scope

步骤1:定义搜索范围

Determine what history to analyze:
  • Specific resources being changed
  • Time period (last month, quarter, year)
  • Specific team members or patterns
确定要分析的历史记录范围:
  • 正在变更的特定资源
  • 时间周期(过去一个月、季度、一年)
  • 特定团队成员或模式

Step 2: Git Archaeology

步骤2:Git考古分析

Find Related Commits

查找相关提交记录

bash
undefined
bash
undefined

Commits touching specific files

涉及特定文件的提交记录

git log --oneline -20 -- "path/to/module/*.tf"
git log --oneline -20 -- "path/to/module/*.tf"

Commits mentioning resource types

提及资源类型的提交记录

git log --oneline -20 --grep="aws_security_group"
git log --oneline -20 --grep="aws_security_group"

Commits by pattern in message

提交信息符合特定模式的记录

git log --oneline -20 --grep="fix|rollback|revert"
git log --oneline -20 --grep="fix|rollback|revert"

Commits in date range

特定日期范围内的提交记录

git log --oneline --since="2024-01-01" --until="2024-06-01" -- "*.tf"
undefined
git log --oneline --since="2024-01-01" --until="2024-06-01" -- "*.tf"
undefined

Analyze Commit Patterns

分析提交模式

bash
undefined
bash
undefined

Most frequently changed files

变更最频繁的文件

git log --pretty=format: --name-only -- "*.tf" | sort | uniq -c | sort -rn | head -20
git log --pretty=format: --name-only -- "*.tf" | sort | uniq -c | sort -rn | head -20

Authors and their focus areas

作者及其关注领域

git shortlog -sn -- "environments/prod/"
git shortlog -sn -- "environments/prod/"

Change frequency by day/time

按日期/时间统计变更频率

git log --format="%ad" --date=format:"%A %H:00" -- "*.tf" | sort | uniq -c
undefined
git log --format="%ad" --date=format:"%A %H:00" -- "*.tf" | sort | uniq -c
undefined

Find Reverts and Fixes

查找回滚和修复记录

bash
undefined
bash
undefined

Revert commits

回滚提交记录

git log --oneline --grep="revert|Revert"
git log --oneline --grep="revert|Revert"

Fix commits following changes

变更后的修复提交记录

git log --oneline --grep="fix|hotfix|Fix"
git log --oneline --grep="fix|hotfix|Fix"

Commits with "URGENT" or "EMERGENCY"

包含"URGENT"或"EMERGENCY"的提交记录

git log --oneline --grep="urgent|emergency" -i
undefined
git log --oneline --grep="urgent|emergency" -i
undefined

Step 3: Analyze Change Patterns

步骤3:分析变更模式

Coupling Analysis

耦合分析

Which files change together?
bash
undefined
哪些文件会一起变更?
bash
undefined

For a specific file, what else changes with it?

对于特定文件,查看哪些文件会和它一起变更?

git log --pretty=format:"%H" -- "modules/vpc/main.tf" |
xargs -I {} git show --name-only --pretty=format: {} |
sort | uniq -c | sort -rn | head -20
undefined
git log --pretty=format:"%H" -- "modules/vpc/main.tf" |
xargs -I {} git show --name-only --pretty=format: {} |
sort | uniq -c | sort -rn | head -20
undefined

Change Sequences

变更序列

Common sequences of changes:
  1. VPC changes → followed by security group changes
  2. IAM role changes → followed by policy attachments
  3. RDS changes → followed by parameter group changes
常见的变更序列:
  1. VPC变更 → 随后是安全组变更
  2. IAM角色变更 → 随后是策略附加操作
  3. RDS变更 → 随后是参数组变更

Time Patterns

时间模式

  • Are prod changes clustered on certain days?
  • Are there "risky" times based on past incidents?
  • How long between staging and prod deployments?
  • 生产环境的变更是否集中在某些特定日期?
  • 根据过往事故,是否存在“高风险”时段?
  • 从预发布环境到生产环境的部署间隔时间是多久?

Step 4: Query Memory

步骤4:查询存储的信息

Check stored patterns:
memory/projects/<hash>/patterns.json
memory/projects/<hash>/incidents.json
Look for:
  • Similar past changes and outcomes
  • Known issues with these resources
  • User preferences for this type of change
检查已存储的模式:
memory/projects/<hash>/patterns.json
memory/projects/<hash>/incidents.json
查找以下内容:
  • 类似的过往变更及其结果
  • 这些资源的已知问题
  • 用户对此类变更的偏好

Step 5: Identify Lessons

步骤5:总结经验教训

From Incidents

从事故中总结

For each past incident:
  • What was the trigger?
  • How was it detected?
  • What was the fix?
  • What could have prevented it?
对于每一起过往事故:
  • 触发因素是什么?
  • 如何检测到的?
  • 修复方案是什么?
  • 原本可以如何避免?

From Patterns

从模式中总结

  • What changes tend to cause problems?
  • What practices lead to success?
  • What review processes work well?
  • 哪些变更容易引发问题?
  • 哪些实践能带来成功?
  • 哪些评审流程效果良好?

Step 6: Generate Report

步骤6:生成报告

markdown
undefined
markdown
undefined

Historical Pattern Analysis

历史模式分析

Search Scope

搜索范围

  • Resources: [resources being analyzed]
  • Time period: [date range]
  • Related commits found: [count]
  • 资源:[正在分析的资源]
  • 时间周期:[日期范围]
  • 找到的相关提交记录:[数量]

Change Frequency

变更频率

Resource/FileChanges (90d)Last ChangedPrimary Authors
modules/vpc/main.tf122024-01-10alice, bob
environments/prod/main.tf82024-01-08alice
资源/文件90天内变更次数最后变更时间主要作者
modules/vpc/main.tf122024-01-10alice, bob
environments/prod/main.tf82024-01-08alice

Change Coupling

变更耦合

These resources typically change together:
  1. aws_security_group.web
    aws_instance.web
    (85% correlation)
  2. aws_iam_role.app
    aws_iam_policy.app
    (100% correlation)
以下资源通常会一起变更:
  1. aws_security_group.web
    aws_instance.web
    (85%相关性)
  2. aws_iam_role.app
    aws_iam_policy.app
    (100%相关性)

Past Incidents Related to These Resources

与这些资源相关的过往事故

Incident: [Date] - [Title]

事故:[日期] - [标题]

  • Trigger: [What caused it]
  • Impact: [What happened]
  • Resolution: [How it was fixed]
  • Lesson: [What we learned]
  • Relevance: [How this applies to current change]
  • 触发因素: [事故原因]
  • 影响: [事故后果]
  • 解决方案: [修复方式]
  • 经验教训: [总结的经验]
  • 相关性: [对当前变更的参考价值]

Patterns Identified

识别到的模式

Pattern: [Pattern Name]

模式:[模式名称]

  • Observation: [What we see in history]
  • Frequency: [How often]
  • Implication: [What this means for current change]
  • 观察结果: [从历史记录中发现的内容]
  • 频率: [出现频率]
  • 影响: [对当前变更的意义]

Risk Indicators

风险指标

Based on historical data:
IndicatorCurrent ChangeHistorical Issues
Similar to past incident[Yes/No][Details]
Frequently problematic resource[Yes/No][Details]
Changed by unfamiliar author[Yes/No][Details]
基于历史数据:
指标当前变更情况过往问题
与过往事故类似[是/否][详情]
频繁出现问题的资源[是/否][详情]
由不熟悉的作者进行变更[是/否][详情]

Recommendations

建议

Based on historical patterns:
  1. [Recommendation 1]
  2. [Recommendation 2]
基于历史模式:
  1. [建议1]
  2. [建议2]

Questions Raised

提出的问题

[Questions that history suggests we should answer]
undefined
[历史记录提示我们需要解答的问题]
undefined

Step 7: Update Memory

步骤7:更新存储的信息

Store new patterns discovered:
json
{
  "patterns": [
    {
      "name": "vpc-sg-coupling",
      "description": "VPC changes often require SG updates",
      "confidence": 0.85,
      "last_seen": "2024-01-15"
    }
  ]
}
存储新发现的模式:
json
{
  "patterns": [
    {
      "name": "vpc-sg-coupling",
      "description": "VPC changes often require SG updates",
      "confidence": 0.85,
      "last_seen": "2024-01-15"
    }
  ]
}

Common Patterns to Look For

需要关注的常见模式

Positive Patterns

积极模式

  • Consistent naming conventions
  • Regular, small changes vs. big-bang updates
  • Changes preceded by plan review
  • Post-change validation
  • 一致的命名规范
  • 定期的小变更而非大规模一次性更新
  • 变更前先进行方案评审
  • 变更后进行验证

Warning Patterns

警示模式

  • Frequent reverts
  • Emergency fixes following changes
  • Clustered failures in specific areas
  • "Temporary" changes that persist
  • 频繁的回滚操作
  • 变更后出现紧急修复
  • 特定区域集中出现故障
  • 持续存在的“临时”变更

Anti-Patterns

反模式

  • Direct prod changes without staging
  • Large changes without incremental steps
  • Missing documentation on complex changes
  • Recurring manual interventions
  • 不经过预发布环境直接修改生产环境
  • 不拆分步骤的大规模变更
  • 复杂变更缺少文档
  • 重复的人工干预操作

Integration with Other Skills

与其他技能的集成

This skill feeds into:
  • terraform-plan-review: Provides historical context for risk assessment
  • terraform-drift-detection: Identifies if drift matches past patterns
  • provider-upgrade-analysis: Shows past upgrade experiences
本技能可为以下技能提供支持:
  • terraform-plan-review:为风险评估提供历史背景信息
  • terraform-drift-detection:识别漂移是否符合过往模式
  • provider-upgrade-analysis:展示过往的升级经验