#89 知识分享

2024-08-23

隐性知识是危险的

隐性知识又称为"部落知识",指的是有些知识没有文档,只掌握在团队成员的头脑里面。

如果你想掌握这些知识,只有去询问团队成员。

隐形知识的优点是,省去了文档成本,而且询问相关成员比自己阅读文档更快,当然前提是那位成员能够快速响应。

隐形知识的缺点是,一旦团队扩大规模,它就会失败。对于掌握知识的团队成员来说,回答问题所占用的时间是一个拖累,影响了生产力,也拖慢了团队的开发速度。

另一方面,随着团队规模的扩大和知识变得更加分散,你自己阅读文档和观看视频讲座,会比向他人寻求帮助更快速和方便。

所以,团队越是大,就越要避免"隐形知识",所有知识尽量文档化,让团队成员能够方便地查阅。

团队知识分享是一个很重要的事情。

  1. 周会分享
  2. 专题分享/讨论会
  3. 文档维护制度

#88 ntfy 信息推送小工具

2024-05-05

发现一个信息推送小工具,ntfy。挺好用的,不需要我自己做的那个简陋版本了。

服务端是 Golang 开发的,然后官方支持的客户端:

  • Phone
    • Android
    • iOS
  • Web APP (没有看到源代码仓库)
  • CLI

无需注册,客户端订阅指定主题,然后直接往这个主题推送消息就行了。

这是官网上的几个推送示例:

curl -d "Backup successful 😀" ntfy.sh/wuhan
curl -H "Title: Dogs are better than cats" -d "Oh my ..." ntfy.sh/wuhan
curl -H "Tags: horse,unicorn" -d "Unicorns are just horses with unique horns" ntfy.sh/wuhan

订阅与推送的相关接口文档,官网写得足够好了,非常容易集成。

项目完全开源,包括 Android / iOS 端,可以自己部署,也可以就是用托管服务。
免费套餐对于个人使用也是足够了的,每天 250 条消息。

小问题:

  1. 只有 Web APP 支持 Markdown,而且支持的语法比较少,不大够。

命令行

ntfy pub -t <title> -f <filepath> <topic> <message>
-> % ntfy
NAME:
   ntfy - Simple pub-sub notification service

USAGE:
   ntfy [OPTION..]

COMMANDS:
   help, h  Shows a list of commands or help for one command
   Client commands:
     publish, pub, send, trigger  Send message via a ntfy server
     subscribe, sub               Subscribe to one or more topics on a ntfy server

GLOBAL OPTIONS:
   --debug, -d                                                                                                            enable debug logging (default: false) [$NTFY_DEBUG]
   --trace                                                                                                                enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
   --no-log-dates, --no_log_dates                                                                                         disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
   --log-level value, --log_level value                                                                                   set log level (default: "INFO") [$NTFY_LOG_LEVEL]
   --log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ]  set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
   --log-format value, --log_format value                                                                                 set log format (default: "text") [$NTFY_LOG_FORMAT]
   --log-file value, --log_file value                                                                                     set log file, default is STDOUT [$NTFY_LOG_FILE]
   --help, -h                                                                                                             show help

Try 'ntfy COMMAND --help' or https://ntfy.sh/docs/ for more information.

