@@ -613,6 +613,82 @@ void flb_test_selector_can_modify_output(void)
613613 flb_stop (ctx );
614614 flb_destroy (ctx );
615615}
616+
617+
618+ void flb_test_selector_context_delete_label_value (void )
619+ {
620+ int ret ;
621+ flb_ctx_t * ctx ;
622+ int in_ffd ;
623+ int out_ffd ;
624+ struct flb_processor * proc ;
625+ struct flb_processor_unit * pu ;
626+ struct cfl_variant var = {
627+ .type = CFL_VARIANT_STRING ,
628+ .data .as_string = "delete_label_value" ,
629+ };
630+ struct cfl_variant label_pair = {
631+ .type = CFL_VARIANT_STRING ,
632+ .data .as_string = "name lib.0" ,
633+ };
634+ int got ;
635+ int n_metrics = 20 ;
636+ int not_used = 0 ;
637+ struct flb_lib_out_cb cb_data ;
638+
639+ /* Prepare output callback with expected result */
640+ cb_data .cb = cb_count_metrics_msgpack ;
641+ cb_data .data = & not_used ;
642+
643+ ctx = flb_create ();
644+ flb_service_set (ctx ,
645+ "Flush" , "0.200000000" ,
646+ "Grace" , "2" ,
647+ NULL );
648+
649+ proc = flb_processor_create (ctx -> config , "unit_test" , NULL , 0 );
650+ TEST_CHECK (proc != NULL );
651+
652+ pu = flb_processor_unit_create (proc , FLB_PROCESSOR_METRICS , "metrics_selector" );
653+ TEST_CHECK (pu != NULL );
654+ ret = flb_processor_unit_set_property (pu , "context" , & var );
655+ TEST_CHECK (ret == 0 );
656+ ret = flb_processor_unit_set_property (pu , "label" , & label_pair );
657+ TEST_CHECK (ret == 0 );
658+
659+ /* Input */
660+ in_ffd = flb_input (ctx , (char * ) "fluentbit_metrics" , NULL );
661+ TEST_CHECK (in_ffd >= 0 );
662+ ret = flb_input_set (ctx , in_ffd , "tag" , "test" , NULL );
663+ TEST_CHECK (ret == 0 );
664+ ret = flb_input_set (ctx , in_ffd , "scrape_on_start" , "true" , NULL );
665+ TEST_CHECK (ret == 0 );
666+ ret = flb_input_set (ctx , in_ffd , "scrape_interval" , "1" , NULL );
667+ TEST_CHECK (ret == 0 );
668+
669+ /* set up processor */
670+ ret = flb_input_set_processor (ctx , in_ffd , proc );
671+ TEST_CHECK (ret == 0 );
672+
673+ out_ffd = flb_output (ctx , (char * ) "lib" , & cb_data );
674+ TEST_CHECK (out_ffd >= 0 );
675+ flb_output_set (ctx , out_ffd , "match" , "test" , NULL );
676+
677+ clear_output_num ();
678+
679+ ret = flb_start (ctx );
680+ TEST_CHECK (ret == 0 );
681+
682+ flb_time_msleep (1500 ); /* waiting flush */
683+
684+ got = get_output_num ();
685+ if (!TEST_CHECK (got >= n_metrics )) {
686+ TEST_MSG ("expect: %d >= %d, got: %d < %d" , got , n_metrics , got , n_metrics );
687+ }
688+
689+ flb_stop (ctx );
690+ flb_destroy (ctx );
691+ }
616692#endif
617693
618694/* Test list */
@@ -625,6 +701,7 @@ TEST_LIST = {
625701 {"substring_include" , flb_test_selector_substring_include },
626702 {"substring_exclude" , flb_test_selector_substring_exclude },
627703 {"can_modify_output" , flb_test_selector_can_modify_output },
704+ {"context_delete_label_value" , flb_test_selector_context_delete_label_value },
628705#endif
629706 {NULL , NULL }
630707};
0 commit comments