resource

package
v0.0.0-...-c2c008b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2022 License: LGPL-2.1 Imports: 14 Imported by: 0

README

资源管理

资源的统一搜索

资源标签管理

应用标签

应用在部署时 需要申请对应的资源, 申请完成后 需要补充标签:

比如 deploy

  • deploy = "app1-v1"
  • deploy = "app2-v1"
监控标签

我们使用2个标签:

  • prometheus.io/node/enabled = "true"

  • prometheus.io/node/endpoint = "9100:/metrics"

  • prometheus.io/node/endpoint = "9200:/metrics"

  • prometheus.io/appv1/enabled = "true"

  • prometheus.io/appv1/endpoint = "9100:/metrics"

  • prometheus.io/appv1/endpoint = "9200:/metrics"

比如搜索 prometheus.io/%/enabled = "true"

[
    {
        "targets": ["10.0.10.2:9100", "10.0.10.3:9100", "10.0.10.4:9100", "10.0.10.5:9100"],
        "labels": {
            "domain": "admin",
            "namespace": "default",
            "env": "prod",
            "accout": "acount11",
            "vendor": "ali_yun",
            "region": "hangzou",
            "instance_id":"ins-xxxxx"
        }
    },
    ...
]

资源生命周期管理

资源申请
资源释放逻辑

create cluster app-v1 devcloud.com/deploy = app-v1 [h1, h2, bucket1, mysql01, dba]

资源状态

  • 3天的 滞留期, 资源无人使用的最大窗口,
  • 超过3天都未使用, 将进入待观察期(4天), 资源会停止服务
  • 当资源超过观察期都还未有人处理,会直接释放, 并记录资源状态 (记录保存期,365天)

Documentation

Index

Constants

View Source
const (
	// SQL 比较操作  =
	Operator_EQUAL = "="
	// SQL 比较操作  !=
	Operator_NOT_EQUAL = "!="
	// SQL 比较操作  LIKE
	Operator_LIKE_EQUAL = "=~"
	// SQL 比较操作  NOT LIKE
	Operator_NOT_LIKE_EQUAL = "!~"
)
View Source
const (
	AppName = "resource"
)

Variables

View Source
var (
	UpdateAction_name = map[int32]string{
		0: "ADD",
		1: "REMOVE",
	}
	UpdateAction_value = map[string]int32{
		"ADD":    0,
		"REMOVE": 1,
	}
)

Enum value maps for UpdateAction.

View Source
var (
	Vendor_name = map[int32]string{
		0: "ALIYUN",
		1: "TENCENT",
		2: "HUAWEI",
		3: "VSPHERE",
		4: "AMAZON",
	}
	Vendor_value = map[string]int32{
		"ALIYUN":  0,
		"TENCENT": 1,
		"HUAWEI":  2,
		"VSPHERE": 3,
		"AMAZON":  4,
	}
)

Enum value maps for Vendor.

View Source
var (
	Type_name = map[int32]string{
		0:  "HOST",
		1:  "RDS",
		99: "BILL",
	}
	Type_value = map[string]int32{
		"HOST": 0,
		"RDS":  1,
		"BILL": 99,
	}
)

Enum value maps for Type.

View Source
var (
	UsageMode_name = map[int32]string{
		0: "SHARED",
		1: "MONOPOLY",
	}
	UsageMode_value = map[string]int32{
		"SHARED":   0,
		"MONOPOLY": 1,
	}
)

Enum value maps for UsageMode.

View Source
var (
	TagType_name = map[int32]string{
		0: "USER",
		1: "THIRD",
		2: "SYSTEM",
	}
	TagType_value = map[string]int32{
		"USER":   0,
		"THIRD":  1,
		"SYSTEM": 2,
	}
)

Enum value maps for TagType.

View Source
var File_apps_resource_pb_resource_proto protoreflect.FileDescriptor
View Source
var Service_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "course.cmdb.resource.Service",
	HandlerType: (*ServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Search",
			Handler:    _Service_Search_Handler,
		},
		{
			MethodName: "QueryTag",
			Handler:    _Service_QueryTag_Handler,
		},
		{
			MethodName: "UpdateTag",
			Handler:    _Service_UpdateTag_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "apps/resource/pb/resource.proto",
}

Service_ServiceDesc is the grpc.ServiceDesc for Service service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterServiceServer

func RegisterServiceServer(s grpc.ServiceRegistrar, srv ServiceServer)

Types

type Base