To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
If you want to chat, simply join the Discord server (https://discord.gg/cT7ECsZj9w), or
the Matrix room (https://matrix.to/#/#ntfy:matrix.org).

ntfy 2.11.0 (Homebre), runtime go1.22.3, built at 2024-05-13T20:11:29Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2

-> % ntfy pub --help
NAME:
   ntfy publish - Send message via a ntfy server

USAGE:
   ntfy publish [OPTIONS..] TOPIC [MESSAGE...]
   ntfy publish [OPTIONS..] --wait-cmd COMMAND...
   NTFY_TOPIC=.. ntfy publish [OPTIONS..] [MESSAGE...]

CATEGORY:
   Client commands

DESCRIPTION:
   Publish a message to a ntfy server.

   Examples:
     ntfy publish mytopic This is my message                 # Send simple message
     ntfy send myserver.com/mytopic "This is my message"     # Send message to different default host
     ntfy pub -p high backups "Backups failed"               # Send high priority message
     ntfy pub --tags=warning,skull backups "Backups failed"  # Add tags/emojis to message
     ntfy pub --delay=10s delayed_topic Laterzz              # Delay message by 10s
     ntfy pub --at=8:30am delayed_topic Laterzz              # Send message at 8:30am
     ntfy pub -e phil@example.com alerts 'App is down!'      # Also send email to phil@example.com
     ntfy pub --click="https://reddit.com" redd 'New msg'    # Opens Reddit when notification is clicked
     ntfy pub --icon="http://some.tld/icon.png" 'Icon!'      # Send notification with custom icon
     ntfy pub --attach="http://some.tld/file.zip" files      # Send ZIP archive from URL as attachment
     ntfy pub --file=flower.jpg flowers 'Nice!'              # Send image.jpg as attachment
     ntfy pub -u phil:mypass secret Psst                     # Publish with username/password
     ntfy pub --wait-pid 1234 mytopic                        # Wait for process 1234 to exit before publishing
     ntfy pub --wait-cmd mytopic rsync -av ./ /tmp/a         # Run command and publish after it completes
     NTFY_USER=phil:mypass ntfy pub secret Psst              # Use env variables to set username/password
     NTFY_TOPIC=mytopic ntfy pub "some message"              # Use NTFY_TOPIC variable as topic
     cat flower.jpg | ntfy pub --file=- flowers 'Nice!'      # Same as above, send image.jpg as attachment
     ntfy trigger mywebhook                                  # Sending without message, useful for webhooks

   Please also check out the docs on publishing messages. Especially for the --tags and --delay options,
   it has incredibly useful information: https://ntfy.sh/docs/publish/.

   The default config file for all client commands is /etc/ntfy/client.yml (if root user),
   or "~/Library/Application Support/ntfy/client.yml" for all other users.

OPTIONS:
   --debug, -d                                                                                                            enable debug logging (default: false) [$NTFY_DEBUG]
   --trace                                                                                                                enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
   --no-log-dates, --no_log_dates                                                                                         disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
   --log-level value, --log_level value                                                                                   set log level (default: "INFO") [$NTFY_LOG_LEVEL]
   --log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ]  set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
   --log-format value, --log_format value                                                                                 set log format (default: "text") [$NTFY_LOG_FORMAT]
   --log-file value, --log_file value                                                                                     set log file, default is STDOUT [$NTFY_LOG_FILE]
   --config value, -c value                                                                                               client config file [$NTFY_CONFIG]
   --title value, -t value                                                                                                message title [$NTFY_TITLE]
   --message value, -m value                                                                                              message body [$NTFY_MESSAGE]
   --priority value, -p value                                                                                             priority of the message (1=min, 2=low, 3=default, 4=high, 5=max) [$NTFY_PRIORITY]
   --tags value, --tag value, -T value                                                                                    comma separated list of tags and emojis [$NTFY_TAGS]
   --delay value, --at value, --in value, -D value                                                                        delay/schedule message [$NTFY_DELAY]
   --click value, -U value                                                                                                URL to open when notification is clicked [$NTFY_CLICK]
   --icon value, -i value                                                                                                 URL to use as notification icon [$NTFY_ICON]
   --actions value, -A value                                                                                              actions JSON array or simple definition [$NTFY_ACTIONS]
   --attach value, -a value                                                                                               URL to send as an external attachment [$NTFY_ATTACH]
   --markdown, --md                                                                                                       Message is formatted as Markdown (default: false) [$NTFY_MARKDOWN]
   --filename value, --name value, -n value                                                                               filename for the attachment [$NTFY_FILENAME]
   --file value, -f value                                                                                                 file to upload as an attachment [$NTFY_FILE]
   --email value, --mail value, -e value                                                                                  also send to e-mail address [$NTFY_EMAIL]
   --user value, -u value                                                                                                 username[:password] used to auth against the server [$NTFY_USER]
   --token value, -k value                                                                                                access token used to auth against the server [$NTFY_TOKEN]
   --wait-pid value, --wait_pid value, --pid value                                                                        wait until PID exits before publishing (default: 0) [$NTFY_WAIT_PID]
   --wait-cmd, --wait_cmd, --cmd, --done                                                                                  run command and wait until it finishes before publishing (default: false) [$NTFY_WAIT_CMD]
   --no-cache, --no_cache, -C                                                                                             do not cache message server-side (default: false) [$NTFY_NO_CACHE]
   --no-firebase, --no_firebase, -F                                                                                       do not forward message to Firebase (default: false) [$NTFY_NO_FIREBASE]
   --quiet, -q                                                                                                            do not print message (default: false) [$NTFY_QUIET]
   --help, -h                                                                                                             show help

参考资料与拓展阅读

#84 异常流量监控

2023-12-09

突然来了大量客户请求,我们无法判断这些请求是正常的,还是客户被攻击所致。为了避免产生严重客损,我们需要识别到这些突然出现的流量高峰,并进行通知以及执行一些处理措施。

客户配置

比如:

request_limit = {
  rate: {
    // 客户配置
    3600: 1000, // 指定 API 1 小时之内的请求量上限
    86400: 8000, // 指定 API 1 天之内的请求量上限
  },
  rate_computed: {
    // 根据之前的请求情况,结合客户配置计算出来的值(不小于客户配置)
    3600: 1000,
    86400: 8000,
  },
  strategy: {
    times_to_notify: 1, // 连续触发几次之后通知
    times_to_suspend: 3, // 连续触发几次之后暂停
    times_to_intercept: 12, // 连续触发几次之后拦截请求
  },
};
  1. 默认给所有客户开启最近 1 小时和最近 24 小时的限制。
  2. 速率控制以小时为单位([1, 24]

定时检查

  1. 定时执行
 5 10 15 20 25 30
35 40 45 50 55  0
  1. 查询过去 1 天有请求的客户清单,根据系统参数(可能还有业务上其他条件)跳过忽略检查客户

  2. 逐个客户查询最近 5 分钟内的请求量,并将 5 分钟数据统计到小时内
    然后逐个时间区间配置,判断总请求量是否超出预设值

end_min = (minute // 5) * 5
start_min = end_minute - 5
  1. 如果流量异常,按照指定策略触发相关事件

客户处理

PS:这个机制的目的是处理异常流量,如果正常的请求量上来了应该调整客户配置。

  1. 警告页面给出客户过去的请求情况,标出告警时间段的数据
  2. 让客户选择处理方案:
  3. 忽略并继续
  4. 清空暂停队列并继续
    可以查看下载受影响的请求信息
  5. 暂不处理
  6. 往后 24 小时之内,下一次触发告警的数量,提供一个默认值(当前请求量的 1.5 倍)
    另一种思路:如果客户选择继续请求,不用填下一次告警的数量,后面计算的时候直接跳过过去一段时间(比如 6 小时)的请求量。

#83 信创是什么

2023-11-30

https://www.cnxclm.com/read-736-1.html

信创,全名:信息技术应用创新,是政府的一个计划,目的是推广国产 IT 技术应用,最终实现 IT 领域自主可控。
这个计划是什么时候开始的我不清楚,确实是自从美国开始对中国展开贸易战之后,这个词才广为人知,也就是近几年的事情。

目前主要是党政军相关项目国产化,以后可能会推广到国企与事业单位。

信创项目的规模不断扩大,自 2019 年起大幅加速。
从 2011 年到 2018 年,信创项目的政府合同规模达到 1.99 亿人民币(合 2852 万美元);
2020 年跃升至 279.2 亿人民币(合 40 亿美元),
2021 年初至 2022 年 11 月为 184.5 亿人民币(合 26.4 亿美元)。
预计 2025 年,这一领域估值将达 2 万亿元(1250 亿美元)。

内容

  • 基础设施:CPU、芯片、服务器、交换机、路由器
  • 基础软件:操作系统、数据库、大数据、中间件、云平台(如 IaaS、PaaS 和低代码平台)
  • 应用软件:办公软件、通用软件、行业软件等
  • 信息安全

信创工委会

https://itaic.org.cn/

2016 年,信创工委会(信息技术应用创新工作委员会)成立。

包括很多知名国产厂商都在信创委员会中,比如:

  • 龙芯(CPU)
  • 浪潮(服务器)
  • 深信服
  • 华为
  • 麒麟软件(操作系统)
  • WPS
  • 奇虎 360
  • 奇安信(360 企业安全)

具体哪些产品符合信创要求,似乎也没有看到一个公开的清单。

项目

  • 操作系统

  • 麒麟 Kylin

  • 统信 UOS
  • 红旗
  • 华为 EularOS

  • 数据库

  • 武汉达梦

  • 其他

  • 东方通

#81 开源编程字体

2023-11-14

已经有的开源字体:

厂商 字体 协议 网址
Adobe Source Code Pro OFL https://adobe-fonts.github.io/source-code-pro/ / Repo
Google Noto OFL https://fonts.google.com/noto / Repo
GitHub Monaspace OFL https://monaspace.githubnext.com/ / Repo
JetBrain Mono OFL https://www.jetbrains.com/zh-cn/lp/mono/ / Repo

Adobe 的 Source Code Pro 补上 CJK 文字就成为了我们熟悉的思源黑体系列。

Google Noto 其实就是思源黑体的基础上,再补充其他语言,试图给所有语言文字一个统一的展示效果。
Noto 这个名字来自 No More Tofu。

Maple Mono

https://font.subf.dev/zh-cn/
https://github.com/subframe7536/maple-font

VSCode 中字体配置加上 “Maple Mono Normal CN” 就好了。
中文字符宽度等于两个英文字符。
NL:不含连字
Normal:去掉手写风格(默认字体在斜体场景下会有手写风格)
NF:包含图标字符

支持这些符号:

[DEBUG] [INFO] [WARN] [ERROR]
[TODO] [FIXME]

# Maple Mono
brew install --cask font-maple-mono
# Maple Mono NF
brew install --cask font-maple-mono-nf
# Maple Mono CN
brew install --cask font-maple-mono-cn
# Maple Mono NF CN
brew install --cask font-maple-mono-nf-cn

# Maple Mono Normal
brew install --cask font-maple-mono-normal
# Maple Mono Normal NF
brew install --cask font-maple-mono-normal-nf
# Maple Mono Normal CN
brew install --cask font-maple-mono-normal-cn
# Maple Mono Normal NF CN
brew install --cask font-maple-mono-normal-nf-cn