Skip to content

Commit

Permalink
feat: add SMI log collector
Browse files Browse the repository at this point in the history
Add log collector for Service Mesh Interface
logs, CustomResourceDefinitions, and custom
resources.

Related to PR Azure#48.

Resolves issue Azure#67.

Signed-off-by: Johnson Shi <[email protected]>
  • Loading branch information
johnsonshi committed Jun 22, 2021
1 parent 3776d34 commit e2a50bd
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {
systemPerfCollector := collector.NewSystemPerfCollector(exporter)
helmCollector := collector.NewHelmCollector(exporter)
osmCollector := collector.NewOsmCollector(exporter)
smiCollector := collector.NewSmiCollector(exporter)

collectors = append(collectors, containerLogsCollector)
collectors = append(collectors, dnsCollector)
Expand All @@ -64,6 +65,10 @@ func main() {
collectors = append(collectors, osmCollector)
}

if contains(collectorList, "SMI") {
collectors = append(collectors, smiCollector)
}

collectorGrp := new(sync.WaitGroup)

for _, c := range collectors {
Expand Down
7 changes: 5 additions & 2 deletions deployment/aks-periscope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ rules:
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "watch"]
- apiGroups: ["access.smi-spec.io", "specs.smi-spec.io", "split.smi-spec.io"]
resources: ["*"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down Expand Up @@ -77,7 +80,7 @@ spec:
beta.kubernetes.io/os: linux
containers:
- name: aks-periscope
image: aksrepos.azurecr.io/staging/aks-periscope:v0.3
image: johshmsft/aks-periscope:latest
securityContext:
privileged: true
imagePullPolicy: Always
Expand Down Expand Up @@ -148,7 +151,7 @@ metadata:
name: collectors-config
namespace: aks-periscope
data:
COLLECTOR_LIST: managedCluster # <custom flag>
COLLECTOR_LIST: managedCluster, OSM, SMI # <custom flag>
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
Expand Down
4 changes: 3 additions & 1 deletion pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
NodeLogs
// Osm defines Open Service Mesh Collector Type
Osm
// Smi defines Service Mesh Interface Collector Type
Smi
// SystemLogs defines SystemLogs Collector Type
SystemLogs
// SystemPerf defines SystemPerf Collector Type
Expand All @@ -37,7 +39,7 @@ const (

// Name returns type name
func (t Type) name() string {
return [...]string{"dns", "containerlogs", "helm", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "osm", "systemlogs", "systemperf"}[t]
return [...]string{"dns", "containerlogs", "helm", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "osm", "smi", "systemlogs", "systemperf"}[t]
}

// BaseCollector defines Base Collector
Expand Down
90 changes: 90 additions & 0 deletions pkg/collector/smi_collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package collector

import (
"log"
"strings"

"github.com/Azure/aks-periscope/pkg/interfaces"
"github.com/Azure/aks-periscope/pkg/utils"
)

// SmiCollector defines an Smi Collector struct
type SmiCollector struct {
BaseCollector
}

var _ interfaces.Collector = &SmiCollector{}

// NewSmiCollector is a constructor
func NewSmiCollector(exporter interfaces.Exporter) *SmiCollector {
return &SmiCollector{
BaseCollector: BaseCollector{
collectorType: Smi,
exporter: exporter,
},
}
}

// Collect implements the interface method
func (collector *SmiCollector) Collect() error {
// Get all CustomResourceDefinitions in the cluster
allCrdsList, err := utils.GetResourceList([]string{"get", "crds", "--all-namespaces", "-o", "jsonpath={..metadata.name}"}, " ")
if err != nil {
return err
}
if len(allCrdsList) == 0 {
log.Printf("Cluster does not contain any CustomResourceDefinitions\n")
return nil
}

// Get all Smi CustomResourceDefinitions in the cluster
crdNameContainsSmiPredicate := func(s string) bool { return strings.Contains(s, "smi-spec.io") }
smiCrdsList := filter(allCrdsList, crdNameContainsSmiPredicate)
if len(smiCrdsList) == 0 {
log.Printf("Cluster does not contain any SMI CustomResourceDefinitions\n")
return nil
}

// Directory where SMI logs will be written to
// rootPath, err := utils.CreateCollectorDir(collector.GetName())
// if err != nil {
// return err
// }

// Steps:

// Obtain list of CRDs in the cluster.
// Return error if error on obtaining CRDs from the cluster.
// Return nil if no CRDs in the cluster.
// Filter Smi CRDs from the list of CRDs.
// Return nil if no Smi CRDs in the cluster.

// Proceed with obtaining Smi logs.
// Create top level directory.

// Top Level Logs - Log a cluster-wide TSV list of all Smi CustomResourceDefinitions in the cluster.
// Top Level Logs - Log the YAML definition of each Smi CustomResourceDefinition in the cluster.

// Proceed with collecting Smi logs from each namespace.

// For each namespace:

// Create a directory for the namespace.

// For each Smi CRD:

// Log a TSV list of all custom resources of that Smi CRD type.

// For each custom resource of that Smi CRD type:

// Log the YAML definition of that custom resource of that Smi CRD type.
}

func filter(ss []string, test func(string) bool) (ret []string) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}

0 comments on commit e2a50bd

Please sign in to comment.