type Base struct {

	// 全局唯一Id, 直接使用个云商自己的Id、云商内唯一ID ,可以通过厂商+1d做到唯一
	// @gotags: json:"id" validate:"required"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" validate:"required"`
	// 同步时间,什么时候录入系统的
	// @gotags: json:"sync_at"
	SyncAt int64 `protobuf:"varint,2,opt,name=sync_at,json=syncAt,proto3" json:"sync_at"`
	// 用于同步的凭证ID,需要权限凭证才能读取活着操作云商的资源
	// @gotags: json:"secret_id"
	SecretId string `protobuf:"bytes,3,opt,name=secret_id,json=secretId,proto3" json:"secret_id"`
	// 厂商
	// @gotags: json:"vendor"
	Vendor Vendor `protobuf:"varint,4,opt,name=vendor,proto3,enum=course.cmdb.resource.Vendor" json:"vendor"`
	// 资源类型
	// @gotags: json:"resource_type"
	ResourceType Type `protobuf:"varint,5,opt,name=resource_type,json=resourceType,proto3,enum=course.cmdb.resource.Type" json:"resource_type"`
	// 地域 //如果这种变动大的字段可以做一个api专门处理变动的资源
	// @gotags: json:"region"
	Region string `protobuf:"bytes,6,opt,name=region,proto3" json:"region"`
	// 区域
	// @gotags: json:"zone"
	Zone string `protobuf:"bytes,7,opt,name=zone,proto3" json:"zone"`
	// 创建时间 //同步不一定是创建的时间。
	// @gotags: json:"create_at"
	CreateAt int64 `protobuf:"varint,8,opt,name=create_at,json=createAt,proto3" json:"create_at"`
	// 基础数据Hash,通用数据hash 用于比对是否需要更新,用于提升效率
	// @gotags: json:"resource_hash"
	ResourceHash string `protobuf:"bytes,10,opt,name=resource_hash,json=resourceHash,proto3" json:"resource_hash"`
	// 描述数据Hash 资源的特有属性,就是其他的模型表,比如主机有gpu
	// @gotags: json:"describe_hash"
	DescribeHash string `protobuf:"bytes,11,opt,name=describe_hash,json=describeHash,proto3" json:"describe_hash"`
	// Resource信息释放有变化,用于描述上面两个信息是否有变化
	// @gotags: json:"resource_hash_changed,omitempty"
	ResourceHashChanged bool `protobuf:"varint,12,opt,name=resource_hash_changed,json=resourceHashChanged,proto3" json:"resource_hash_changed,omitempty"`
	// Describe信息释放有变化
	// @gotags: json:"describe_hash_changed,omitempty"
	DescribeHashChanged bool `protobuf:"varint,13,opt,name=describe_hash_changed,json=describeHashChanged,proto3" json:"describe_hash_changed,omitempty"`
	// 资源所属空间 ,跟我们的权限系统挂钩,属于哪个项目
	// @gotags: json:"namespace"
	Namespace string `protobuf:"bytes,14,opt,name=namespace,proto3" json:"namespace"`
	// 资源所属环境
	// @gotags: json:"env"
	Env string `protobuf:"bytes,15,opt,name=env,proto3" json:"env"`
	// 使用方式(可选的)
	// @gotags: json:"usage_mode"
	UsageMode UsageMode `protobuf:"varint,16,opt,name=usage_mode,json=usageMode,proto3,enum=course.cmdb.resource.UsageMode" json:"usage_mode"`
	// 共享策略, 当一个资源被多个应用共享时, 可以指定允许的应用
	// @gotags: json:"shared_policy"
	SharedPolicy *SharedPolicy `protobuf:"bytes,17,opt,name=shared_policy,json=sharedPolicy,proto3" json:"shared_policy"`
	// 资源所属域,一个组织或者一个公司,为了做多租户模型使用,多个公司使用。
	// @gotags: json:"domain"
	Domain string `protobuf:"bytes,18,opt,name=domain,proto3" json:"domain"`
	// contains filtered or unexported fields
}

定义资源信息的固有属性 需要自己去云服务厂商抽象出这些信息的字段

func (*Base) Descriptor deprecated

func (*Base) Descriptor() ([]byte, []int)

Deprecated: Use Base.ProtoReflect.Descriptor instead.

func (*Base) GetCreateAt

func (x *Base) GetCreateAt() int64

func (*Base) GetDescribeHash

func (x *Base) GetDescribeHash() string

func (*Base) GetDescribeHashChanged

func (x *Base) GetDescribeHashChanged() bool

func (*Base) GetDomain

func (x *Base) GetDomain() string

func (*Base) GetEnv

func (x *Base) GetEnv() string

func (*Base) GetId

func (x *Base) GetId() string

func (*Base) GetNamespace

func (x *Base) GetNamespace() string

func (*Base) GetRegion

func (x *Base) GetRegion() string

func (*Base) GetResourceHash

func (x *Base) GetResourceHash() string

func (*Base) GetResourceHashChanged

func (x *Base) GetResourceHashChanged() bool

func (*Base) GetResourceType

func (x *Base) GetResourceType() Type

func (*Base) GetSecretId

func (x *Base) GetSecretId() string

func (*Base) GetSharedPolicy

func (x *Base) GetSharedPolicy() *SharedPolicy

func (*Base) GetSyncAt

func (x *Base) GetSyncAt() int64

func (*Base) GetUsageMode

func (x *Base) GetUsageMode() UsageMode

func (*Base) GetVendor

func (x *Base) GetVendor() Vendor

func (*Base) GetZone

func (x *Base) GetZone() string

func (*Base) ProtoMessage

func (*Base) ProtoMessage()

func (*Base) ProtoReflect

func (x *Base) ProtoReflect() protoreflect.Message

func (*Base) Reset

func (x *Base) Reset()

func (*Base) String

func (x *Base) String() string

type Information

