VirtualService 混沌测试/错误注入 在 Istio 中还实现了一个很重要的功能: 错误注入。 可以设置 一定几率 出现 延迟(delay) 和 中止(abort) 错误。 Http Fault Injection Delay 延迟 一定概率出现 缓慢 相应。 fixedDelay: 延迟时间。 格式 1h / 1m / 1s。 最小 1ms。 percentage: 错误触发几率。 0-100 之间。 可以为 double 类型的小数。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……
阅读全文
VirtualService 重试机制 在 Istio VirtualService 中, 有一个很关键的机制: 重试。 发起重试不需要业务本身实现, 而是 istio 通过 envoy 发起的。 其中有几个关键参数 attempts: 重试次数(不含初始请求), 即最大请求次数为 n+1。 perTryTimeout: 发起重试的间隔时间。 必须大于 1ms。 默认于 http route 中的 timeout 一致, 即无 timeout 时间 retryOn: 执行重试的触发条件。 条件值有 envoy 提供: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on http retry 1……
阅读全文
VirtualService 路由重定向 在 VirtualService 配置中, 除了 http rewrite 路由重写之外, 还有 http redirect 路由重定向。 即常说的 30x。 https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRedirect http redirect VirtualService 重定向配置如下。 有三个重要参数 uri: 重定向后的 uri redirectCode: 重定向时的 http response code。 ex: 301, 302。 默认值为 301 。 authority: 重定向后的 http host。 即 http response header 中的 location 字段。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata:……
阅读全文
使用 lego 创建 https 证书 https://go-acme.github.io/lego/dns/ 1 2 3 4 5 6 7 8 9 10 11 #!/bin/bash # cd $(dirname $0) source .env lego --email="${EMAIL}" \ --key-type rsa2048 \ --domains="${DOMAIN1}" \ --path=$(pwd) --dns $DNS_PROVIDER --accept-tos run……
阅读全文
升级项目 之前的项目中只有 prod 服务,具有版本的区分。 现在对项目进行一些升级, 模拟一个多服务的项目。 两个服务, review / prod 服务之前还有调用关系。 prod -> review review 这次新加入了 review 评论服务。 { "1": { "id": "1", "name": "zhangsan", "commment": "istio 功能很强大, 就是配置太麻烦" }, "2": { "id": "1", "name": "wangwu", "commment": "《istio in action》 真是一本……
阅读全文
《istio-in-action系列》 1. 初始化第一个项目 项目代码在 https://github.com/tangx/istio-in-action 命令中有很多快捷键, 参考 install and prepare 1. 创建 namespace 并开启整体 istio 注入 这里已经使用了 alias 命令别名, 如果看不懂, 请参考第一篇 1.1 创建 namespace myistio 1 2 3 4 5 6 kc ns myistio namespace/myistio created kns myistio Context "default" modified. Active namespace is "myistio". 1.2 向 namespace 中开启 istio 注入 1 2 3 4 5 6 7 8 9 10 11 12 13 # 向 ns 加入标签……
阅读全文
《istio-in-action 系列》 1. 安装 docker-k3s-istio 开发环境 1. 安装 docker 我这里使用的是 ubuntu20.04LTS 操作系统 1 2 sudo apt update sudo apt install docker-ce 配置 docker 加速仓库 1 2 3 4 5 6 7 { "registry-mirrors": [ "https://mirror.ccs.tencentyun.com", "https://wlzfs4t4.mirror.aliyuncs.com" ], "bip": "169.253.32.1/24" } 上述是腾讯云和阿里云的加速仓库, 根据需求自行调整。 完成配置后, 重启 docker 1 2 systemctl daemon-reload systemctl restart docker 2. 安装 k3s 2.1 安装 k3s k3s 使用 --docker 模式是为了方便 docker build 产生的……
阅读全文
gorm 数据库表模型声明 - 基础 链接数据库 1 2 3 4 5 6 7 8 9 10 import ( "gorm.io/driver/mysql" "gorm.io/gorm" ) func main() { // refer https://github.com/go-sql-driver/mysql#dsn-data-source-name for details dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) } 常用字段类型与 gorm 默认字段类型 varchar, int, datetime, timestamp 表定义如下 1 2 3 4 5 type Author struct { gorm.Model Name string Password string } auto migrate 后, 可以看到 name, password 默认使用的是 longtext 类型。 1 2 3 4 5 6 7 8 9 10 11 12 show create table authors; CREATE TABLE `authors` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `created_at` datetime(3) DEFAULT NULL, `updated_at` datetime(3) DEFAULT……
阅读全文
Golang 实现深拷贝(DeepCopy)的两种方式 如果在 公众号 文章发现状态为 已更新, 建议点击 查看原文 查看最新内容。 状态: 未更新 原文链接: https://typonotes.com/posts/2021/12/14/golang-struct-interface-deepcopy/ golang deepcopy 的两种实现方式 最近在基于 gin 封装 rum-gonic - github web 框架的过程中,遇到了一个问题。 在注册路由的时候传递是 指针对象, 因此造成所有的 request 请求使用相同的 CreateUser 对象, 出现并发……
阅读全文
Mysql 外键 如果说 mysql 中的 left/right/out join 查询 软链接 关系, 只是通过看似有关系的字段把两张表聚合在一起。 那么 foreign key 就是 硬连接 , 实实在在把两张表聚合在一起。 如果数据的字段的值 不符合 所连接表, 将不允许输入 插入或修改 数据。 创建外键 准备环境 1 2 3 4 5 6 7 create database day123 default charset utf8 collate utf8_general_ci; use day123; create table depart( id int not null primary key auto_increment, name varchar(32) not null ) default charset=utf8; 创建……
阅读全文