Duncan-tree-zhou commented on code in PR #66:
URL: https://github.com/apache/skywalking-swck/pull/66#discussion_r907496696


##########
operator/pkg/operator/injector/webhook.go:
##########
@@ -63,11 +68,35 @@ func (r *JavaagentInjector) Handle(ctx context.Context, req 
admission.Request) a
        // initialize SidecarInjectField and get injected strategy from 
annotations
        s := NewSidecarInjectField()
        // initialize InjectProcess as a call chain
-       ip := NewInjectProcess(ctx, s, anno, ao, pod, req, 
javaagentInjectorLog, r.Client)
+       ip := NewInjectProcess(ctx, s, anno, ao, swAgentL, pod, req, 
javaagentInjectorLog, r.Client)
        // do real injection
        return ip.Run()
 }
 
+func (r *JavaagentInjector) findMatchedSwAgentL(ctx context.Context, req 
admission.Request, pod *corev1.Pod) *v1alpha1.SwAgentList {
+       swAgentList := &v1alpha1.SwAgentList{}
+       if err := r.Client.List(ctx, swAgentList, 
client.InNamespace(req.Namespace)); err != nil {
+               javaagentInjectorLog.Error(err, "get SwAgent error")
+       }
+
+       // selector
+       var availableSwAgentL []v1alpha1.SwAgent
+       for _, swAgent := range swAgentList.Items {
+               isMatch := true
+               if len(swAgent.Spec.Selector) != 0 {
+                       for k, v := range swAgent.Spec.Selector {
+                               if !strings.EqualFold(v, pod.Labels[k]) {
+                                       isMatch = false
+                               }
+                       }
+               }
+               if isMatch {
+                       availableSwAgentL = append(availableSwAgentL, swAgent)
+               }
+       }
+       return swAgentList

Review Comment:
   it looks like that javaagent instruments failed to instrument demo app.
   
   i can see the javaagent loaded, but logs for exporting data wasm't been 
printed after curling http://demo:8085/hello.
   
   1.
   ``` bash
   kubectl port-forward service/demo 8085:8085
   ```
   2.
   ``` bash
   ╰$ curl http://localhost:8085/hello
   Hello World!%
   ```
   3.
   ``` log
   DEBUG 2022-06-27 14:56:17:608 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.LogbackSkyWalkingContextPatternConverterActivation.
   DEBUG 2022-06-27 14:56:17:613 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc.MDCConverterActivation.
   DEBUG 2022-06-27 14:56:17:618 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.async.AsyncAppenderBaseInstrumentation.
   DEBUG 2022-06-27 14:56:17:622 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.async.LoggingEventInstrumentation.
   DEBUG 2022-06-27 14:56:17:627 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.logstash.TcpSocketAppenderActivation.
   DEBUG 2022-06-27 14:56:17:631 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.logstash.TraceIdJsonProviderActivation.
   DEBUG 2022-06-27 14:56:17:636 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.logstash.SkyWalkingContextJsonProviderActivation.
   DEBUG 2022-06-27 14:56:17:641 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.log.GRPCLogAppenderActivation.
   DEBUG 2022-06-27 14:56:17:645 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerActivation.
   DEBUG 2022-06-27 14:56:17:650 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.opentracing.span.SkywalkingSpanActivation.
   DEBUG 2022-06-27 14:56:17:655 main PluginBootstrap : loading plugin class 
org.apache.skywalking.apm.toolkit.activation.opentracing.continuation.SkywalkingContinuationActivation.
   
     .   ____          _            __ _ _
    /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
   ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
     '  |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot ::                (v2.5.3)
   
   2022-06-27 14:56:30.596  INFO 1 --- [           main] 
com.example.demo.DemoApplication         : Starting DemoApplication 
v0.0.1-SNAPSHOT using Java 1.8.0_212 on demo-57d4cc48b8-f8lcv with PID 1 
(/app.jar started by root in /)
   2022-06-27 14:56:30.602  INFO 1 --- [           main] 
com.example.demo.DemoApplication         : No active profile set, falling back 
to default profiles: default
   2022-06-27 14:56:33.652  INFO 1 --- [           main] 
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 
8085 (http)
   2022-06-27 14:56:33.680  INFO 1 --- [           main] 
o.apache.catalina.core.StandardService   : Starting service [Tomcat]
   2022-06-27 14:56:33.680  INFO 1 --- [           main] 
org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache 
Tomcat/9.0.50]
   2022-06-27 14:56:33.883  INFO 1 --- [           main] 
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded 
WebApplicationContext
   2022-06-27 14:56:33.883  INFO 1 --- [           main] 
w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: 
initialization completed in 3087 ms
   2022-06-27 14:56:35.901  INFO 1 --- [           main] 
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8085 
(http) with context path ''
   2022-06-27 14:56:35.925  INFO 1 --- [           main] 
com.example.demo.DemoApplication         : Started DemoApplication in 8.247 
seconds (JVM running for 20.514)
   2022-06-27 14:56:36.241  INFO 1 --- [nio-8085-exec-1] 
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring 
DispatcherServlet 'dispatcherServlet'
   2022-06-27 14:56:36.243  INFO 1 --- [nio-8085-exec-1] 
o.s.web.servlet.DispatcherServlet        : Initializing Servlet 
'dispatcherServlet'
   2022-06-27 14:56:36.246  INFO 1 --- [nio-8085-exec-1] 
o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
   
   ```
   
   do you know where i can find the source code of image 
'ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1' ? maybe we can find some 
clues in demo source code...
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to