type Information struct {

	// 过期时间
	// @gotags: json:"expire_at"
	ExpireAt int64 `protobuf:"varint,1,opt,name=expire_at,json=expireAt,proto3" json:"expire_at"`
	// 种类,计算型,内存型
	// @gotags: json:"category"
	Category string `protobuf:"bytes,2,opt,name=category,proto3" json:"category"`
	// 规格,small(1c1g),根据云商的概念
	// @gotags: json:"type"
	Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type"`
	// 资源名称
	// @gotags: json:"name"
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name"`
	// 资源描述
	// @gotags: json:"description"
	Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description"`
	// 服务商中的状态,统一多个云商的状态
	// @gotags: json:"status"
	Status string `protobuf:"bytes,6,opt,name=status,proto3" json:"status"`
	// 资源标签,key=value 一个标签
	// @gotags: json:"tags"
	Tags []*Tag `protobuf:"bytes,7,rep,name=tags,proto3" json:"tags"`
	// 更新时间
	// @gotags: json:"update_at"
	UpdateAt int64 `protobuf:"varint,8,opt,name=update_at,json=updateAt,proto3" json:"update_at"`
	// 同步的账号,资源的所属账号
	// @gotags: json:"sync_account"
	SyncAccount string `protobuf:"bytes,9,opt,name=sync_account,json=syncAccount,proto3" json:"sync_account"`
	// 公网IP, 或者域名,用于检索
	// @gotags: json:"public_ip"
	PublicIp []string `protobuf:"bytes,10,rep,name=public_ip,json=publicIp,proto3" json:"public_ip"`
	// 内网IP, 或者域名
	// @gotags: json:"private_ip"
	PrivateIp []string `protobuf:"bytes,11,rep,name=private_ip,json=privateIp,proto3" json:"private_ip"`
	// 实例付费方式,按量,包年包月。idc机器一次性付费(自定义添加)
	// @gotags: json:"pay_type"
	PayType string `protobuf:"bytes,12,opt,name=pay_type,json=payType,proto3" json:"pay_type"`
	// contains filtered or unexported fields
}

通用属性,可能会变化,用于快速解锁资源

func (*Information) AddTag

func (r *Information) AddTag(t *Tag)

把tag添加到information的哪个字段上面

func (*Information) Descriptor deprecated

func (*Information) Descriptor() ([]byte, []int)

Deprecated: Use Information.ProtoReflect.Descriptor instead.

func (*Information) GetCategory

func (x *Information) GetCategory() string

func (*Information) GetDescription

func (x *Information) GetDescription() string

func (*Information) GetExpireAt

func (x *Information) GetExpireAt() int64

func (*Information) GetName

func (x *Information) GetName() string

func (*Information) GetPayType

func (x *Information) GetPayType() string

func (*Information) GetPrivateIp

func (x *Information) GetPrivateIp() []string

func (*Information) GetPublicIp

func (x *Information) GetPublicIp() []string

func (*Information) GetStatus

func (x *Information) GetStatus() string

func (*Information) GetSyncAccount

func (x *Information) GetSyncAccount() string

func (*Information) GetTags

func (x *Information) GetTags() []*Tag

func (*Information) GetType

func (x *Information) GetType() string

func (*Information) GetUpdateAt

func (x *Information) GetUpdateAt() int64

func (*Information) Hash

func (i *Information) Hash() string

Information结构体的hash 作为一个方法,hash自己

func (*Information) LoadPrivateIPString

func (i *Information) LoadPrivateIPString(s string)

从数据库取得数据需要进行格式化 独立绑定一个方法单独处理这个逻辑

func (*Information) LoadPublicIPString

func (i *Information) LoadPublicIPString(s string)

func (*Information) PrivateIPToString

func (i *Information) PrivateIPToString() string

ip地址的转换逻辑 数组转为string,用逗号链接

func (*Information) ProtoMessage

func (*Information) ProtoMessage()

func (*Information) ProtoReflect

func (x *Information) ProtoReflect() protoreflect.Message

func (*Information) PublicIPToString

func (i *Information) PublicIPToString() string

func (*Information) Reset

func (x *Information) Reset()

func (*Information) String

func (x *Information) String() string

type Operator

type Operator string

定义四种表达式,用于匹配values的场景2 使用符号搜索 tag的比较操作符号类比promethus做的 官网找到四种操作符号 把四种符号映射为sql语句

type QueryTagRequest

type QueryTagRequest struct {

	// 资源id
	// @gotags: json:"resource_ids"
	ResourceIds []string `protobuf:"bytes,1,rep,name=resource_ids,json=resourceIds,proto3" json:"resource_ids"`
	// contains filtered or unexported fields
}

请求tag的参数

func (*QueryTagRequest) Descriptor deprecated

func (*QueryTagRequest) Descriptor() ([]byte, []int)

Deprecated: Use QueryTagRequest.ProtoReflect.Descriptor instead.

func (*QueryTagRequest) GetResourceIds

func (x *QueryTagRequest) GetResourceIds() []string

func (*QueryTagRequest) ProtoMessage

func (*QueryTagRequest) ProtoMessage()

func (*QueryTagRequest) ProtoReflect

func (x *QueryTagRequest) ProtoReflect() protoreflect.Message

func (*QueryTagRequest) Reset

func (x *QueryTagRequest) Reset()

func (*QueryTagRequest) String

func (x *QueryTagRequest) String() string

type ReleasePlan

type ReleasePlan struct {

	// 释放原因
	// @gotags: json:"reason"
	Reason string `protobuf:"bytes,1,opt,name=reason,proto3" json:"reason"`
	// 是否立即释放
	// @gotags: json:"immediately"
	Immediately bool `protobuf:"varint,2,opt,name=immediately,proto3" json:"immediately"`
	// 计划时间
	// @gotags: json:"plan_at"
	PlanAt int64 `protobuf:"varint,3,opt,name=plan_at,json=planAt,proto3" json:"plan_at"`
	// 执行时间
	// @gotags: json:"exec_at"
	ExecAt int64 `protobuf:"varint,4,opt,name=exec_at,json=execAt,proto3" json:"exec_at"`
	// 释放前 提前几天通知, 过期后 云商会自动释放的也需要提前通知
	// @gotags: json:"notice_before_days"
	NoticeBeforeDays int64 `protobuf:"varint,5,opt,name=notice_before_days,json=noticeBeforeDays,proto3" json:"notice_before_days"`
	// 资源释放后, 什么时候销毁该数据
	// @gotags: json:"destory_at"
	DestoryAt int64 `protobuf:"varint,6,opt,name=destory_at,json=destoryAt,proto3" json:"destory_at"`
	// contains filtered or unexported fields
}

