forked from Azure/aks-periscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
3776d34
commit e2a50bd
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |