Skip to content

Commit

Permalink
incluster kube-apiserver: include pod name in requested URL to track …
Browse files Browse the repository at this point in the history
…request source
  • Loading branch information
vrutkovs committed Nov 12, 2024
1 parent 7d982f2 commit f763d47
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/cmd/openshift-tests/run-disruption/disruption.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type RunAPIDisruptionMonitorFlags struct {

ArtifactDir string
LoadBalancerType string
PodName string
StopConfigMapName string

genericclioptions.IOStreams
Expand Down Expand Up @@ -100,6 +101,7 @@ func NewRunInClusterDisruptionMonitorCommand(ioStreams genericclioptions.IOStrea

func (f *RunAPIDisruptionMonitorFlags) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&f.LoadBalancerType, "lb-type", f.LoadBalancerType, "Set load balancer type, available options: internal-lb, service-network, external-lb (default)")
flags.StringVar(&f.PodName, "pod-name", f.PodName, "Append pod name to URI to record request source")
flags.StringVar(&f.StopConfigMapName, "stop-configmap", f.StopConfigMapName, "the name of the configmap that indicates that this pod should stop all watchers.")

f.ConfigFlags.AddFlags(flags)
Expand Down Expand Up @@ -150,6 +152,7 @@ func (f *RunAPIDisruptionMonitorFlags) ToOptions() (*RunAPIDisruptionMonitorOpti
KubeClientConfig: restConfig,
OutputFile: f.OutputFlags.OutFile,
LoadBalancerType: f.LoadBalancerType,
PodName: f.PodName,
StopConfigMapName: f.StopConfigMapName,
Namespace: namespace,
CloseFn: closeFn,
Expand All @@ -164,6 +167,7 @@ type RunAPIDisruptionMonitorOptions struct {
KubeClientConfig *rest.Config
OutputFile string
LoadBalancerType string
PodName string
StopConfigMapName string
Namespace string

Expand All @@ -190,7 +194,7 @@ func (o *RunAPIDisruptionMonitorOptions) Run(ctx context.Context) error {
lb := backend.ParseStringToLoadBalancerType(o.LoadBalancerType)

recorder := monitor.WrapWithJSONLRecorder(monitor.NewRecorder(), o.IOStreams.Out, nil)
samplers, err := controlplane.StartAPIMonitoringUsingNewBackend(ctx, recorder, o.KubeClientConfig, o.KubeClient, lb)
samplers, err := controlplane.StartAPIMonitoringUsingNewBackend(ctx, recorder, o.KubeClientConfig, o.KubeClient, lb, o.PodName)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
- run-disruption
- --output-file=/var/log/disruption-data/monitor-events/internal-lb-$(DEPLOYMENT_ID).txt
- --lb-type=$(LOAD_BALANCER)
- --pod-name=$(POD_NAME)
- --stop-configmap=stop-configmap
env:
- name: KUBERNETES_SERVICE_HOST
Expand All @@ -42,6 +43,10 @@ spec:
- name: DEPLOYMENT_ID
#to be overwritten at deployment initialization time
value: "DEFAULT"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: to-be-replaced
volumeMounts:
- mountPath: /var/log/disruption-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
- run-disruption
- --output-file=/var/log/disruption-data/monitor-events/localhost-monitor-$(DEPLOYMENT_ID).txt
- --lb-type=$(LOAD_BALANCER)
- --pod-name=$(POD_NAME)
- --stop-configmap=stop-configmap
env:
- name: KUBECONFIG
Expand All @@ -40,6 +41,10 @@ spec:
- name: DEPLOYMENT_ID
#to be overwritten at deployment initialization time
value: "DEFAULT"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: to-be-replaced
volumeMounts:
- mountPath: /var/log/disruption-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ spec:
- run-disruption
- --output-file=/var/log/disruption-data/monitor-events/service-network-monitor-$(DEPLOYMENT_ID).txt
- --lb-type=$(LOAD_BALANCER)
- --pod-name=$(POD_NAME)
- --stop-configmap=stop-configmap
env:
- name: LOAD_BALANCER
value: service-network
- name: DEPLOYMENT_ID
#to be overwritten at deployment initialization time
value: "DEFAULT"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: to-be-replaced
volumeMounts:
- mountPath: /var/log/disruption-data
Expand Down
7 changes: 4 additions & 3 deletions test/extended/util/disruption/controlplane/known_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func StartAPIMonitoringUsingNewBackend(
recorder monitorapi.Recorder,
clusterConfig *rest.Config,
kubeClient kubernetes.Interface,
lb backend.LoadBalancerType) ([]disruptionci.Sampler, error) {
lb backend.LoadBalancerType,
podName string) ([]disruptionci.Sampler, error) {

samplers := []disruptionci.Sampler{}
errs := []error{}
Expand All @@ -32,7 +33,7 @@ func StartAPIMonitoringUsingNewBackend(
if err != nil {
return nil, err
}
path := fmt.Sprintf("/api/v1/namespaces/default?resourceVersion=%s", ns.ResourceVersion)
path := fmt.Sprintf("/api/v1/namespaces/default?resourceVersion=%s&podName=%s", ns.ResourceVersion, podName)

sampler, err := createKubeAPIMonitoringWithNewConnectionsHTTP2(factory, lb, path)
samplers = append(samplers, sampler)
Expand Down Expand Up @@ -62,7 +63,7 @@ func StartAPIMonitoringUsingNewBackend(
return nil, fmt.Errorf("no imagestreams found")
}
stream := streams.Items[0]
path = fmt.Sprintf("/apis/image.openshift.io/v1/namespaces/openshift/imagestreams/%s?resourceVersion=%s", stream.Name, stream.ResourceVersion)
path = fmt.Sprintf("/apis/image.openshift.io/v1/namespaces/openshift/imagestreams/%s?resourceVersion=%s&podName=%s", stream.Name, stream.ResourceVersion, podName)

sampler, err = createOpenShiftAPIMonitoringWithNewConnectionsHTTP2(factory, lb, path)
samplers = append(samplers, sampler)
Expand Down

0 comments on commit f763d47

Please sign in to comment.