资源释放计划

func (*ReleasePlan) Descriptor deprecated

func (*ReleasePlan) Descriptor() ([]byte, []int)

Deprecated: Use ReleasePlan.ProtoReflect.Descriptor instead.

func (*ReleasePlan) GetDestoryAt

func (x *ReleasePlan) GetDestoryAt() int64

func (*ReleasePlan) GetExecAt

func (x *ReleasePlan) GetExecAt() int64

func (*ReleasePlan) GetImmediately

func (x *ReleasePlan) GetImmediately() bool

func (*ReleasePlan) GetNoticeBeforeDays

func (x *ReleasePlan) GetNoticeBeforeDays() int64

func (*ReleasePlan) GetPlanAt

func (x *ReleasePlan) GetPlanAt() int64

func (*ReleasePlan) GetReason

func (x *ReleasePlan) GetReason() string

func (*ReleasePlan) ProtoMessage

func (*ReleasePlan) ProtoMessage()

func (*ReleasePlan) ProtoReflect

func (x *ReleasePlan) ProtoReflect() protoreflect.Message

func (*ReleasePlan) Reset

func (x *ReleasePlan) Reset()

func (*ReleasePlan) String

func (x *ReleasePlan) String() string

type Resource

type Resource struct {

	//资源元数据信息,固有属性,比如云商
	//@gotags:json:"base"
	Base *Base `protobuf:"bytes,1,opt,name=base,proto3" json:"base"`
	//资源信息,通用信息,比如:IP
	//@gotags: json:"information"
	Information *Information `protobuf:"bytes,2,opt,name=information,proto3" json:"information"`
	//资源释放计划
	//@gotags: json:"release_plan"
	ReleasePlan *ReleasePlan `protobuf:"bytes,3,opt,name=release_plan,json=releasePlan,proto3" json:"release_plan"`
	// contains filtered or unexported fields
}

资源的描述信息

func NewDefaultResource

func NewDefaultResource() *Resource

func (*Resource) Descriptor deprecated

func (*Resource) Descriptor() ([]byte, []int)

Deprecated: Use Resource.ProtoReflect.Descriptor instead.

func (*Resource) GetBase

func (x *Resource) GetBase() *Base

func (*Resource) GetInformation

func (x *Resource) GetInformation() *Information

func (*Resource) GetReleasePlan

func (x *Resource) GetReleasePlan() *ReleasePlan

func (*Resource) ProtoMessage

func (*Resource) ProtoMessage()

func (*Resource) ProtoReflect

func (x *Resource) ProtoReflect() protoreflect.Message

func (*Resource) Reset

func (x *Resource) Reset()

func (*Resource) String

func (x *Resource) String() string

type ResourceSet

type ResourceSet struct {

	// @gotags: json:"total"
	Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total"`
	// @gotags: json:"items"
	Items []*Resource `protobuf:"bytes,2,rep,name=items,proto3" json:"items"`
	// contains filtered or unexported fields
}

func NewResourceSet

func NewResourceSet() *ResourceSet

func (*ResourceSet) Add

func (s *ResourceSet) Add(item *Resource)

add逻辑就是

func (*ResourceSet) Descriptor deprecated

func (*ResourceSet) Descriptor() ([]byte, []int)

Deprecated: Use ResourceSet.ProtoReflect.Descriptor instead.

func (*ResourceSet) GetItems

func (x *ResourceSet) GetItems() []*Resource

func (*ResourceSet) GetTotal

func (x *ResourceSet) GetTotal() int64

func (*ResourceSet) ProtoMessage

func (*ResourceSet) ProtoMessage()

func (*ResourceSet) ProtoReflect

func (x *ResourceSet) ProtoReflect() protoreflect.Message

func (*ResourceSet) Reset

func (x *ResourceSet) Reset()

func (*ResourceSet) ResourceIds

func (s *ResourceSet) ResourceIds() (ids []string)

ResourceIds 方法 把item里面的所有id取出,放到ids []string 数组里面去返回 把属性里面的id取出来转换为string的一个操作 循环到append到一个数组里面

func (*ResourceSet) String

func (x *ResourceSet) String() string

func (*ResourceSet) UpdateTag

func (s *ResourceSet) UpdateTag(tags []*Tag)

UpdateTag 是一个循环 先循环所有的tag 把tag里面的 ResourceId 跟我们的列表里面的item里面的id相等 我们就把这个tag添加到information里面Tag 字段里面 所以我们的information 需要添加一个addtag的功能

type SearchRequest

