产品介绍图

    科技2025-03-28  13

    产品介绍图

    As a software developer there is a high probability that you would have created a presentation, wiki or some other asset to document your architecture. And one of the key component is diagrams. You could have generated a UML class diagram to show your design or a deployment diagram for your cloud deployment.

    作为软件开发人员,您很有可能创建了演示文稿,Wiki或其他资产来记录您的体系结构。 关键要素之一就是图表。 您可能已经生成了一个UML类图来显示您的设计或云部署的部署图。

    But the problem with these diagrams is that once done, mostly it’s never revisited and updated. Your architecture or design evolves over time. Code, infrastructure and every other component gets updated but not your original architecture diagram unless there is significant change. I’m guilty of this as much as the next software developer.

    但是这些图的问题在于,一旦完成,大多数情况下就永远不会重新访问和更新。 您的架构或设计会随着时间而发展。 除非进行重大更改,否则代码,基础结构和所有其他组件都会更新,但不会更新原始架构图。 我和下一个软件开发人员一样对此感到内gui。

    The velocity of changes to a software system has increased with Cloud and Micro services and because of that we have started treating Infrastructure as Code to ensure that your infrastructure provisioning can be versioned and made repeatable and less error-prone. There are tons of changes that keep happening to the infrastructure, addition of database replicas for handling query loads, new compute added, services onboarded etc. But the diagrams are left behind.

    借助Cloud和Micro服务,对软件系统进行更改的速度有所提高,因此,我们已开始将基础架构视为代码,以确保您的基础架构配置可以版本化,可重复且不易出错。 基础架构不断发生大量变化,添加了用于处理查询负载的数据库副本,添加了新的计算,提供了服务等。但是,这些图被遗忘了。

    Enter Diagrams

    输入图表

    It’s an open source python library and as it says on the website

    这是一个开源的python库,正如网站上所说

    Diagrams lets you draw the cloud system architecture in Python code.

    图表使您可以用Python代码绘制云系统架构。

    It was born for prototyping a new system architecture without any design tools. You can also describe or visualize the existing system architecture as well.

    它的诞生是为了在没有任何设计工具的情况下为新的系统架构提供原型。 您还可以描述或可视化现有的系统架构。

    It’s leverages graphviz to render the diagrams. The diagrams are directed graphs provided by graphviz. To install the library, (other pre-requisites and steps can be found here)

    它利用g raphviz渲染图。 这些图是graphviz提供的有向图。 要安装该库,(可以在此处找到其他先决条件和步骤)

    pip install diagrams

    It supports all major cloud vendors and also has very good support for on-premise infrastructure as well.

    它支持所有主要的云供应商,并且还对内部部署基础结构提供了很好的支持。

    Let’s create a diagram for a simple web services deployment in AWS. Where 3 instances of a container are running on ECS with backend DB’s in RDS.

    让我们为AWS中的简单Web服务部署创建一个图表。 容器的3个实例在RDS中具有后端数据库的ECS上运行。

    from diagrams import Cluster, Diagram from diagrams.aws.compute import ECS from diagrams.aws.database import ElastiCache, RDS from diagrams.aws.network import ELB from diagrams.aws.network import Route53 with Diagram("Clustered Web Services", show=False): dns = Route53("dns") lb = ELB("lb") with Cluster("Services"): svc_group = [ECS("web1"), ECS("web2"), ECS("web3")] with Cluster("DB Cluster"): db_master = RDS("userdb") db_master - [RDS("userdb readonly")] memcached = ElastiCache("memcached") #create the graph dns >> lb >> svc_group svc_group >> db_master svc_group >> memcached

    Once you execute the code, it generates a .png file(see below) in the current working directory. Other output formats like jpg, svg are also supported.

    执行代码后,它将在当前工作目录中生成一个.png文件(请参见下文)。 还支持其他输出格式,例如jpg,svg。

    Log Search Application

    日志搜索应用

    Let’s say you want to design a log search system, which indexes logs from S3 into elasticsearch and exposes a set of API’s and nice SPA as UI.

    假设您要设计一个日志搜索系统,该系统将来自S3的日志索引到elasticsearch中,并将一组API和不错的SPA公开为UI。

    from diagrams import Cluster, Diagram from diagrams.aws.compute import EC2 from diagrams.aws.database import RDS from diagrams.aws.network import ELB from diagrams.aws.network import Route53 from diagrams.aws.storage import S3 from diagrams.elastic.elasticsearch import Elasticsearch,Logstash graph_attr = { "fontsize": "45" } with Diagram("Log Search", direction='TB', show=False, graph_attr=graph_attr): dns = Route53("https://searchlogs.example.com") lb = ELB("external load balancer") with Cluster("SPA"): client_group = [EC2("web1"), EC2("web2"), EC2("web3")] with Cluster("API"): svc_group = [EC2("api1"), EC2("api2"), EC2("api3")] with Cluster("DB Cluster"): db_master = RDS("master") db_master - [RDS("read-replica1")] internal_lb = ELB("internal load balancer") with Cluster("Ingest Nodes"): es_master = Elasticsearch("master") ingest_nodes = [es_master, Elasticsearch("ingest-node1"), Elasticsearch("ingest-node2")] with Cluster("Query Nodes"): query_nodes = [Elasticsearch("query-node1"), Elasticsearch("query-node2")] log_bucket = S3('Log Buckets') with Cluster("Forwarder"): internal_lb - [ Logstash('forwarder1'), Logstash('forwarder2'), Logstash('forwarder3') ] - log_bucket dns >> lb >> client_group lb >> svc_group >> internal_lb >> es_master internal_lb >> ingest_nodes es_master >> query_nodes svc_group >> db_master

    Now the image is generated top-to-bottom instead of left-to-right and there are lot of other graph related attributes that can be tweaked as well.

    现在,图像是从上到下而不是从左到右生成的,还有许多其他与图相关的属性也可以调整。

    So now let’s say we have a terraform script which does all the infrastructure provisioning for this application and when we change that we can also update this python script to reflect the latest changes to the stack. This ensures the diagrams are also versioned and kept up to date.

    因此,现在让我们说我们有一个terraform脚本,它为该应用程序执行所有基础结构配置,并且当我们进行更改时,我们还可以更新此python脚本以反映对堆栈的最新更改。 这样可以确保对图表进行版本控制并保持最新。

    We can also further automate things by generating diagrams by connecting to existing cloud infrastructure or even parse descriptors like CloudFormation or terraform in json format.

    我们还可以通过连接到现有的云基础架构或什至以JSON格式解析诸如CloudFormation或terraform的描述符来生成图表,从而进一步使事情自动化。

    翻译自: https://medium.com/@rengarajanm/introducing-diagrams-55b16fa805b9

    产品介绍图

    Processed: 0.012, SQL: 8