• sleuth+zipkin持久化和gateway设置跨域


    目录

    1.为什么使用sleuth+zipkin持久化

    2.使用mysql实现数据持久化

    2.1.创建数据库--省略

    2.2.创建表

    2.3.在启动ZipKin Server的时候,指定数据保存的mysql的信息

    2.4.重启一下自己的项目--省略

    2.5.访问浏览器

    3.gateway设置跨域

    3.1.设置一个跨域配置类

    3.2.设置配置文件


    1.为什么使用sleuth+zipkin持久化

    Zipkin Server默认会将追踪数据信息保存到内存,但这种方式不适合生产环境。Zipkin支持将追踪数据持久化到mysql数据库或elasticsearch中。

    2.使用mysql实现数据持久化

    2.1.创建数据库--省略

    2.2.创建表

    1. CREATE TABLE IF NOT EXISTS zipkin_spans (
    2. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
    3. `trace_id` BIGINT NOT NULL,
    4. `id` BIGINT NOT NULL,
    5. `name` VARCHAR(255) NOT NULL,
    6. `parent_id` BIGINT,
    7. `debug` BIT(1),
    8. `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
    9. `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query' )
    10. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    11. ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
    12. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
    13. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
    14. ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
    15. ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';
    16. CREATE TABLE IF NOT EXISTS zipkin_annotations (
    17. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
    18. `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
    19. `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
    20. `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
    21. `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
    22. `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
    23. `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
    24. `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
    25. `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
    26. `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
    27. `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null' )
    28. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    29. ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
    30. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
    31. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
    32. ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
    33. ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
    34. ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';
    35. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';
    36. CREATE TABLE IF NOT EXISTS zipkin_dependencies (
    37. `day` DATE NOT NULL,
    38. `parent` VARCHAR(255) NOT NULL,
    39. `child` VARCHAR(255) NOT NULL,
    40. `call_count` BIGINT )
    41. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    42. ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

    2.3.在启动ZipKin Server的时候,指定数据保存的mysql的信息

    找到自己下载的位置在地址栏输入cmd

    2.4.重启一下自己的项目--省略

    2.5.访问浏览器

     可以自己在测试一下关闭 ZipKin Server,在重新启动一下看看有没有 ,持久化错了的可能数据库的版本高

    3.gateway设置跨域

    3.1.设置一个跨域配置类

    1. @Configuration
    2. public class CorsConfig {
    3. @Bean
    4. public CorsWebFilter corsFilter() {
    5. CorsConfiguration config = new CorsConfiguration();
    6. config.addAllowedMethod("*");
    7. config.addAllowedOrigin("*");
    8. config.addAllowedHeader("*");
    9. UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    10. source.registerCorsConfiguration("/**", config);
    11. return new CorsWebFilter(source);
    12. }
    13. }

    3.2.设置配置文件

    1. spring:
    2. cloud:
    3. gateway:
    4. globalcors:
    5. cors-configurations:
    6. '[/**]':
    7. allowedOrigins: "*"
    8. allowedMethods:
    9. - GET
    10. - POST
    11. - DELETE
    12. - PUT
    13. - OPTION

  • 相关阅读:
    前端原生socket封装
    [maven] maven 创建 web 项目并嵌套项目
    maven大全(概述、maven安装配置、IDEA配置maven、IDEA创建maven项目并如何使用)
    微信小程序--》数据绑定和事件绑定
    如何使用SMS向客户传递服务信息?指南在这里!
    dht11温湿度传感器工作原理引脚功能电路接线图
    Python 错误、调试和测试
    训练集测试集验证集的区别
    python计算阶层
    【spring mvc】配置默认Servlet处理器
  • 原文地址:https://blog.csdn.net/ne_123456/article/details/126488877