type SearchRequest struct {

	// 分页参数
	// @gotags: json:"page"
	Page *request.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page"`
	// 资源所属域
	// @gotags: json:"domain"
	Domain string `protobuf:"bytes,2,opt,name=domain,proto3" json:"domain"`
	// 资源所属空间
	// @gotags: json:"namespace"
	Namespace string `protobuf:"bytes,3,opt,name=namespace,proto3" json:"namespace"`
	// 资源所属环境
	// @gotags: json:"env"
	Env string `protobuf:"bytes,4,opt,name=env,proto3" json:"env"`
	// 使用方式
	// @gotags: json:"usage_mode"
	UsageMode *UsageMode `protobuf:"varint,5,opt,name=usage_mode,json=usageMode,proto3,enum=course.cmdb.resource.UsageMode,oneof" json:"usage_mode"`
	// 厂商
	// @gotags: json:"vendor"
	Vendor *Vendor `protobuf:"varint,6,opt,name=vendor,proto3,enum=course.cmdb.resource.Vendor,oneof" json:"vendor"`
	// 同步的账号
	// @gotags: json:"sync_account"
	SyncAccount string `protobuf:"bytes,7,opt,name=sync_account,json=syncAccount,proto3" json:"sync_account"`
	// 资源类型,opentional protoc 编译过后为指针,允许为空指针
	// @gotags: json:"type"
	Type *Type `protobuf:"varint,8,opt,name=type,proto3,enum=course.cmdb.resource.Type,oneof" json:"type"`
	// 服务商中的状态
	// @gotags: json:"status"
	Status string `protobuf:"bytes,9,opt,name=status,proto3" json:"status"`
	// 资源标签,
	// @gotags: json:"tags"
	Tags []*TagSelector `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags"`
	// 是否返回资源的标签, 如果标签哼多,你又不想要,可以控制返回该资源的标签?
	// 提升访问性能,避免一些不必要数据的传输。
	// @gotags: json:"with_tags"
	WithTags bool `protobuf:"varint,11,opt,name=with_tags,json=withTags,proto3" json:"with_tags"`
	// 关键字参数
	// @gotags: json:"keywords"
	Keywords string `protobuf:"bytes,14,opt,name=keywords,proto3" json:"keywords"`
	// 是否精确匹配,比如匹配ip,10.0.1.1 10.10.1.1xxx
	// @gotags: json:"exact_match"
	ExactMatch bool `protobuf:"varint,15,opt,name=exact_match,json=exactMatch,proto3" json:"exact_match"`
	// contains filtered or unexported fields
}

定义三个请求 资源的检索

func NewSearchRequestFromHTTP

func NewSearchRequestFromHTTP(r *http.Request) (*SearchRequest, error)

keywords=xx&domain=xx&tag=app=~app1,app2,app3

func (*SearchRequest) AddTag

func (req *SearchRequest) AddTag(t ...*TagSelector)

AddTag 添加tag 逻辑 扔到TagSelector 标签里面

func (*SearchRequest) Descriptor deprecated

func (*SearchRequest) Descriptor() ([]byte, []int)

Deprecated: Use SearchRequest.ProtoReflect.Descriptor instead.

func (*SearchRequest) GetDomain

func (x *SearchRequest) GetDomain() string

func (*SearchRequest) GetEnv

func (x *SearchRequest) GetEnv() string

func (*SearchRequest) GetExactMatch

func (x *SearchRequest) GetExactMatch() bool

func (*SearchRequest) GetKeywords

func (x *SearchRequest) GetKeywords() string

func (*SearchRequest) GetNamespace

func (x *SearchRequest) GetNamespace() string

func (*SearchRequest) GetPage

func (x *SearchRequest) GetPage() *request.PageRequest

func (*SearchRequest) GetStatus

func (x *SearchRequest) GetStatus() string

func (*SearchRequest) GetSyncAccount

func (x *SearchRequest) GetSyncAccount() string

func (*SearchRequest) GetTags

func (x *SearchRequest) GetTags() []*TagSelector

func (*SearchRequest) GetType

func (x *SearchRequest) GetType() Type

func (*SearchRequest) GetUsageMode

func (x *SearchRequest) GetUsageMode() UsageMode

func (*SearchRequest) GetVendor

func (x *SearchRequest) GetVendor() Vendor

func (*SearchRequest) GetWithTags

func (x *SearchRequest) GetWithTags() bool

func (*SearchRequest) HasTag

func (r *SearchRequest) HasTag() bool

HasTag 扩展SearchRequest 给他一个方法HasTag,让他返回一个当前的查询参数到底有没有带着tag来做一个查询 判断下长度是不是大于0,如果大于0就可以做过滤,如果等于0就没有tag

func (*SearchRequest) ProtoMessage

func (*SearchRequest) ProtoMessage()

func (*SearchRequest) ProtoReflect

func (x *SearchRequest) ProtoReflect() protoreflect.Message

func (*SearchRequest) Reset

func (x *SearchRequest) Reset()

func (*SearchRequest) String

func (x *SearchRequest) String() string

type ServiceClient

type ServiceClient interface {
	Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*ResourceSet, error)
	QueryTag(ctx context.Context, in *QueryTagRequest, opts ...grpc.CallOption) (*TagSet, error)
	UpdateTag(ctx context.Context, in *UpdateTagRequest, opts ...grpc.CallOption) (*Resource, error)
}

ServiceClient is the client API for Service service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewServiceClient

func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient

type ServiceServer

type ServiceServer interface {
	Search(context.Context, *SearchRequest) (*ResourceSet, error)
	QueryTag(context.Context, *QueryTagRequest) (*TagSet, error)
	UpdateTag(context.Context, *UpdateTagRequest) (*Resource, error)
	// contains filtered or unexported methods
}

