Skip to content

Commit

Permalink
Add logs for testing
Browse files Browse the repository at this point in the history
This commit will be removed after the testing in INT is done
  • Loading branch information
nwnt committed Oct 2, 2023
1 parent c566480 commit 8f2e6c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/monitor/azure/nsg/nsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ func (n *NSGMonitor) toSubnetConfig(ctx context.Context, subnetID string) (subne
}

func (n *NSGMonitor) Monitor(ctx context.Context) {
n.log.Info("NSGMonitor object Monitor has started")
n.log.Info("Parsing the master subnet ID: ", n.oc.Properties.MasterProfile.SubnetID)
masterSubnet, err := n.toSubnetConfig(ctx, n.oc.Properties.MasterProfile.SubnetID)
if err != nil {
n.log.Info("Unable to parse the masterSubnet: ", n.oc.Properties.MasterProfile.SubnetID)
// FP has no access to the subnet
n.done <- err
return
Expand All @@ -124,6 +127,7 @@ func (n *NSGMonitor) Monitor(ctx context.Context) {
for _, wp := range workerProfiles {
s, err := n.toSubnetConfig(ctx, wp.SubnetID)
if err != nil {
n.log.Info("Unable to parse the workerSubnet: ", wp.SubnetID)
// FP has no access to the subnet
n.done <- err
return
Expand All @@ -136,9 +140,11 @@ func (n *NSGMonitor) Monitor(ctx context.Context) {
nsgSet := map[string]*mgmtnetwork.SecurityGroup{
*masterSubnet.nsg.ID: masterSubnet.nsg,
}
n.log.Info("nsgSet: ", nsgSet)
for _, w := range workerSubnets {
nsgSet[*w.nsg.ID] = w.nsg
}
n.log.Info("nsgSet: ", nsgSet)

for nsgID, nsg := range nsgSet {
for _, rule := range *nsg.SecurityRules {
Expand All @@ -153,9 +159,13 @@ func (n *NSGMonitor) Monitor(ctx context.Context) {
continue
}

n.log.Info("Rule Name ", *rule.Name)
r := newRuleChecker(n.log, masterSubnet.prefix, workerPrefixes, &rule)

if r.isInvalidDenyRule() {
// TODO remove after testing
n.log.Infof("%s is an invalid rule", *r.rule.Name)

dims := map[string]string{
DimClusterResourceID: n.oc.ID,
DimLocation: n.oc.Location,
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func getHiveClientSet(hiveRestConfig *rest.Config) (client.Client, error) {

// Monitor checks the API server health of a cluster
func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
mon.log.Debug("monitoring")
mon.log.Info("monitoring")

if mon.hourlyRun {
mon.emitGauge("cluster.provisioning", 1, map[string]string{
Expand Down
1 change: 1 addition & 0 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func NewMonitor(log *logrus.Entry, dialer proxy.Dialer, dbMonitors database.Moni
}

func (mon *monitor) Run(ctx context.Context) error {
mon.baseLog.Info("Monitoring has started.")
_, err := mon.dbMonitors.Create(ctx, &api.MonitorDocument{
ID: "master",
})
Expand Down
8 changes: 7 additions & 1 deletion pkg/monitor/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ func (mon *monitor) workOne(ctx context.Context, log *logrus.Entry, doc *api.Ope
}

var nsgMon *nsg.NSGMonitor
if doc.OpenShiftCluster.Properties.NetworkProfile.PreconfiguredNSG == api.PreconfiguredNSGEnabled && hourlyRun {
log.Info(doc.OpenShiftCluster.Properties.NetworkProfile.PreconfiguredNSG, hourlyRun)
if doc.OpenShiftCluster.Properties.NetworkProfile.PreconfiguredNSG == api.PreconfiguredNSGEnabled {
// TODO remove after testing
log.Info("NSG Monitoring is starting for ", doc.OpenShiftCluster.ID)

fpAuthorizer, err := mon.env.FPAuthorizer(sub.Subscription.Properties.TenantID, mon.env.Environment().ResourceManagerEndpoint)
if err != nil {
Expand All @@ -262,6 +265,7 @@ func (mon *monitor) workOne(ctx context.Context, log *logrus.Entry, doc *api.Ope
})
} else {
nsgMon = nsg.NewNSGMonitor(log, doc.OpenShiftCluster, sub.ID, mon.env.Environment(), fpAuthorizer, mon.m)
log.Info("nsgMon obj", *nsgMon)
go nsgMon.Monitor(ctx)
}
}
Expand All @@ -281,6 +285,8 @@ func (mon *monitor) workOne(ctx context.Context, log *logrus.Entry, doc *api.Ope
if err != nil {
log.Error("Error occurred during NSG monitoring", err)
}
// TODO remove after testing
log.Info("NSG monitoring completed successfully for ", doc.OpenShiftCluster.ID)
case <-ctx.Done():
log.Info("NSG Monitoring timed out")
mon.m.EmitGauge(nsg.MetricNSGMonitoringTimedOut, int64(1), map[string]string{
Expand Down

0 comments on commit 8f2e6c1

Please sign in to comment.