ServiceServer is the server API for Service service. All implementations must embed UnimplementedServiceServer for forward compatibility

type SharedPolicy

type SharedPolicy struct {

	// 分享的维度,这个资源被多个应用 使用,多个使用者
	// @gotags: json:"tag_key"
	TagKey string `protobuf:"bytes,1,opt,name=tag_key,json=tagKey,proto3" json:"tag_key"`
	// 分享给哪些值,app1,app2,app3 共享使用这个资源,那些人共享这个资源user1,user2,user3
	// @gotags: json:"tag_values"
	TagValues []string `protobuf:"bytes,2,rep,name=tag_values,json=tagValues,proto3" json:"tag_values"`
	// contains filtered or unexported fields
}

共享策略,

func (*SharedPolicy) Descriptor deprecated

func (*SharedPolicy) Descriptor() ([]byte, []int)

Deprecated: Use SharedPolicy.ProtoReflect.Descriptor instead.

func (*SharedPolicy) GetTagKey

func (x *SharedPolicy) GetTagKey() string

func (*SharedPolicy) GetTagValues

func (x *SharedPolicy) GetTagValues() []string

func (*SharedPolicy) ProtoMessage

func (*SharedPolicy) ProtoMessage()

func (*SharedPolicy) ProtoReflect

func (x *SharedPolicy) ProtoReflect() protoreflect.Message

func (*SharedPolicy) Reset

func (x *SharedPolicy) Reset()

func (*SharedPolicy) String

func (x *SharedPolicy) String() string

type Tag

type Tag struct {

	// 标签属于的资源,通过resource_id进行关联,跟数据库的设计有关系
	// @gotags: json:"resource_id"
	ResourceId string `protobuf:"bytes,1,opt,name=resource_id,json=resourceId,proto3" json:"resource_id"`
	// 标签的类型
	// @gotags: json:"type"
	Type TagType `protobuf:"varint,2,opt,name=type,proto3,enum=course.cmdb.resource.TagType" json:"type"`
	// 标签的Key
	// @gotags: json:"key" validate:"lte=255,required"
	Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key" validate:"lte=255,required"`
	// 标签的值,可读性不友好,appid=0xxx111
	// @gotags: json:"value" validate:"lte=255,required"
	Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value" validate:"lte=255,required"`
	// 标签的值的描述, 通常用于展示,财务系统A
	// @gotags: json:"describe"
	Describe string `protobuf:"bytes,5,opt,name=describe,proto3" json:"describe"`
	// 标签权重, 针对同一个key, 多个value场景, 默认值1
	// 资源的具体金额,费用是100,被多个业务方共同使用,出业务成本,面临这个成本如何分摊的问题
	// 为了让分摊更加的灵活,添加了标签的权重,更加权重的值做具体的分摊比例计算,比如a:1(1/4),b2(2/4),c:1(1/4)
	// 默认公平分摊,默认就是1,通过使用量进行分摊,外部系统(监控系统),通过使用计算出权重,设置过来。
	// @gotags: json:"weight"
	Weight int64 `protobuf:"varint,6,opt,name=weight,proto3" json:"weight"`
	// 标签是否纳入成本统计, 比如监控标签就不需要纳入到成本统计
	// @gotags: json:"is_cost"
	IsCost bool `protobuf:"varint,7,opt,name=is_cost,json=isCost,proto3" json:"is_cost"`
	// 标签是否隐藏, 用于控制是否在前端展示
	// @gotags: json:"hidden"
	Hidden bool `protobuf:"varint,8,opt,name=hidden,proto3" json:"hidden"`
	// 标签meta信息, 比如前端需要设置标签的颜色
	// @gotags: json:"meta"
	// 后期需要添加什么可以添加了一个meta
	Meta map[string]string `` /* 140-byte string literal not displayed */
	// contains filtered or unexported fields
}

func NewDefaultTag

func NewDefaultTag() *Tag

NewDefaultTag 方法 默认给予的tag 是TagType_USER 用户自定义标签, 允许用户修改

func NewThirdTag

func NewThirdTag(key, value string) *Tag

func (*Tag) Descriptor deprecated

func (*Tag) Descriptor() ([]byte, []int)

Deprecated: Use Tag.ProtoReflect.Descriptor instead.

func (*Tag) GetDescribe

func (x *Tag) GetDescribe() string

func (*Tag) GetHidden

func (x *Tag) GetHidden() bool

func (*Tag) GetIsCost

func (x *Tag) GetIsCost() bool

func (*Tag) GetKey

func (x *Tag) GetKey() string

func (*Tag) GetMeta

func (x *Tag) GetMeta() map[string]string

func (*Tag) GetResourceId

func (x *Tag) GetResourceId() string

func (*Tag) GetType

func (x *Tag) GetType() TagType

func (*Tag) GetValue

func (x *Tag) GetValue() string

func (*Tag) GetWeight

func (x *Tag) GetWeight() int64

func (*Tag) ProtoMessage

func (*Tag) ProtoMessage()

func (*Tag) ProtoReflect

func (x *Tag) ProtoReflect() protoreflect.Message

func (*Tag) Reset

func (x *Tag) Reset()

func (*Tag) String

func (x *Tag) String() string

type TagSelector

type TagSelector struct {

	// 匹配的key, 支持LIKE匹配
	// @gotags: json:"key"
	Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key"`
	// 匹配符
	// @gotags: json:"operator"
	Operator string `protobuf:"bytes,2,opt,name=operator,proto3" json:"operator"`
	// 匹配的值
	// @gotags: json:"values"
	Values []string `protobuf:"bytes,3,rep,name=values,proto3" json:"values"`
	// contains filtered or unexported fields
}

标签选择器 通过key value 进行匹配,匹配key,app-atrr1,app-attr2 以下两个标签共同组成一套业务逻辑,需要过滤 promethues.io 开头的标签 promethues.io/port = "xxxx" promethues.io/metric_path = "xxxx"

func NewTagsFromString

func NewTagsFromString(tagStr string) (tags []*TagSelector, err error)

key1=v1,v2,v3&key2=~v1,v2,v3 表示共同产生的一个标签

func ParExpr

func ParExpr(str string) (*TagSelector, error)

func (*TagSelector) Descriptor deprecated

func (*TagSelector) Descriptor() ([]byte, []int)

Deprecated: Use TagSelector.ProtoReflect.Descriptor instead.

func (*TagSelector) GetKey

func (x *TagSelector) GetKey() string

func (*TagSelector) GetOperator

func (x *TagSelector) GetOperator() string

func (*TagSelector) GetValues

func (x *TagSelector) GetValues() []string

func (*TagSelector) ProtoMessage

func (*TagSelector) ProtoMessage()

func (*TagSelector) ProtoReflect

func (x *TagSelector) ProtoReflect() protoreflect.Message

func (*TagSelector) Relationship

func (s *TagSelector) Relationship() string

func (*TagSelector) Reset

func (x *TagSelector) Reset()

func (*TagSelector) String

func (x *TagSelector) String() string

type TagSet

type TagSet struct {

	// @gotags: json:"total"
	Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total"`
	// @gotags: json:"items"
	Items []*Tag `protobuf:"bytes,2,rep,name=items,proto3" json:"items"`
	// contains filtered or unexported fields
}

返回的tag列表

func (*TagSet) Descriptor deprecated

func (*TagSet) Descriptor() ([]byte, []int)

Deprecated: Use TagSet.ProtoReflect.Descriptor instead.

func (*TagSet) GetItems

func (x *TagSet) GetItems() []*Tag

func (*TagSet) GetTotal

func (x *TagSet) GetTotal() int64

func (*TagSet) ProtoMessage

func (*TagSet) ProtoMessage()

func (*TagSet) ProtoReflect

func (x *TagSet) ProtoReflect() protoreflect.Message

func (*TagSet) Reset

func (x *TagSet) Reset()

func (*TagSet) String

func (x *TagSet) String() string

type TagType

type TagType int32
const (
	// 用户自定义标签, 允许用户修改
	TagType_USER TagType = 0
	// 外部系统使用的标签第三方定义的标签, 比如云商同步过来的标签,不允许通过本系统修改,如果修改需要去第三方系统修改
	TagType_THIRD TagType = 1
	// 内部系统使用标签, 禁止用户修改, 表示被其他系统引用, 比如应用关联标签,app=app1
	TagType_SYSTEM TagType = 2
)

func ParseTagTypeFromString

func ParseTagTypeFromString(str string) (TagType, error)

ParseTagTypeFromString Parse TagType from string

func (TagType) Descriptor

func (TagType) Descriptor() protoreflect.EnumDescriptor

func (TagType) Enum

func (x TagType) Enum() *TagType

func (TagType) EnumDescriptor deprecated

func (TagType) EnumDescriptor() ([]byte, []int)

Deprecated: Use TagType.Descriptor instead.

func (TagType) Equal

func (t TagType) Equal(target TagType) bool

Equal type compare

func (TagType) IsIn

func (t TagType) IsIn(targets ...TagType) bool

IsIn todo

func (TagType) MarshalJSON

func (t TagType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (TagType) Number

func (x TagType) Number() protoreflect.EnumNumber

func (TagType) String

func (x TagType) String() string

func (TagType) Type

func (TagType) Type() protoreflect.EnumType

func (*TagType) UnmarshalJSON

func (t *TagType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Type

type Type int32

定义资源的类型

const (
	Type_HOST Type = 0 //定义的主机
	Type_RDS  Type = 1 //rds
	//可以定义很多其他的资源
	Type_BILL Type = 99 //账单,跟其他的资源不太一样所以放大了
)

func ParseTypeFromString

func ParseTypeFromString(str string) (Type, error)

ParseTypeFromString Parse Type from string

func (Type) Descriptor

func (Type) Descriptor() protoreflect.EnumDescriptor

func (Type) Enum

func (x Type) Enum() *Type

func (Type) EnumDescriptor deprecated

func (Type) EnumDescriptor() ([]byte, []int)

Deprecated: Use Type.Descriptor instead.

func (Type) Equal

func (t Type) Equal(target Type) bool

Equal type compare

func (Type) IsIn

func (t Type) IsIn(targets ...Type) bool

IsIn todo

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Type) Number

func (x Type) Number() protoreflect.EnumNumber

func (Type) String

func (x Type) String() string

func (Type) Type

func (Type) Type() protoreflect.EnumType

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type UnimplementedServiceServer

type UnimplementedServiceServer struct {
}

UnimplementedServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedServiceServer) QueryTag

func (UnimplementedServiceServer) Search

func (UnimplementedServiceServer) UpdateTag

type UnsafeServiceServer

type UnsafeServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ServiceServer will result in compilation errors.

type UpdateAction

type UpdateAction int32

定义枚举,控制是添加一个标签还是删除一个标签

const (
	// 添加
	UpdateAction_ADD UpdateAction = 0
	// 移除
	UpdateAction_REMOVE UpdateAction = 1
)

func ParseUpdateActionFromString

func ParseUpdateActionFromString(str string) (UpdateAction, error)

ParseUpdateActionFromString Parse UpdateAction from string

func (UpdateAction) Descriptor

func (UpdateAction) Enum

func (x UpdateAction) Enum() *UpdateAction

func (UpdateAction) EnumDescriptor deprecated

func (UpdateAction) EnumDescriptor() ([]byte, []int)

Deprecated: Use UpdateAction.Descriptor instead.

func (UpdateAction) Equal

func (t UpdateAction) Equal(target UpdateAction) bool

Equal type compare

func (UpdateAction) IsIn

func (t UpdateAction) IsIn(targets ...UpdateAction) bool

IsIn todo

func (UpdateAction) MarshalJSON

func (t UpdateAction) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (UpdateAction) Number

func (UpdateAction) String

func (x UpdateAction) String() string

func (UpdateAction) Type

func (*UpdateAction) UnmarshalJSON

func (t *UpdateAction) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type UpdateTagRequest

type UpdateTagRequest struct {

	// 资源id,修改哪一个资源的标签
	// @gotags: json:"id" validate:"required"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" validate:"required"`
	// 资源id,具体标签的对象
	// @gotags: json:"action"
	Action UpdateAction `protobuf:"varint,2,opt,name=action,proto3,enum=course.cmdb.resource.UpdateAction" json:"action"`
	// 需要添加的资源标签,
	// @gotags: json:"tags" validate:"required"
	Tags []*Tag `protobuf:"bytes,3,rep,name=tags,proto3" json:"tags" validate:"required"`
	// contains filtered or unexported fields
}

更新我们的标签

func (*UpdateTagRequest) Descriptor deprecated

func (*UpdateTagRequest) Descriptor() ([]byte, []int)

Deprecated: Use UpdateTagRequest.ProtoReflect.Descriptor instead.

func (*UpdateTagRequest) GetAction

func (x *UpdateTagRequest) GetAction() UpdateAction

func (*UpdateTagRequest) GetId

func (x *UpdateTagRequest) GetId() string

func (*UpdateTagRequest) GetTags

func (x *UpdateTagRequest) GetTags() []*Tag

func (*UpdateTagRequest) ProtoMessage

func (*UpdateTagRequest) ProtoMessage()

func (*UpdateTagRequest) ProtoReflect

func (x *UpdateTagRequest) ProtoReflect() protoreflect.Message

func (*UpdateTagRequest) Reset

func (x *UpdateTagRequest) Reset()

func (*UpdateTagRequest) String

func (x *UpdateTagRequest) String() string

type UsageMode

type UsageMode int32

使用方式,同一个资源可能会被多个业务方使用,或者多个人共享使用 对这种使用方式做一个标记

const (
	// 共享使用
	UsageMode_SHARED UsageMode = 0
	// 独占使用
	UsageMode_MONOPOLY UsageMode = 1
)

func ParseUsageModeFromString

func ParseUsageModeFromString(str string) (UsageMode, error)

ParseUsageModeFromString Parse UsageMode from string

func (UsageMode) Descriptor

func (UsageMode) Descriptor() protoreflect.EnumDescriptor

func (UsageMode) Enum

func (x UsageMode) Enum() *UsageMode

func (UsageMode) EnumDescriptor deprecated

func (UsageMode) EnumDescriptor() ([]byte, []int)

Deprecated: Use UsageMode.Descriptor instead.

func (UsageMode) Equal

func (t UsageMode) Equal(target UsageMode) bool

Equal type compare

func (UsageMode) IsIn

func (t UsageMode) IsIn(targets ...UsageMode) bool

IsIn todo

func (UsageMode) MarshalJSON

func (t UsageMode) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (UsageMode) Number

func (x UsageMode) Number() protoreflect.EnumNumber

func (UsageMode) String

func (x UsageMode) String() string

func (UsageMode) Type

func (*UsageMode) UnmarshalJSON

func (t *UsageMode) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Vendor

type Vendor int32

定义厂商,使用枚举定义

const (
	Vendor_ALIYUN  Vendor = 0
	Vendor_TENCENT Vendor = 1
	Vendor_HUAWEI  Vendor = 2
	Vendor_VSPHERE Vendor = 3 //vmware私有化资源
	Vendor_AMAZON  Vendor = 4 //aws
)

func ParseVendorFromString

func ParseVendorFromString(str string) (Vendor, error)

ParseVendorFromString Parse Vendor from string

func (Vendor) Descriptor

func (Vendor) Descriptor() protoreflect.EnumDescriptor

func (Vendor) Enum

func (x Vendor) Enum() *Vendor

func (Vendor) EnumDescriptor deprecated

func (Vendor) EnumDescriptor() ([]byte, []int)

Deprecated: Use Vendor.Descriptor instead.

func (Vendor) Equal

func (t Vendor) Equal(target Vendor) bool

Equal type compare

func (Vendor) IsIn

func (t Vendor) IsIn(targets ...Vendor) bool

IsIn todo

func (Vendor) MarshalJSON

func (t Vendor) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Vendor) Number

func (x Vendor) Number() protoreflect.EnumNumber

func (Vendor) String

func (x Vendor) String() string

func (Vendor) Type

func (Vendor) Type() protoreflect.EnumType

func (*Vendor) UnmarshalJSON

func (t *Vendor) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL